diff --git a/js/src/contracts/abi/consensys-multisig-wallet.json b/js/src/contracts/abi/consensys-multisig-wallet.json
new file mode 100644
index 000000000..79623637d
--- /dev/null
+++ b/js/src/contracts/abi/consensys-multisig-wallet.json
@@ -0,0 +1,510 @@
+[
+ {
+ "constant": true,
+ "inputs": [
+ {
+ "name": "",
+ "type": "uint256"
+ }
+ ],
+ "name": "owners",
+ "outputs": [
+ {
+ "name": "",
+ "type": "address"
+ }
+ ],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": false,
+ "inputs": [
+ {
+ "name": "owner",
+ "type": "address"
+ }
+ ],
+ "name": "removeOwner",
+ "outputs": [],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": false,
+ "inputs": [
+ {
+ "name": "transactionId",
+ "type": "uint256"
+ }
+ ],
+ "name": "revokeConfirmation",
+ "outputs": [],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [
+ {
+ "name": "",
+ "type": "address"
+ }
+ ],
+ "name": "isOwner",
+ "outputs": [
+ {
+ "name": "",
+ "type": "bool"
+ }
+ ],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [
+ {
+ "name": "",
+ "type": "uint256"
+ },
+ {
+ "name": "",
+ "type": "address"
+ }
+ ],
+ "name": "confirmations",
+ "outputs": [
+ {
+ "name": "",
+ "type": "bool"
+ }
+ ],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [
+ {
+ "name": "pending",
+ "type": "bool"
+ },
+ {
+ "name": "executed",
+ "type": "bool"
+ }
+ ],
+ "name": "getTransactionCount",
+ "outputs": [
+ {
+ "name": "count",
+ "type": "uint256"
+ }
+ ],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": false,
+ "inputs": [
+ {
+ "name": "owner",
+ "type": "address"
+ }
+ ],
+ "name": "addOwner",
+ "outputs": [],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [
+ {
+ "name": "transactionId",
+ "type": "uint256"
+ }
+ ],
+ "name": "isConfirmed",
+ "outputs": [
+ {
+ "name": "",
+ "type": "bool"
+ }
+ ],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [
+ {
+ "name": "transactionId",
+ "type": "uint256"
+ }
+ ],
+ "name": "getConfirmationCount",
+ "outputs": [
+ {
+ "name": "count",
+ "type": "uint256"
+ }
+ ],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [
+ {
+ "name": "",
+ "type": "uint256"
+ }
+ ],
+ "name": "transactions",
+ "outputs": [
+ {
+ "name": "destination",
+ "type": "address"
+ },
+ {
+ "name": "value",
+ "type": "uint256"
+ },
+ {
+ "name": "data",
+ "type": "bytes"
+ },
+ {
+ "name": "executed",
+ "type": "bool"
+ }
+ ],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [],
+ "name": "getOwners",
+ "outputs": [
+ {
+ "name": "",
+ "type": "address[]"
+ }
+ ],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [
+ {
+ "name": "from",
+ "type": "uint256"
+ },
+ {
+ "name": "to",
+ "type": "uint256"
+ },
+ {
+ "name": "pending",
+ "type": "bool"
+ },
+ {
+ "name": "executed",
+ "type": "bool"
+ }
+ ],
+ "name": "getTransactionIds",
+ "outputs": [
+ {
+ "name": "_transactionIds",
+ "type": "uint256[]"
+ }
+ ],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [
+ {
+ "name": "transactionId",
+ "type": "uint256"
+ }
+ ],
+ "name": "getConfirmations",
+ "outputs": [
+ {
+ "name": "_confirmations",
+ "type": "address[]"
+ }
+ ],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [],
+ "name": "transactionCount",
+ "outputs": [
+ {
+ "name": "",
+ "type": "uint256"
+ }
+ ],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": false,
+ "inputs": [
+ {
+ "name": "_required",
+ "type": "uint256"
+ }
+ ],
+ "name": "changeRequirement",
+ "outputs": [],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": false,
+ "inputs": [
+ {
+ "name": "transactionId",
+ "type": "uint256"
+ }
+ ],
+ "name": "confirmTransaction",
+ "outputs": [],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": false,
+ "inputs": [
+ {
+ "name": "destination",
+ "type": "address"
+ },
+ {
+ "name": "value",
+ "type": "uint256"
+ },
+ {
+ "name": "data",
+ "type": "bytes"
+ }
+ ],
+ "name": "submitTransaction",
+ "outputs": [
+ {
+ "name": "transactionId",
+ "type": "uint256"
+ }
+ ],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [],
+ "name": "MAX_OWNER_COUNT",
+ "outputs": [
+ {
+ "name": "",
+ "type": "uint256"
+ }
+ ],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [],
+ "name": "required",
+ "outputs": [
+ {
+ "name": "",
+ "type": "uint256"
+ }
+ ],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": false,
+ "inputs": [
+ {
+ "name": "owner",
+ "type": "address"
+ },
+ {
+ "name": "newOwner",
+ "type": "address"
+ }
+ ],
+ "name": "replaceOwner",
+ "outputs": [],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "constant": false,
+ "inputs": [
+ {
+ "name": "transactionId",
+ "type": "uint256"
+ }
+ ],
+ "name": "executeTransaction",
+ "outputs": [],
+ "payable": false,
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "name": "_owners",
+ "type": "address[]"
+ },
+ {
+ "name": "_required",
+ "type": "uint256"
+ }
+ ],
+ "payable": false,
+ "type": "constructor"
+ },
+ {
+ "payable": true,
+ "type": "fallback"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": true,
+ "name": "sender",
+ "type": "address"
+ },
+ {
+ "indexed": true,
+ "name": "transactionId",
+ "type": "uint256"
+ }
+ ],
+ "name": "Confirmation",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": true,
+ "name": "sender",
+ "type": "address"
+ },
+ {
+ "indexed": true,
+ "name": "transactionId",
+ "type": "uint256"
+ }
+ ],
+ "name": "Revocation",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": true,
+ "name": "transactionId",
+ "type": "uint256"
+ }
+ ],
+ "name": "Submission",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": true,
+ "name": "transactionId",
+ "type": "uint256"
+ }
+ ],
+ "name": "Execution",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": true,
+ "name": "transactionId",
+ "type": "uint256"
+ }
+ ],
+ "name": "ExecutionFailure",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": true,
+ "name": "sender",
+ "type": "address"
+ },
+ {
+ "indexed": false,
+ "name": "value",
+ "type": "uint256"
+ }
+ ],
+ "name": "Deposit",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": true,
+ "name": "owner",
+ "type": "address"
+ }
+ ],
+ "name": "OwnerAddition",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": true,
+ "name": "owner",
+ "type": "address"
+ }
+ ],
+ "name": "OwnerRemoval",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": false,
+ "name": "required",
+ "type": "uint256"
+ }
+ ],
+ "name": "RequirementChange",
+ "type": "event"
+ }
+]
diff --git a/js/src/contracts/abi/wallet.json b/js/src/contracts/abi/foundation-multisig-wallet.json
similarity index 100%
rename from js/src/contracts/abi/wallet.json
rename to js/src/contracts/abi/foundation-multisig-wallet.json
diff --git a/js/src/contracts/abi/index.js b/js/src/contracts/abi/index.js
index 8985d869e..f475cce07 100644
--- a/js/src/contracts/abi/index.js
+++ b/js/src/contracts/abi/index.js
@@ -28,4 +28,4 @@ export registry2 from './registry2.json';
export signaturereg from './signaturereg.json';
export smsverification from './sms-verification.json';
export tokenreg from './tokenreg.json';
-export wallet from './wallet.json';
+export foundationWallet from './foundation-multisig-wallet.json';
diff --git a/js/src/embed.js b/js/src/embed.js
index 5e8bf7ffe..0413fb466 100644
--- a/js/src/embed.js
+++ b/js/src/embed.js
@@ -64,14 +64,19 @@ class FakeTransport {
class FrameSecureApi extends SecureApi {
constructor (transport) {
- super(transport.uiUrl, null, () => {
- return transport;
- });
+ super(
+ transport.uiUrl,
+ null,
+ () => transport,
+ () => 'http:'
+ );
}
connect () {
// Do nothing - this API does not need connecting
this.emit('connecting');
+ // Fetch settings
+ this._fetchSettings();
// Fire connected event with some delay.
setTimeout(() => {
this.emit('connected');
diff --git a/js/src/modals/AddContract/types.js b/js/src/modals/AddContract/types.js
index b229fc7ac..dd1e20fbc 100644
--- a/js/src/modals/AddContract/types.js
+++ b/js/src/modals/AddContract/types.js
@@ -17,7 +17,7 @@
import React from 'react';
import { FormattedMessage } from 'react-intl';
-import { eip20, wallet } from '~/contracts/abi';
+import { eip20, foundationWallet } from '~/contracts/abi';
const ABI_TYPES = [
{
@@ -72,7 +72,7 @@ const ABI_TYPES = [
),
readOnly: true,
type: 'multisig',
- value: JSON.stringify(wallet)
+ value: JSON.stringify(foundationWallet)
},
{
description: (
diff --git a/js/src/modals/CreateWallet/createWalletStore.js b/js/src/modals/CreateWallet/createWalletStore.js
index d614e8041..26ed5816c 100644
--- a/js/src/modals/CreateWallet/createWalletStore.js
+++ b/js/src/modals/CreateWallet/createWalletStore.js
@@ -21,7 +21,7 @@ import { FormattedMessage } from 'react-intl';
import Contract from '~/api/contract';
import Contracts from '~/contracts';
-import { wallet as walletAbi } from '~/contracts/abi';
+import { foundationWallet as walletAbi } from '~/contracts/abi';
import { wallet as walletCode, walletLibrary as walletLibraryCode, walletLibraryRegKey, fullWalletCode } from '~/contracts/code/wallet';
import { validateUint, validateAddress, validateName } from '~/util/validation';
@@ -163,11 +163,11 @@ export default class CreateWalletStore {
WalletsUtils.fetchOwners(walletContract),
WalletsUtils.fetchDailylimit(walletContract)
])
- .then(([ require, owners, dailylimit ]) => {
+ .then(([ require, owners, daylimit ]) => {
transaction(() => {
this.wallet.owners = owners;
this.wallet.required = require.toNumber();
- this.wallet.dailylimit = dailylimit.limit;
+ this.wallet.daylimit = daylimit.limit;
this.wallet = this.getWalletWithMeta(this.wallet);
});
diff --git a/js/src/modals/Transfer/store.js b/js/src/modals/Transfer/store.js
index 737bab778..eaccf4f40 100644
--- a/js/src/modals/Transfer/store.js
+++ b/js/src/modals/Transfer/store.js
@@ -18,12 +18,12 @@ import { noop } from 'lodash';
import { observable, computed, action, transaction } from 'mobx';
import BigNumber from 'bignumber.js';
-import { eip20 as tokenAbi, wallet as walletAbi } from '~/contracts/abi';
+import { eip20 as tokenAbi } from '~/contracts/abi';
import { fromWei } from '~/api/util/wei';
-import Contract from '~/api/contract';
import ERRORS from './errors';
-import { DEFAULT_GAS, DEFAULT_GASPRICE, MAX_GAS_ESTIMATION } from '~/util/constants';
+import { DEFAULT_GAS } from '~/util/constants';
import { ETH_TOKEN } from '~/util/tokens';
+import { getTxOptions } from '~/util/tx';
import GasPriceStore from '~/ui/GasPriceEditor/store';
import { getLogger, LOG_KEYS } from '~/config';
@@ -92,7 +92,6 @@ export default class TransferStore {
if (this.isWallet) {
this.wallet = props.wallet;
- this.walletContract = new Contract(this.api, walletAbi);
}
if (senders) {
@@ -115,19 +114,13 @@ export default class TransferStore {
@computed get isValid () {
const detailsValid = !this.recipientError && !this.valueError && !this.totalError && !this.senderError;
const extrasValid = !this.gasStore.errorGas && !this.gasStore.errorPrice && !this.gasStore.conditionBlockError && !this.totalError;
- const verifyValid = !this.passwordError;
switch (this.stage) {
case 0:
return detailsValid;
case 1:
- return this.extras
- ? extrasValid
- : verifyValid;
-
- case 2:
- return verifyValid;
+ return extrasValid;
}
}
@@ -263,16 +256,21 @@ export default class TransferStore {
if (this.isWallet && !valueError) {
const { last, limit, spent } = this.wallet.dailylimit;
- const remains = fromWei(limit.minus(spent));
- const today = Math.round(Date.now() / (24 * 3600 * 1000));
- const isResetable = last.lt(today);
- if ((!isResetable && remains.lt(value)) || fromWei(limit).lt(value)) {
- // already spent too much today
- this.walletWarning = WALLET_WARNING_SPENT_TODAY_LIMIT;
- } else if (this.walletWarning) {
- // all ok
- this.walletWarning = null;
+ // Don't show a warning if the limit is 0
+ // (will always need confirmations)
+ if (limit.gt(0)) {
+ const remains = fromWei(limit.minus(spent));
+ const today = Math.round(Date.now() / (24 * 3600 * 1000));
+ const willResetLimit = last.lt(today);
+
+ if ((!willResetLimit && remains.lt(value)) || fromWei(limit).lt(value)) {
+ // already spent too much today
+ this.walletWarning = WALLET_WARNING_SPENT_TODAY_LIMIT;
+ } else if (this.walletWarning) {
+ // all ok
+ this.walletWarning = null;
+ }
}
}
@@ -312,24 +310,16 @@ export default class TransferStore {
});
}
- getBalance (forceSender = false) {
- if (this.isWallet && !forceSender) {
- return this.balance;
- }
-
- const balance = this.senders
- ? this.sendersBalances[this.sender]
- : this.balance;
-
- return balance;
- }
-
/**
* Return the balance of the selected token
* (in WEI for ETH, without formating for other tokens)
*/
- getTokenBalance (token = this.token, forceSender = false) {
- return new BigNumber(this.balance[token.id] || 0);
+ getTokenBalance (token = this.token, address = this.account.address) {
+ const balance = address === this.account.address
+ ? this.balance
+ : this.sendersBalances[address];
+
+ return new BigNumber(balance[token.id] || 0);
}
getTokenValue (token = this.token, value = this.value, inverse = false) {
@@ -348,54 +338,30 @@ export default class TransferStore {
return _value.mul(token.format);
}
- getValues (_gasTotal) {
- const gasTotal = new BigNumber(_gasTotal || 0);
+ getValue () {
const { valueAll, isEth, isWallet } = this;
- log.debug('@getValues', 'gas', gasTotal.toFormat());
-
if (!valueAll) {
const value = this.getTokenValue();
- // If it's a token or a wallet, eth is the estimated gas,
- // and value is the user input
- if (!isEth || isWallet) {
- return {
- eth: gasTotal,
- token: value
- };
- }
-
- // Otherwise, eth is the sum of the gas and the user input
- const totalEthValue = gasTotal.plus(value);
-
- return {
- eth: totalEthValue,
- token: value
- };
+ return value;
}
- // If it's the total balance that needs to be sent, send the total balance
- // if it's not a proper ETH transfer
+ const balance = this.getTokenBalance();
+
if (!isEth || isWallet) {
- const tokenBalance = this.getTokenBalance();
-
- return {
- eth: gasTotal,
- token: tokenBalance
- };
+ return balance;
}
- // Otherwise, substract the gas estimate
- const availableEth = this.getTokenBalance(ETH_TOKEN);
- const totalEthValue = availableEth.gt(gasTotal)
- ? availableEth.minus(gasTotal)
+ // substract the gas estimate
+ const gasTotal = new BigNumber(this.gasStore.price || 0)
+ .mul(new BigNumber(this.gasStore.gas || 0));
+
+ const totalEthValue = balance.gt(gasTotal)
+ ? balance.minus(gasTotal)
: new BigNumber(0);
- return {
- eth: totalEthValue.plus(gasTotal),
- token: totalEthValue
- };
+ return totalEthValue;
}
getFormattedTokenValue (tokenValue) {
@@ -403,160 +369,125 @@ export default class TransferStore {
}
@action recalculate = (redo = false) => {
- const { account } = this;
+ const { account, balance } = this;
- if (!account || !this.balance) {
+ if (!account || !balance) {
return;
}
- const balance = this.getBalance();
+ return this.getTransactionOptions()
+ .then((options) => {
+ const gasTotal = options.gas.mul(options.gasPrice);
- if (!balance) {
- return;
- }
+ const tokenValue = this.getValue();
+ const ethValue = options.value.add(gasTotal);
- const gasTotal = new BigNumber(this.gasStore.price || 0).mul(new BigNumber(this.gasStore.gas || 0));
+ const tokenBalance = this.getTokenBalance();
+ const ethBalance = this.getTokenBalance(ETH_TOKEN, options.from);
- const ethBalance = this.getTokenBalance(ETH_TOKEN, true);
- const tokenBalance = this.getTokenBalance();
- const { eth, token } = this.getValues(gasTotal);
+ let totalError = null;
+ let valueError = null;
- let totalError = null;
- let valueError = null;
+ if (tokenValue.gt(tokenBalance)) {
+ valueError = ERRORS.largeAmount;
+ }
- if (eth.gt(ethBalance)) {
- totalError = ERRORS.largeAmount;
- }
+ if (ethValue.gt(ethBalance)) {
+ totalError = ERRORS.largeAmount;
+ }
- if (token && token.gt(tokenBalance)) {
- valueError = ERRORS.largeAmount;
- }
+ log.debug('@recalculate', {
+ eth: ethValue.toFormat(),
+ token: tokenValue.toFormat(),
+ ethBalance: ethBalance.toFormat(),
+ tokenBalance: tokenBalance.toFormat(),
+ gasTotal: gasTotal.toFormat()
+ });
- log.debug('@recalculate', {
- eth: eth.toFormat(),
- token: token.toFormat(),
- ethBalance: ethBalance.toFormat(),
- tokenBalance: tokenBalance.toFormat(),
- gasTotal: gasTotal.toFormat()
- });
+ transaction(() => {
+ this.totalError = totalError;
+ this.valueError = valueError;
+ this.gasStore.setErrorTotal(totalError);
+ this.gasStore.setEthValue(options.value);
- transaction(() => {
- this.totalError = totalError;
- this.valueError = valueError;
- this.gasStore.setErrorTotal(totalError);
- this.gasStore.setEthValue(eth.sub(gasTotal));
+ this.total = fromWei(ethValue).toFixed();
- this.total = this.api.util.fromWei(eth).toFixed();
+ const nextValue = this.getFormattedTokenValue(tokenValue);
+ let prevValue;
- const nextValue = this.getFormattedTokenValue(token);
- let prevValue;
+ try {
+ prevValue = new BigNumber(this.value || 0);
+ } catch (error) {
+ prevValue = new BigNumber(0);
+ }
- try {
- prevValue = new BigNumber(this.value || 0);
- } catch (error) {
- prevValue = new BigNumber(0);
- }
+ // Change the input only if necessary
+ if (!nextValue.eq(prevValue)) {
+ this.value = nextValue.toString();
+ }
- // Change the input only if necessary
- if (!nextValue.eq(prevValue)) {
- this.value = nextValue.toString();
- }
-
- // Re Calculate gas once more to be sure
- if (redo) {
- return this.recalculateGas(false);
- }
- });
- }
-
- send () {
- const { options, values } = this._getTransferParams();
-
- log.debug('@send', 'transfer value', options.value && options.value.toFormat());
-
- return this._getTransferMethod().postTransaction(options, values);
- }
-
- _estimateGas (forceToken = false) {
- const { options, values } = this._getTransferParams(true, forceToken);
-
- return this._getTransferMethod(true, forceToken).estimateGas(options, values);
+ // Re Calculate gas once more to be sure
+ if (redo) {
+ return this.recalculateGas(false);
+ }
+ });
+ });
}
estimateGas () {
- return this._estimateGas();
+ return this.getTransactionOptions()
+ .then((options) => {
+ return this.api.eth.estimateGas(options);
+ });
}
- _getTransferMethod (gas = false, forceToken = false) {
- const { isEth, isWallet } = this;
+ send () {
+ return this.getTransactionOptions()
+ .then((options) => {
+ log.debug('@send', 'transfer value', options.value && options.value.toFormat());
- if (isEth && !isWallet && !forceToken) {
- return gas ? this.api.eth : this.api.parity;
- }
-
- if (isWallet && !forceToken) {
- return this.wallet.instance.execute;
- }
-
- return this.tokenContract.at(this.token.address).instance.transfer;
+ return this.api.parity.postTransaction(options);
+ });
}
- _getData (gas = false) {
- const { isEth, isWallet } = this;
+ getTransactionOptions () {
+ const [ func, options, values ] = this._getTransactionArgs();
- if (!isWallet || isEth) {
- return this.data && this.data.length ? this.data : '';
- }
-
- const func = this._getTransferMethod(gas, true);
- const { options, values } = this._getTransferParams(gas, true);
-
- return this.tokenContract.at(this.token.address).getCallData(func, options, values);
+ return getTxOptions(this.api, func, options, values)
+ .then((_options) => {
+ delete _options.sender;
+ return _options;
+ });
}
- _getTransferParams (gas = false, forceToken = false) {
- const { isEth, isWallet } = this;
-
- const to = (isEth && !isWallet) ? this.recipient
- : (this.isWallet ? this.wallet.address : this.token.address);
+ _getTransactionArgs () {
+ const { isEth } = this;
+ const value = this.getValue();
const options = this.gasStore.overrideTransaction({
- from: this.sender || this.account.address,
- to
+ from: this.account.address,
+ sender: this.sender
});
- if (gas) {
- options.gas = MAX_GAS_ESTIMATION;
- }
-
- const gasTotal = new BigNumber(options.gas || DEFAULT_GAS).mul(options.gasPrice || DEFAULT_GASPRICE);
- const { token } = this.getValues(gasTotal);
-
- if (isEth && !isWallet && !forceToken) {
- options.value = token;
- options.data = this._getData(gas);
-
- return { options, values: [] };
- }
-
- if (isWallet && !forceToken) {
- const to = isEth ? this.recipient : this.token.address;
- const value = isEth ? token : new BigNumber(0);
-
- const values = [
- to, value,
- this._getData(gas)
- ];
-
- return { options, values };
+ // A simple ETH transfer
+ if (isEth) {
+ options.value = value;
+ options.data = this.data || '';
+ options.to = this.recipient;
+
+ return [ null, options ];
}
+ // A token transfer
+ const tokenContract = this.tokenContract.at(this.token.address);
const values = [
this.recipient,
- token.toFixed(0)
+ value
];
- return { options, values };
+ options.to = this.token.address;
+
+ return [ tokenContract.instance.transfer, options, values ];
}
_validatePositiveNumber (num) {
diff --git a/js/src/modals/WalletSettings/walletSettingsStore.js b/js/src/modals/WalletSettings/walletSettingsStore.js
index d31ec9eb2..c3adb812e 100644
--- a/js/src/modals/WalletSettings/walletSettingsStore.js
+++ b/js/src/modals/WalletSettings/walletSettingsStore.js
@@ -20,6 +20,7 @@ import BigNumber from 'bignumber.js';
import { validateUint, validateAddress } from '~/util/validation';
import { DEFAULT_GAS, MAX_GAS_ESTIMATION } from '~/util/constants';
+import WalletsUtils from '~/util/wallets';
const STEPS = {
EDIT: { title: 'wallet settings' },
@@ -220,8 +221,6 @@ export default class WalletSettingsStore {
this.api = api;
this.step = this.stepsKeys[0];
- this.walletInstance = wallet.instance;
-
this.initialWallet = {
address: wallet.address,
owners: wallet.owners,
@@ -280,72 +279,43 @@ export default class WalletSettingsStore {
@action send = () => {
const changes = this.changes;
- const walletInstance = this.walletInstance;
- Promise.all(changes.map((change) => this.sendChange(change, walletInstance)));
+ Promise.all(changes.map((change) => this.sendChange(change)));
this.onClose();
}
- @action sendChange = (change, walletInstance) => {
- const { method, values } = this.getChangeMethod(change, walletInstance);
+ @action sendChange = (change) => {
+ const { api, initialWallet } = this;
- const options = {
- from: this.wallet.sender,
- to: this.initialWallet.address,
- gas: MAX_GAS_ESTIMATION
- };
-
- return method
- .estimateGas(options, values)
- .then((gasEst) => {
- let gas = gasEst;
-
- if (gas.gt(DEFAULT_GAS)) {
- gas = gas.mul(1.2);
+ WalletsUtils.getChangeMethod(api, initialWallet.address, change)
+ .then((changeMethod) => {
+ if (!changeMethod) {
+ return;
}
- options.gas = gas;
- return method.postTransaction(options, values);
+ const { method, values } = changeMethod;
+
+ const options = {
+ from: this.wallet.sender,
+ to: initialWallet.address,
+ gas: MAX_GAS_ESTIMATION
+ };
+
+ return method
+ .estimateGas(options, values)
+ .then((gasEst) => {
+ let gas = gasEst;
+
+ if (gas.gt(DEFAULT_GAS)) {
+ gas = gas.mul(1.2);
+ }
+ options.gas = gas;
+
+ return method.postTransaction(options, values);
+ });
});
}
- getChangeMethod = (change, walletInstance) => {
- if (change.type === 'require') {
- return {
- method: walletInstance.changeRequirement,
- values: [ change.value ]
- };
- }
-
- if (change.type === 'dailylimit') {
- return {
- method: walletInstance.setDailyLimit,
- values: [ change.value ]
- };
- }
-
- if (change.type === 'add_owner') {
- return {
- method: walletInstance.addOwner,
- values: [ change.value ]
- };
- }
-
- if (change.type === 'change_owner') {
- return {
- method: walletInstance.changeOwner,
- values: [ change.value.from, change.value.to ]
- };
- }
-
- if (change.type === 'remove_owner') {
- return {
- method: walletInstance.removeOwner,
- values: [ change.value ]
- };
- }
- }
-
@action validateWallet = (_wallet) => {
const senderValidation = validateAddress(_wallet.sender);
const requireValidation = validateUint(_wallet.require);
diff --git a/js/src/redux/providers/personalActions.js b/js/src/redux/providers/personalActions.js
index 6200537c3..f747fa92e 100644
--- a/js/src/redux/providers/personalActions.js
+++ b/js/src/redux/providers/personalActions.js
@@ -23,7 +23,7 @@ import { attachWallets } from './walletActions';
import Contract from '~/api/contract';
import MethodDecodingStore from '~/ui/MethodDecoding/methodDecodingStore';
import WalletsUtils from '~/util/wallets';
-import { wallet as WalletAbi } from '~/contracts/abi';
+import { foundationWallet as WalletAbi } from '~/contracts/abi';
export function personalAccountsInfo (accountsInfo) {
const accounts = {};
diff --git a/js/src/redux/providers/status.js b/js/src/redux/providers/status.js
index fc5dc38ba..e58fcf6c1 100644
--- a/js/src/redux/providers/status.js
+++ b/js/src/redux/providers/status.js
@@ -227,12 +227,12 @@ export default class Status {
}
_overallStatus = (health) => {
- const all = [health.peers, health.sync, health.time].filter(x => x);
- const allNoTime = [health.peers, health.sync].filter(x => x);
+ const allWithTime = [health.peers, health.sync, health.time].filter(x => x);
+ const all = [health.peers, health.sync].filter(x => x);
const statuses = all.map(x => x.status);
const bad = statuses.find(x => x === STATUS_BAD);
- const needsAttention = allNoTime.map(x => x.status).find(x => x === STATUS_WARN);
- const message = all.map(x => x.message).filter(x => x);
+ const needsAttention = statuses.find(x => x === STATUS_WARN);
+ const message = allWithTime.map(x => x.message).filter(x => x);
if (all.length) {
return {
diff --git a/js/src/redux/providers/walletActions.js b/js/src/redux/providers/walletActions.js
index b31a2b35b..58a8faca6 100644
--- a/js/src/redux/providers/walletActions.js
+++ b/js/src/redux/providers/walletActions.js
@@ -17,19 +17,17 @@
import { isEqual, uniq } from 'lodash';
import Contract from '~/api/contract';
-import { bytesToHex, toHex } from '~/api/util/format';
import { ERROR_CODES } from '~/api/transport/error';
-import { wallet as WALLET_ABI } from '~/contracts/abi';
-import { MAX_GAS_ESTIMATION } from '~/util/constants';
+import { foundationWallet as WALLET_ABI } from '~/contracts/abi';
import WalletsUtils from '~/util/wallets';
-
import { newError } from '~/ui/Errors/actions';
-
-const UPDATE_OWNERS = 'owners';
-const UPDATE_REQUIRE = 'require';
-const UPDATE_DAILYLIMIT = 'dailylimit';
-const UPDATE_TRANSACTIONS = 'transactions';
-const UPDATE_CONFIRMATIONS = 'confirmations';
+import {
+ UPDATE_OWNERS,
+ UPDATE_REQUIRE,
+ UPDATE_DAILYLIMIT,
+ UPDATE_TRANSACTIONS,
+ UPDATE_CONFIRMATIONS
+} from '~/util/wallets/updates';
export function confirmOperation (address, owner, operation) {
return modifyOperation('confirm', address, owner, operation);
@@ -39,41 +37,25 @@ export function revokeOperation (address, owner, operation) {
return modifyOperation('revoke', address, owner, operation);
}
-function modifyOperation (method, address, owner, operation) {
+function modifyOperation (modification, address, owner, operation) {
return (dispatch, getState) => {
const { api } = getState();
- const contract = new Contract(api, WALLET_ABI).at(address);
-
- const options = {
- from: owner,
- gas: MAX_GAS_ESTIMATION
- };
-
- const values = [ operation ];
dispatch(setOperationPendingState(address, operation, true));
- contract.instance[method]
- .estimateGas(options, values)
- .then((gas) => {
- options.gas = gas.mul(1.2);
- return contract.instance[method].postTransaction(options, values);
- })
+ WalletsUtils.postModifyOperation(api, address, modification, owner, operation)
.then((requestId) => {
- return api
- .pollMethod('parity_checkRequest', requestId)
- .catch((e) => {
- dispatch(setOperationPendingState(address, operation, false));
- if (e.code === ERROR_CODES.REQUEST_REJECTED) {
- return;
- }
-
- throw e;
- });
+ return api.pollMethod('parity_checkRequest', requestId);
})
.catch((error) => {
- dispatch(setOperationPendingState(address, operation, false));
+ if (error.code === ERROR_CODES.REQUEST_REJECTED) {
+ return;
+ }
+
dispatch(newError(error));
+ })
+ .then(() => {
+ dispatch(setOperationPendingState(address, operation, false));
});
};
}
@@ -97,14 +79,18 @@ export function attachWallets (_wallets) {
return dispatch(updateWallets({ wallets: {}, walletsAddresses: [], filterSubId: null }));
}
- const filterOptions = {
- fromBlock: 0,
- toBlock: 'latest',
- address: nextAddresses
- };
-
+ // Filter the logs from the current block
api.eth
- .newFilter(filterOptions)
+ .blockNumber()
+ .then((block) => {
+ const filterOptions = {
+ fromBlock: block,
+ toBlock: 'latest',
+ address: nextAddresses
+ };
+
+ return api.eth.newFilter(filterOptions);
+ })
.then((filterId) => {
dispatch(updateWallets({ wallets: _wallets, walletsAddresses: nextAddresses, filterSubId: filterId }));
})
@@ -142,7 +128,6 @@ export function load (api) {
api.eth
.getFilterChanges(filterSubId)
- .then((logs) => contract.parseEventLogs(logs))
.then((logs) => {
parseLogs(logs)(dispatch, getState);
})
@@ -292,202 +277,57 @@ function fetchWalletDailylimit (contract) {
}
function fetchWalletConfirmations (contract, _operations, _owners = null, _transactions = null, getState) {
- const walletInstance = contract.instance;
-
const wallet = getState().wallet.wallets[contract.address];
const owners = _owners || (wallet && wallet.owners) || null;
const transactions = _transactions || (wallet && wallet.transactions) || null;
- // Full load if no operations given, or if the one given aren't loaded yet
- const fullLoad = !Array.isArray(_operations) || _operations
- .filter((op) => !wallet.confirmations.find((conf) => conf.operation === op))
- .length > 0;
+ const cache = { owners, transactions };
- let promise;
-
- if (fullLoad) {
- promise = walletInstance
- .ConfirmationNeeded
- .getAllLogs()
- .then((logs) => {
- return logs.map((log) => ({
- initiator: log.params.initiator.value,
- to: log.params.to.value,
- data: log.params.data.value,
- value: log.params.value.value,
- operation: bytesToHex(log.params.operation.value),
- transactionIndex: log.transactionIndex,
- transactionHash: log.transactionHash,
- blockNumber: log.blockNumber,
- confirmedBy: []
- }));
- })
- .then((logs) => {
- return logs.sort((logA, logB) => {
- const comp = logA.blockNumber.comparedTo(logB.blockNumber);
-
- if (comp !== 0) {
- return comp;
- }
-
- return logA.transactionIndex.comparedTo(logB.transactionIndex);
- });
- })
- .then((confirmations) => {
- if (confirmations.length === 0) {
- return confirmations;
- }
-
- // Only fetch confirmations for operations not
- // yet confirmed (ie. not yet a transaction)
- if (transactions) {
- const operations = transactions
- .filter((t) => t.operation)
- .map((t) => t.operation);
-
- return confirmations.filter((confirmation) => {
- return !operations.includes(confirmation.operation);
- });
- }
-
- return confirmations;
- });
- } else {
- const { confirmations } = wallet;
- const nextConfirmations = confirmations
- .filter((conf) => _operations.includes(conf.operation));
-
- promise = Promise.resolve(nextConfirmations);
- }
-
- return promise
+ return WalletsUtils.fetchPendingTransactions(contract, cache)
.then((confirmations) => {
- if (confirmations.length === 0) {
- return confirmations;
- }
-
- const uniqConfirmations = Object.values(
- confirmations.reduce((confirmations, confirmation) => {
- confirmations[confirmation.operation] = confirmation;
- return confirmations;
- }, {})
- );
-
- const operations = uniqConfirmations.map((conf) => conf.operation);
-
- return Promise
- .all(operations.map((op) => fetchOperationConfirmations(contract, op, owners)))
- .then((confirmedBys) => {
- uniqConfirmations.forEach((_, index) => {
- uniqConfirmations[index].confirmedBy = confirmedBys[index];
- });
-
- return uniqConfirmations;
- });
- })
- .then((confirmations) => {
- const prevConfirmations = wallet.confirmations || [];
- const nextConfirmations = prevConfirmations
- .filter((conA) => !confirmations.find((conB) => conB.operation === conA.operation))
- .concat(confirmations)
- .map((conf) => ({
- ...conf,
- pending: false
- }));
-
return {
key: UPDATE_CONFIRMATIONS,
- value: nextConfirmations
+ value: confirmations
};
});
}
-function fetchOperationConfirmations (contract, operation, owners = null) {
- if (!owners) {
- console.warn('[fetchOperationConfirmations] try to provide the owners for the Wallet', contract.address);
- }
-
- const walletInstance = contract.instance;
-
- const promise = owners
- ? Promise.resolve({ value: owners })
- : fetchWalletOwners(contract);
-
- return promise
- .then((result) => {
- const owners = result.value;
-
- return Promise
- .all(owners.map((owner) => walletInstance.hasConfirmed.call({}, [ operation, owner ])))
- .then((data) => {
- return owners.filter((owner, index) => data[index]);
- });
- });
-}
-
function parseLogs (logs) {
return (dispatch, getState) => {
if (!logs || logs.length === 0) {
return;
}
- const WalletSignatures = WalletsUtils.getWalletSignatures();
-
+ const { api } = getState();
const updates = {};
- logs.forEach((log) => {
- const { address, topics } = log;
- const eventSignature = toHex(topics[0]);
- const prev = updates[address] || {
- [ UPDATE_DAILYLIMIT ]: true,
- address
- };
+ const promises = logs.map((log) => {
+ const { address } = log;
- switch (eventSignature) {
- case WalletSignatures.OwnerChanged:
- case WalletSignatures.OwnerAdded:
- case WalletSignatures.OwnerRemoved:
- updates[address] = {
- ...prev,
- [ UPDATE_OWNERS ]: true
+ return WalletsUtils.logToUpdate(api, address, log)
+ .then((update) => {
+ const prev = updates[address] || {
+ [ UPDATE_DAILYLIMIT ]: true,
+ address
};
- return;
- case WalletSignatures.RequirementChanged:
- updates[address] = {
- ...prev,
- [ UPDATE_REQUIRE ]: true
- };
- return;
+ if (update[UPDATE_CONFIRMATIONS]) {
+ const operations = (prev[UPDATE_CONFIRMATIONS] || []).concat(update[UPDATE_CONFIRMATIONS]);
- case WalletSignatures.ConfirmationNeeded:
- case WalletSignatures.Confirmation:
- case WalletSignatures.Revoke:
- const operation = bytesToHex(log.params.operation.value);
+ update[UPDATE_CONFIRMATIONS] = uniq(operations);
+ }
updates[address] = {
...prev,
- [ UPDATE_CONFIRMATIONS ]: uniq(
- (prev[UPDATE_CONFIRMATIONS] || []).concat(operation)
- )
+ ...update
};
-
- return;
-
- case WalletSignatures.Deposit:
- case WalletSignatures.SingleTransact:
- case WalletSignatures.MultiTransact:
- case WalletSignatures.Old.SingleTransact:
- case WalletSignatures.Old.MultiTransact:
- updates[address] = {
- ...prev,
- [ UPDATE_TRANSACTIONS ]: true
- };
- return;
- }
+ });
});
- fetchWalletsInfo(updates)(dispatch, getState);
+ return Promise.all(promises)
+ .then(() => {
+ fetchWalletsInfo(updates)(dispatch, getState);
+ });
};
}
diff --git a/js/src/util/tx.js b/js/src/util/tx.js
index 9ab8b6599..e325e6024 100644
--- a/js/src/util/tx.js
+++ b/js/src/util/tx.js
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see
+ WARNING: The web browser dapp is not safe as a general purpose browser. + Make sure to only visit web3-enabled sites that you trust. + Do not use it to browse web2.0 and never log in to any service - web3 dapps should not require that. +
+