start POS adaptation to new contract

This commit is contained in:
Michele Balistreri 2020-10-02 12:08:08 +02:00
parent b1f2c2f0b7
commit de12709570
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
2 changed files with 13 additions and 27 deletions

View File

@ -1,9 +1,10 @@
const StatusPay = artifacts.require('StatusPay');
const StatusPay = artifacts.require('StatusPay'); // TODO: load JSON
import { recoverTypedSignature } from 'eth-sig-util';
const addressZero = "0x0000000000000000000000000000000000000000";
const tokenAddress = "0xc55cF4B03948D7EBc8b9E8BAD92643703811d162";
const statusPay; //TODO: initialize with web3/JSON
export const NEW_WALLET = 'NEW_WALLET';
export const newWallet = () => ({
@ -209,11 +210,11 @@ export const paymentRequested = () => ({
type: PAYMENT_REQUESTED,
});
export const sendPaymentRequest = (walletContract, message, sig) => {
export const sendPaymentRequest = (message, sig) => {
return async (dispatch) => {
try {
dispatch(requestingPayment())
const requestPayment = await walletContract.methods.requestPayment(message, sig);
const requestPayment = await statusPay.requestPayment(message, sig);
const gas = await requestPayment.estimateGas();
const receipt = await requestPayment.send({
gas: gas
@ -230,24 +231,12 @@ export const loadWallet = (walletAddress, message, sig) => {
return async (dispatch) => {
dispatch(loadingWallet())
const jsonInterface = KeycardWallet.options.jsonInterface;
const walletContract = new EmbarkJS.Blockchain.Contract({
abi: jsonInterface,
address: walletAddress,
});
walletContract.address = walletAddress;
const erc20Contract = new EmbarkJS.Blockchain.Contract({
abi: IERC20.options.jsonInterface,
address: tokenAddress,
});
erc20Contract.address = tokenAddress;
const balance = await erc20Contract.methods.balanceOf(walletAddress).call();
const maxTxValue = await walletContract.methods.tokenMaxTxAmount(tokenAddress).call();
const account = await statusPay.accounts(walletAddress).call();
const balance = account.balance.toNumber();
const maxTxValue = account.maxTxAmount.toNumber();
dispatch(walletLoaded(balance, maxTxValue))
dispatch(sendPaymentRequest(walletContract, message, sig))
dispatch(sendPaymentRequest(message, sig))
};
}
@ -277,7 +266,10 @@ export const paymentAmountValueChange = (value) => ({
export const findWallet = (keycardAddress, message, sig) => {
return async (dispatch) => {
dispatch(findingWallet());
KeycardWalletFactory.methods.keycardsWallets(keycardAddress).call()
assert.equal((await token.balanceOf.call(owner)).toNumber(), 0);
assert.equal((await statusPay.accounts.call(account)).balance.toNumber(), 100);
statusPay.keycards.call(keycardAddress)
.then((address) => {
//FIXME: if 0x00, display error
if (address === addressZero) {

View File

@ -1,7 +1,6 @@
import React from 'react';
import Pos from "../containers/Pos"
import KeycardWalletFactory from 'Embark/contracts/KeycardWalletFactory';
import { withStyles } from '@material-ui/core/styles';
import AppBar from '@material-ui/core/AppBar';
@ -9,8 +8,6 @@ import Toolbar from '@material-ui/core/Toolbar';
import Typography from '@material-ui/core/Typography';
import CircularProgress from '@material-ui/core/CircularProgress';
import { compressedAddress } from '../utils';
const styles = theme => ({
loading: {
textAlign: "center",
@ -36,9 +33,6 @@ const App = (props) => {
<Toolbar>
<Typography variant="h6" color="inherit">
Keycard POS
<Typography variant="caption" color="inherit">
{compressedAddress(KeycardWalletFactory.address)} {networkText}
</Typography>
</Typography>
</Toolbar>
</AppBar>