tests fix wip commit

This commit is contained in:
mmv 2019-03-14 17:02:04 +04:00
parent d4c6fda203
commit 122be46934
32 changed files with 177 additions and 134 deletions

View File

@ -135,7 +135,7 @@
"collectCoverageFrom": [ "collectCoverageFrom": [
"src/**/*.{js,jsx}" "src/**/*.{js,jsx}"
], ],
"setupTestFrameworkScriptFile": "<rootDir>/config/jest/jest.setup.js", "setupFilesAfterEnv": ["<rootDir>/config/jest/jest.setup.js"],
"setupFiles": [ "setupFiles": [
"<rootDir>/config/webpack.config.test.js", "<rootDir>/config/webpack.config.test.js",
"<rootDir>/config/polyfills.js", "<rootDir>/config/polyfills.js",

View File

@ -2,7 +2,6 @@
import contract from 'truffle-contract' import contract from 'truffle-contract'
import { ensureOnce } from '~/utils/singleton' import { ensureOnce } from '~/utils/singleton'
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { promisify } from '~/utils/promisify'
import GnosisSafeSol from '#/GnosisSafe.json' import GnosisSafeSol from '#/GnosisSafe.json'
import ProxyFactorySol from '#/ProxyFactory.json' import ProxyFactorySol from '#/ProxyFactory.json'
import { calculateGasOf, calculateGasPrice } from '~/logic/wallets/ethTransactions' import { calculateGasOf, calculateGasPrice } from '~/logic/wallets/ethTransactions'
@ -42,7 +41,7 @@ const instanciateMasterCopies = async () => {
// ONLY USED IN TEST ENVIRONMENT // ONLY USED IN TEST ENVIRONMENT
const createMasterCopies = async () => { const createMasterCopies = async () => {
const web3 = getWeb3() const web3 = getWeb3()
const accounts = await promisify(cb => web3.eth.getAccounts(cb)) const accounts = await web3.eth.getAccounts()
const userAccount = accounts[0] const userAccount = accounts[0]
const ProxyFactory = getCreateProxyFactoryContract(web3) const ProxyFactory = getCreateProxyFactoryContract(web3)

View File

@ -23,8 +23,17 @@ export const approveTransaction = async (
// return executeTransaction(safeAddress, to, valueInWei, data, operation, nonce, sender) // return executeTransaction(safeAddress, to, valueInWei, data, operation, nonce, sender)
const safe = await getSafeEthereumInstance(safeAddress) const safe = await getSafeEthereumInstance(safeAddress)
const txGasEstimate = await generateTxGasEstimateFrom(safe, safeAddress, data, to, valueInWei, operation) const txGasEstimate = await generateTxGasEstimateFrom(safe, safeAddress, data, to, valueInWei, operation)
const signature = const signature = await generateMetamaskSignature(
await generateMetamaskSignature(safe, safeAddress, sender, to, valueInWei, nonce, data, operation, txGasEstimate) safe,
safeAddress,
sender,
to,
valueInWei,
nonce,
data,
operation,
txGasEstimate,
)
storeSignature(safeAddress, nonce, signature) storeSignature(safeAddress, nonce, signature)
return undefined return undefined
@ -33,7 +42,7 @@ export const approveTransaction = async (
const gnosisSafe = await getSafeEthereumInstance(safeAddress) const gnosisSafe = await getSafeEthereumInstance(safeAddress)
const contractTxHash = await gnosisSafe.getTransactionHash(to, valueInWei, data, operation, 0, 0, 0, 0, 0, nonce) const contractTxHash = await gnosisSafe.getTransactionHash(to, valueInWei, data, operation, 0, 0, 0, 0, 0, nonce)
const approveData = gnosisSafe.contract.approveHash.getData(contractTxHash) const approveData = gnosisSafe.contract.methods.approveHash(contractTxHash).encodeABI()
const gas = await calculateGasOf(approveData, sender, safeAddress) const gas = await calculateGasOf(approveData, sender, safeAddress)
const txReceipt = await gnosisSafe.approveHash(contractTxHash, { from: sender, gas, gasPrice }) const txReceipt = await gnosisSafe.approveHash(contractTxHash, { from: sender, gas, gasPrice })
@ -60,16 +69,35 @@ export const executeTransaction = async (
if (signaturesViaMetamask()) { if (signaturesViaMetamask()) {
const safe = await getSafeEthereumInstance(safeAddress) const safe = await getSafeEthereumInstance(safeAddress)
const txGasEstimate = await generateTxGasEstimateFrom(safe, safeAddress, data, to, valueInWei, operation) const txGasEstimate = await generateTxGasEstimateFrom(safe, safeAddress, data, to, valueInWei, operation)
const signature = const signature = await generateMetamaskSignature(
await generateMetamaskSignature(safe, safeAddress, sender, to, valueInWei, nonce, data, operation, txGasEstimate) safe,
safeAddress,
sender,
to,
valueInWei,
nonce,
data,
operation,
txGasEstimate,
)
storeSignature(safeAddress, nonce, signature) storeSignature(safeAddress, nonce, signature)
const sigs = getSignaturesFrom(safeAddress, nonce) const sigs = getSignaturesFrom(safeAddress, nonce)
const threshold = await safe.getThreshold() const threshold = await safe.getThreshold()
const gas = const gas = await estimateDataGas(
await estimateDataGas(safe, to, valueInWei, data, operation, txGasEstimate, 0, nonce, Number(threshold), 0) safe,
to,
valueInWei,
data,
operation,
txGasEstimate,
0,
nonce,
Number(threshold),
0,
)
const numOwners = await safe.getOwners() const numOwners = await safe.getOwners()
const gasIncludingRemovingStoreUpfront = gas + txGasEstimate + (numOwners.length * 15000) const gasIncludingRemovingStoreUpfront = gas + txGasEstimate + numOwners.length * 15000
const txReceipt = await safe.execTransaction( const txReceipt = await safe.execTransaction(
to, to,
@ -94,24 +122,17 @@ export const executeTransaction = async (
const gnosisSafe = await getSafeEthereumInstance(safeAddress) const gnosisSafe = await getSafeEthereumInstance(safeAddress)
const signatures = buildSignaturesFrom(ownersWhoHasSigned, sender) const signatures = buildSignaturesFrom(ownersWhoHasSigned, sender)
const txExecutionData = const txExecutionData = gnosisSafe.contract.methods
gnosisSafe.contract.execTransaction.getData(to, valueInWei, data, operation, 0, 0, 0, 0, 0, signatures) .execTransaction(to, valueInWei, data, operation, 0, 0, 0, 0, 0, signatures)
.encodeABI()
const gas = await calculateGasOf(txExecutionData, sender, safeAddress) const gas = await calculateGasOf(txExecutionData, sender, safeAddress)
const numOwners = await gnosisSafe.getOwners() const numOwners = await gnosisSafe.getOwners()
const gasIncludingRemovingStoreUpfront = gas + (numOwners.length * 15000) const gasIncludingRemovingStoreUpfront = gas + numOwners.length * 15000
const txReceipt = await gnosisSafe.execTransaction( const txReceipt = await gnosisSafe.execTransaction(to, valueInWei, data, operation, 0, 0, 0, 0, 0, signatures, {
to, from: sender,
valueInWei, gas: gasIncludingRemovingStoreUpfront,
data, gasPrice,
operation, })
0,
0,
0,
0,
0,
signatures,
{ from: sender, gas: gasIncludingRemovingStoreUpfront, gasPrice },
)
const txHash = txReceipt.tx const txHash = txReceipt.tx
await checkReceiptStatus(txHash) await checkReceiptStatus(txHash)

View File

@ -42,7 +42,7 @@ export const createTransaction = async (
const web3 = getWeb3() const web3 = getWeb3()
const safeAddress = safe.get('address') const safeAddress = safe.get('address')
const threshold = safe.get('threshold') const threshold = safe.get('threshold')
const valueInWei = web3.toWei(value, 'ether') const valueInWei = web3.utils.toWei(value, 'ether')
const CALL = 0 const CALL = 0
const isExecution = hasOneOwner(safe) || threshold === 1 const isExecution = hasOneOwner(safe) || threshold === 1

View File

@ -1,6 +1,5 @@
// @flow // @flow
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { promisify } from '~/utils/promisify'
import { BigNumber } from 'bignumber.js' import { BigNumber } from 'bignumber.js'
import { EMPTY_DATA } from '~/logic/wallets/ethTransactions' import { EMPTY_DATA } from '~/logic/wallets/ethTransactions'
import { getSignaturesFrom } from '~/utils/localStorage/signatures' import { getSignaturesFrom } from '~/utils/localStorage/signatures'
@ -21,7 +20,6 @@ const estimateDataGasCosts = (data) => {
return data.match(/.{2}/g).reduce(reducer, 0) return data.match(/.{2}/g).reduce(reducer, 0)
} }
export const estimateDataGas = ( export const estimateDataGas = (
safe: any, safe: any,
to: string, to: string,
@ -42,8 +40,9 @@ export const estimateDataGas = (
const signatureCost = signatureCount * (68 + 2176 + 2176) // array count (3 -> r, s, v) * signature count const signatureCost = signatureCount * (68 + 2176 + 2176) // array count (3 -> r, s, v) * signature count
const sigs = getSignaturesFrom(safe.address, nonce) const sigs = getSignaturesFrom(safe.address, nonce)
const payload = safe.contract.execTransaction const payload = safe.contract.methods
.getData(to, valueInWei, data, operation, txGasEstimate, 0, gasPrice, gasToken, refundReceiver, sigs) .execTransaction(to, valueInWei, data, operation, txGasEstimate, 0, gasPrice, gasToken, refundReceiver, sigs)
.encodeABI()
let dataGasEstimate = estimateDataGasCosts(payload) + signatureCost let dataGasEstimate = estimateDataGasCosts(payload) + signatureCost
if (dataGasEstimate > 65536) { if (dataGasEstimate > 65536) {
@ -64,19 +63,19 @@ export const generateTxGasEstimateFrom = async (
operation: number, operation: number,
) => { ) => {
try { try {
const estimateData = safe.contract.requiredTxGas.getData(to, valueInWei, data, operation) const estimateData = safe.contract.methods.requiredTxGas(to, valueInWei, data, operation).encodeABI()
const estimateResponse = await promisify(cb => getWeb3().eth.call({ const estimateResponse = await getWeb3().eth.call({
to: safeAddress, to: safeAddress,
from: safeAddress, from: safeAddress,
data: estimateData, data: estimateData,
}, cb)) })
const txGasEstimate = new BigNumber(estimateResponse.substring(138), 16) const txGasEstimate = new BigNumber(estimateResponse.substring(138), 16)
// Add 10k else we will fail in case of nested calls // Add 10k else we will fail in case of nested calls
return Promise.resolve(txGasEstimate.toNumber() + 10000) return Promise.resolve(txGasEstimate.toNumber() + 10000)
} catch (error) { } catch (error) {
// eslint-disable-next-line // eslint-disable-next-line
console.log("Error calculating tx gas estimation " + error) console.log('Error calculating tx gas estimation ' + error)
return Promise.resolve(0) return Promise.resolve(0)
} }
} }
@ -151,8 +150,16 @@ export const generateMetamaskSignature = async (
txGasEstimate: number, txGasEstimate: number,
) => { ) => {
const web3 = getWeb3() const web3 = getWeb3()
const typedData = const typedData = await generateTypedDataFrom(
await generateTypedDataFrom(safe, safeAddress, to, valueInWei, nonce, data, operation, txGasEstimate) safe,
safeAddress,
to,
valueInWei,
nonce,
data,
operation,
txGasEstimate,
)
const jsonTypedData = JSON.stringify(typedData) const jsonTypedData = JSON.stringify(typedData)
const signedTypedData = { const signedTypedData = {
@ -163,7 +170,7 @@ export const generateMetamaskSignature = async (
params: [jsonTypedData, sender], params: [jsonTypedData, sender],
from: sender, from: sender,
} }
const txSignedResponse = await promisify(cb => web3.currentProvider.sendAsync(signedTypedData, cb)) const txSignedResponse = await web3.currentProvider.sendAsync(signedTypedData)
return txSignedResponse.result.replace(EMPTY_DATA, '') return txSignedResponse.result.replace(EMPTY_DATA, '')
} }

View File

@ -1,7 +1,6 @@
// @flow // @flow
import { BigNumber } from 'bignumber.js' import { BigNumber } from 'bignumber.js'
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { promisify } from '~/utils/promisify'
import { enhancedFetch } from '~/utils/fetch' import { enhancedFetch } from '~/utils/fetch'
// const MAINNET_NETWORK = 1 // const MAINNET_NETWORK = 1
@ -13,7 +12,7 @@ export const checkReceiptStatus = async (hash: string) => {
} }
const web3 = getWeb3() const web3 = getWeb3()
const txReceipt = await promisify(cb => web3.eth.getTransactionReceipt(hash, cb)) const txReceipt = await web3.eth.getTransactionReceipt(hash)
const { status } = txReceipt const { status } = txReceipt
if (!status) { if (!status) {
@ -53,7 +52,7 @@ export const calculateGasPrice = async () => {
export const calculateGasOf = async (data: Object, from: string, to: string) => { export const calculateGasOf = async (data: Object, from: string, to: string) => {
const web3 = getWeb3() const web3 = getWeb3()
try { try {
const gas = await promisify(cb => web3.eth.estimateGas({ data, from, to }, cb)) const gas = await web3.eth.estimateGas({ data, from, to })
return gas * 2 return gas * 2
} catch (err) { } catch (err) {

View File

@ -5,5 +5,5 @@ import { BigNumber } from 'bignumber.js'
export const toNative = async (amt: string | number | BigNumber, decimal: number): Promise<BigNumber> => { export const toNative = async (amt: string | number | BigNumber, decimal: number): Promise<BigNumber> => {
const web3 = getWeb3() const web3 = getWeb3()
return web3.toBigNumber(amt).mul(10 ** decimal) return web3.utils.BN(amt).mul(10 ** decimal)
} }

View File

@ -12,14 +12,13 @@ import Review from './Review'
import selector, { type SelectorProps } from './selector' import selector, { type SelectorProps } from './selector'
import actions, { type Actions } from './actions' import actions, { type Actions } from './actions'
const getSteps = () => [ const getSteps = () => ['Fill Owner Form', 'Review Add order operation']
'Fill Owner Form', 'Review Add order operation',
]
type Props = SelectorProps & Actions & { type Props = SelectorProps &
safe: Safe, Actions & {
threshold: number, safe: Safe,
} threshold: number,
}
type State = { type State = {
done: boolean, done: boolean,
@ -44,7 +43,7 @@ export const addOwner = async (values: Object, safe: Safe, threshold: number, ex
const newOwnerAddress = values[OWNER_ADDRESS_PARAM] const newOwnerAddress = values[OWNER_ADDRESS_PARAM]
const newOwnerName = values[NAME_PARAM] const newOwnerName = values[NAME_PARAM]
const data = gnosisSafe.contract.addOwnerWithThreshold.getData(newOwnerAddress, newThreshold) const data = gnosisSafe.contract.methods.addOwnerWithThreshold(newOwnerAddress, newThreshold).encodeABI()
await createTransaction(safe, `Add Owner ${newOwnerName}`, safeAddress, 0, nonce, executor, data) await createTransaction(safe, `Add Owner ${newOwnerName}`, safeAddress, 0, nonce, executor, data)
setOwners(safeAddress, safe.get('owners').push(makeOwner({ name: newOwnerName, address: newOwnerAddress }))) setOwners(safeAddress, safe.get('owners').push(makeOwner({ name: newOwnerName, address: newOwnerAddress })))
} }
@ -90,15 +89,16 @@ class AddOwner extends React.Component<Props, State> {
onReset={this.onReset} onReset={this.onReset}
> >
<Stepper.Page numOwners={safe.get('owners').count()} threshold={safe.get('threshold')} addresses={addresses}> <Stepper.Page numOwners={safe.get('owners').count()} threshold={safe.get('threshold')} addresses={addresses}>
{ AddOwnerForm } {AddOwnerForm}
</Stepper.Page>
<Stepper.Page>
{ Review }
</Stepper.Page> </Stepper.Page>
<Stepper.Page>{Review}</Stepper.Page>
</Stepper> </Stepper>
</React.Fragment> </React.Fragment>
) )
} }
} }
export default connect(selector, actions)(AddOwner) export default connect(
selector,
actions,
)(AddOwner)

View File

@ -37,10 +37,9 @@ type State = {
filter: string, filter: string,
} }
const filterBy = (filter: string, tokens: List<Token>): List<Token> => const filterBy = (filter: string, tokens: List<Token>): List<Token> => tokens.filter((token: Token) => !filter
tokens.filter((token: Token) => !filter || || token.get('symbol').toLowerCase().includes(filter.toLowerCase())
token.get('symbol').toLowerCase().includes(filter.toLowerCase()) || || token.get('name').toLowerCase().includes(filter.toLowerCase()))
token.get('name').toLowerCase().includes(filter.toLowerCase()))
class Tokens extends React.Component<Props, State> { class Tokens extends React.Component<Props, State> {
@ -132,4 +131,3 @@ class Tokens extends React.Component<Props, State> {
const TokenComponent = withStyles(styles)(Tokens) const TokenComponent = withStyles(styles)(Tokens)
export default connect(undefined, actions)(TokenComponent) export default connect(undefined, actions)(TokenComponent)

View File

@ -16,7 +16,9 @@ import Paragraph from '~/components/layout/Paragraph'
import Modal from '~/components/Modal' import Modal from '~/components/Modal'
import { type Column, cellWidth } from '~/components/Table/TableHead' import { type Column, cellWidth } from '~/components/Table/TableHead'
import Table from '~/components/Table' import Table from '~/components/Table'
import { getBalanceData, generateColumns, BALANCE_TABLE_ASSET_ID, type BalanceRow, filterByZero } from './dataFetcher' import {
getBalanceData, generateColumns, BALANCE_TABLE_ASSET_ID, type BalanceRow, filterByZero,
} from './dataFetcher'
import Tokens from './Tokens' import Tokens from './Tokens'
import Send from './Send' import Send from './Send'
import Receive from './Receive' import Receive from './Receive'
@ -114,32 +116,50 @@ class Balances extends React.Component<Props, State> {
> >
{(sortedData: Array<BalanceRow>) => sortedData.map((row: any, index: number) => ( {(sortedData: Array<BalanceRow>) => sortedData.map((row: any, index: number) => (
<TableRow tabIndex={-1} key={index} className={classes.hide}> <TableRow tabIndex={-1} key={index} className={classes.hide}>
{ autoColumns.map((column: Column) => ( {autoColumns.map((column: Column) => (
<TableCell key={column.id} style={cellWidth(column.width)} numeric={column.numeric} component="td"> <TableCell key={column.id} style={cellWidth(column.width)} align={column.align} component="td">
{row[column.id]} {row[column.id]}
</TableCell> </TableCell>
)) } ))}
<TableCell component="td"> <TableCell component="td">
<Row align="end" className={classes.actions}> <Row align="end" className={classes.actions}>
{ granted && {granted && (
<Button variant="contained" size="small" color="secondary" className={classes.send} onClick={this.onShow('Send')}> <Button
variant="contained"
size="small"
color="secondary"
className={classes.send}
onClick={this.onShow('Send')}
>
<CallMade className={classNames(classes.leftIcon, classes.iconSmall)} /> <CallMade className={classNames(classes.leftIcon, classes.iconSmall)} />
Send Send
</Button> </Button>
} )}
<Button variant="contained" size="small" color="secondary" className={classes.receive} onClick={this.onShow('Receive')}> <Button
variant="contained"
size="small"
color="secondary"
className={classes.receive}
onClick={this.onShow('Receive')}
>
<CallReceived className={classNames(classes.leftIcon, classes.iconSmall)} /> <CallReceived className={classNames(classes.leftIcon, classes.iconSmall)} />
Receive Receive
</Button> </Button>
</Row> </Row>
</TableCell> </TableCell>
</TableRow> </TableRow>
))} ))
}
</Table> </Table>
<Modal title="Send Tokens" description="Send Tokens Form" handleClose={this.onHide('Send')} open={showSend}> <Modal title="Send Tokens" description="Send Tokens Form" handleClose={this.onHide('Send')} open={showSend}>
<Send onClose={this.onHide('Send')} /> <Send onClose={this.onHide('Send')} />
</Modal> </Modal>
<Modal title="Receive Tokens" description="Receive Tokens Form" handleClose={this.onHide('Receive')} open={showReceive}> <Modal
title="Receive Tokens"
description="Receive Tokens Form"
handleClose={this.onHide('Receive')}
open={showReceive}
>
<Receive onClose={this.onHide('Receive')} /> <Receive onClose={this.onHide('Receive')} />
</Modal> </Modal>
</React.Fragment> </React.Fragment>

View File

@ -48,7 +48,7 @@ export const removeOwner = async (
const storedOwners = await gnosisSafe.getOwners() const storedOwners = await gnosisSafe.getOwners()
const index = storedOwners.findIndex(ownerAddress => ownerAddress === userToRemove) const index = storedOwners.findIndex(ownerAddress => ownerAddress === userToRemove)
const prevAddress = index === 0 ? SENTINEL_ADDRESS : storedOwners[index - 1] const prevAddress = index === 0 ? SENTINEL_ADDRESS : storedOwners[index - 1]
const data = gnosisSafe.contract.removeOwner.getData(prevAddress, userToRemove, newThreshold) const data = gnosisSafe.contract.removeOwner(prevAddress, userToRemove, newThreshold).encodeABI()
const text = name || userToRemove const text = name || userToRemove
return createTransaction(safe, `Remove Owner ${text}`, safeAddress, 0, nonce, executor, data) return createTransaction(safe, `Remove Owner ${text}`, safeAddress, 0, nonce, executor, data)

View File

@ -36,7 +36,7 @@ const getTransferData = async (tokenAddress: string, to: string, amount: BigNumb
const StandardToken = await getStandardTokenContract() const StandardToken = await getStandardTokenContract()
const myToken = await StandardToken.at(tokenAddress) const myToken = await StandardToken.at(tokenAddress)
return myToken.contract.transfer.getData(to, amount) return myToken.contract.transfer(to, amount).encodeABI()
} }
const processTokenTransfer = async (safe: Safe, token: Token, to: string, amount: number, userAddress: string) => { const processTokenTransfer = async (safe: Safe, token: Token, to: string, amount: number, userAddress: string) => {

View File

@ -32,14 +32,14 @@ class Threshold extends React.PureComponent<Props, State> {
onThreshold = async (values: Object) => { onThreshold = async (values: Object) => {
try { try {
const { safe, userAddress } = this.props // , fetchThreshold } = this.props const { safe, userAddress, fetchTransactions } = this.props // , fetchThreshold } = this.props
const newThreshold = values[THRESHOLD_PARAM] const newThreshold = values[THRESHOLD_PARAM]
const safeAddress = safe.get('address') const safeAddress = safe.get('address')
const gnosisSafe = await getSafeEthereumInstance(safeAddress) const gnosisSafe = await getSafeEthereumInstance(safeAddress)
const nonce = await gnosisSafe.nonce() const nonce = await gnosisSafe.nonce()
const data = gnosisSafe.contract.changeThreshold.getData(newThreshold) const data = gnosisSafe.contract.changeThreshold(newThreshold).encodeABI()
await createTransaction(safe, `Change Safe's threshold [${nonce}]`, safeAddress, 0, nonce, userAddress, data) await createTransaction(safe, `Change Safe's threshold [${nonce}]`, safeAddress, 0, nonce, userAddress, data)
await this.props.fetchTransactions(safeAddress) await fetchTransactions(safeAddress)
this.setState({ done: true }) this.setState({ done: true })
} catch (error) { } catch (error) {
this.setState({ done: false }) this.setState({ done: false })
@ -49,8 +49,10 @@ class Threshold extends React.PureComponent<Props, State> {
} }
onReset = () => { onReset = () => {
const { onReset } = this.props
this.setState({ done: false }) this.setState({ done: false })
this.props.onReset()
onReset()
} }
render() { render() {

View File

@ -5,7 +5,6 @@ import TextField from '~/components/forms/TextField'
import { composeValidators, required, mustBeEthereumAddress, uniqueAddress } from '~/components/forms/validator' import { composeValidators, required, mustBeEthereumAddress, uniqueAddress } from '~/components/forms/validator'
import Block from '~/components/layout/Block' import Block from '~/components/layout/Block'
import Heading from '~/components/layout/Heading' import Heading from '~/components/layout/Heading'
import { promisify } from '~/utils/promisify'
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { EMPTY_DATA } from '~/logic/wallets/ethTransactions' import { EMPTY_DATA } from '~/logic/wallets/ethTransactions'
import { getStandardTokenContract } from '~/routes/tokens/store/actions/fetchTokens' import { getStandardTokenContract } from '~/routes/tokens/store/actions/fetchTokens'
@ -17,7 +16,7 @@ type Props = {
export const TOKEN_ADRESS_PARAM = 'tokenAddress' export const TOKEN_ADRESS_PARAM = 'tokenAddress'
export const token = async (tokenAddress: string) => { export const token = async (tokenAddress: string) => {
const code = await promisify(cb => getWeb3().eth.getCode(tokenAddress, cb)) const code = await getWeb3().eth.getCode(tokenAddress)
const isDeployed = code !== EMPTY_DATA const isDeployed = code !== EMPTY_DATA
if (!isDeployed) { if (!isDeployed) {

View File

@ -3,11 +3,12 @@ import * as React from 'react'
import Stepper from '~/components/Stepper' import Stepper from '~/components/Stepper'
import { getHumanFriendlyToken } from '~/routes/tokens/store/actions/fetchTokens' import { getHumanFriendlyToken } from '~/routes/tokens/store/actions/fetchTokens'
import FirstPage, { TOKEN_ADRESS_PARAM } from '~/routes/tokens/component/AddToken/FirstPage' import FirstPage, { TOKEN_ADRESS_PARAM } from '~/routes/tokens/component/AddToken/FirstPage'
import SecondPage, { TOKEN_SYMBOL_PARAM, TOKEN_DECIMALS_PARAM, TOKEN_LOGO_URL_PARAM, TOKEN_NAME_PARAM } from '~/routes/tokens/component/AddToken/SecondPage' import SecondPage, {
TOKEN_SYMBOL_PARAM, TOKEN_DECIMALS_PARAM, TOKEN_LOGO_URL_PARAM, TOKEN_NAME_PARAM,
} from '~/routes/tokens/component/AddToken/SecondPage'
import { makeToken, type Token } from '~/routes/tokens/store/model/token' import { makeToken, type Token } from '~/routes/tokens/store/model/token'
import addTokenAction from '~/routes/tokens/store/actions/addToken' import addTokenAction from '~/routes/tokens/store/actions/addToken'
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { promisify } from '~/utils/promisify'
import { EMPTY_DATA } from '~/logic/wallets/ethTransactions' import { EMPTY_DATA } from '~/logic/wallets/ethTransactions'
import Review from './Review' import Review from './Review'
@ -69,17 +70,18 @@ class AddToken extends React.Component<Props, State> {
const tokenAddress = values[TOKEN_ADRESS_PARAM] const tokenAddress = values[TOKEN_ADRESS_PARAM]
const erc20Token = await getHumanFriendlyToken() const erc20Token = await getHumanFriendlyToken()
const instance = await erc20Token.at(tokenAddress) const instance = await erc20Token.at(tokenAddress)
const web3 = getWeb3()
const dataName = await instance.contract.name.getData() const dataName = await instance.contract.methods.name().encodeABI()
const nameResult = await promisify(cb => getWeb3().eth.call({ to: tokenAddress, data: dataName }, cb)) const nameResult = await web3.eth.call({ to: tokenAddress, data: dataName })
const hasName = nameResult !== EMPTY_DATA const hasName = nameResult !== EMPTY_DATA
const dataSymbol = await instance.contract.symbol.getData() const dataSymbol = await instance.contract.methods.symbol().encodeABI()
const symbolResult = await promisify(cb => getWeb3().eth.call({ to: tokenAddress, data: dataSymbol }, cb)) const symbolResult = await web3.eth.call({ to: tokenAddress, data: dataSymbol })
const hasSymbol = symbolResult !== EMPTY_DATA const hasSymbol = symbolResult !== EMPTY_DATA
const dataDecimals = await instance.contract.decimals.getData() const dataDecimals = await instance.contract.methods.decimals().encodeABI()
const decimalsResult = await promisify(cb => getWeb3().eth.call({ to: tokenAddress, data: dataDecimals }, cb)) const decimalsResult = await web3.eth.call({ to: tokenAddress, data: dataDecimals })
const hasDecimals = decimalsResult !== EMPTY_DATA const hasDecimals = decimalsResult !== EMPTY_DATA

View File

@ -76,10 +76,12 @@ class TokenComponent extends React.PureComponent<Props, State> {
color="primary" color="primary"
/> />
{symbol} {symbol}
{ token.get('removable') && { token.get('removable')
<IconButton aria-label="Delete" onClick={this.onRemoveClick}> && (
<Delete /> <IconButton aria-label="Delete" onClick={this.onRemoveClick}>
</IconButton> <Delete />
</IconButton>
)
} }
</Typography> </Typography>
</CardContent> </CardContent>

View File

@ -5,7 +5,6 @@ import SafeView from '~/routes/safe/component/Safe'
import { aNewStore, type GlobalState } from '~/store' import { aNewStore, type GlobalState } from '~/store'
import { sleep } from '~/utils/timer' import { sleep } from '~/utils/timer'
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { promisify } from '~/utils/promisify'
import { addEtherTo } from '~/test/utils/tokenMovements' import { addEtherTo } from '~/test/utils/tokenMovements'
import { aMinedSafe } from '~/test/builder/safe.redux.builder' import { aMinedSafe } from '~/test/builder/safe.redux.builder'
import { travelToSafe } from '~/test/builder/safe.dom.utils' import { travelToSafe } from '~/test/builder/safe.dom.utils'
@ -31,7 +30,7 @@ export const renderSafeInDom = async (
// deploy safe updating store // deploy safe updating store
const address = await aMinedSafe(store, owners, threshold) const address = await aMinedSafe(store, owners, threshold)
// have available accounts // have available accounts
const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) const accounts = await getWeb3().eth.getAccounts()
// navigate to SAFE route // navigate to SAFE route
const SafeDom = travelToSafe(store, address) const SafeDom = travelToSafe(store, address)

View File

@ -6,7 +6,7 @@ import { SEE_MULTISIG_BUTTON_TEXT } from '~/routes/safe/component/Safe/MultisigT
import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions' import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions'
import { sleep } from '~/utils/timer' import { sleep } from '~/utils/timer'
import { Provider } from 'react-redux' import { Provider } from 'react-redux'
import { ConnectedRouter } from 'react-router-redux' import { ConnectedRouter } from 'connected-react-router'
import AppRoutes from '~/routes' import AppRoutes from '~/routes'
import { SAFELIST_ADDRESS, SETTINS_ADDRESS } from '~/routes/routes' import { SAFELIST_ADDRESS, SETTINS_ADDRESS } from '~/routes/routes'
import { history, type GlobalState } from '~/store' import { history, type GlobalState } from '~/store'

View File

@ -3,7 +3,6 @@ import { makeSafe, type Safe } from '~/routes/safe/store/model/safe'
import addSafe, { buildOwnersFrom } from '~/routes/safe/store/actions/addSafe' import addSafe, { buildOwnersFrom } from '~/routes/safe/store/actions/addSafe'
import { FIELD_NAME, FIELD_CONFIRMATIONS, FIELD_OWNERS, getOwnerNameBy, getOwnerAddressBy } from '~/routes/open/components/fields' import { FIELD_NAME, FIELD_CONFIRMATIONS, FIELD_OWNERS, getOwnerNameBy, getOwnerAddressBy } from '~/routes/open/components/fields'
import { getWeb3, getProviderInfo } from '~/logic/wallets/getWeb3' import { getWeb3, getProviderInfo } from '~/logic/wallets/getWeb3'
import { promisify } from '~/utils/promisify'
import { createSafe, type OpenState } from '~/routes/open/container/Open' import { createSafe, type OpenState } from '~/routes/open/container/Open'
import { type GlobalState } from '~/store/index' import { type GlobalState } from '~/store/index'
import { makeProvider } from '~/logic/wallets/store/model/provider' import { makeProvider } from '~/logic/wallets/store/model/provider'
@ -72,7 +71,7 @@ export const aMinedSafe = async (
const walletRecord = makeProvider(provider) const walletRecord = makeProvider(provider)
store.dispatch(addProvider(walletRecord)) store.dispatch(addProvider(walletRecord))
const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) const accounts = await getWeb3().eth.getAccounts()
const form = { const form = {
[FIELD_NAME]: 'Safe Name', [FIELD_NAME]: 'Safe Name',
[FIELD_CONFIRMATIONS]: `${threshold}`, [FIELD_CONFIRMATIONS]: `${threshold}`,

View File

@ -4,7 +4,7 @@ import { type Store } from 'redux'
import TestUtils from 'react-dom/test-utils' import TestUtils from 'react-dom/test-utils'
import Select from '@material-ui/core/Select' import Select from '@material-ui/core/Select'
import { Provider } from 'react-redux' import { Provider } from 'react-redux'
import { ConnectedRouter } from 'react-router-redux' import { ConnectedRouter } from 'connected-react-router'
import { ADD_OWNER_BUTTON } from '~/routes/open/components/SafeOwnersForm' import { ADD_OWNER_BUTTON } from '~/routes/open/components/SafeOwnersForm'
import Open from '~/routes/open/container/Open' import Open from '~/routes/open/container/Open'
import { aNewStore, history, type GlobalState } from '~/store' import { aNewStore, history, type GlobalState } from '~/store'
@ -12,7 +12,6 @@ import { sleep } from '~/utils/timer'
import { getProviderInfo, getWeb3 } from '~/logic/wallets/getWeb3' import { getProviderInfo, getWeb3 } from '~/logic/wallets/getWeb3'
import addProvider from '~/logic/wallets/store/actions/addProvider' import addProvider from '~/logic/wallets/store/actions/addProvider'
import { makeProvider } from '~/logic/wallets/store/model/provider' import { makeProvider } from '~/logic/wallets/store/model/provider'
import { promisify } from '~/utils/promisify'
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
import { whenSafeDeployed } from './builder/safe.dom.utils' import { whenSafeDeployed } from './builder/safe.dom.utils'
@ -34,7 +33,7 @@ const fillOpenSafeForm = async (localStore: Store<GlobalState>) => {
const deploySafe = async (safe: React$Component<{}>, threshold: number, numOwners: number) => { const deploySafe = async (safe: React$Component<{}>, threshold: number, numOwners: number) => {
const web3 = getWeb3() const web3 = getWeb3()
const accounts = await promisify(cb => web3.eth.getAccounts(cb)) const accounts = await web3.eth.getAccounts()
expect(threshold).toBeLessThanOrEqual(numOwners) expect(threshold).toBeLessThanOrEqual(numOwners)
const form = TestUtils.findRenderedDOMComponentWithTag(safe, 'form') const form = TestUtils.findRenderedDOMComponentWithTag(safe, 'form')

View File

@ -3,7 +3,7 @@ import * as React from 'react'
import { type Store } from 'redux' import { type Store } from 'redux'
import TestUtils from 'react-dom/test-utils' import TestUtils from 'react-dom/test-utils'
import { Provider } from 'react-redux' import { Provider } from 'react-redux'
import { ConnectedRouter } from 'react-router-redux' import { ConnectedRouter } from 'connected-react-router'
import Load from '~/routes/load/container/Load' import Load from '~/routes/load/container/Load'
import { aNewStore, history, type GlobalState } from '~/store' import { aNewStore, history, type GlobalState } from '~/store'
import { sleep } from '~/utils/timer' import { sleep } from '~/utils/timer'

View File

@ -6,7 +6,6 @@ import { aNewStore } from '~/store'
import { aMinedSafe } from '~/test/builder/safe.redux.builder' import { aMinedSafe } from '~/test/builder/safe.redux.builder'
import { addTknTo, getFirstTokenContract } from '~/test/utils/tokenMovements' import { addTknTo, getFirstTokenContract } from '~/test/utils/tokenMovements'
import { EXPAND_BALANCE_INDEX, travelToSafe } from '~/test/builder/safe.dom.utils' import { EXPAND_BALANCE_INDEX, travelToSafe } from '~/test/builder/safe.dom.utils'
import { promisify } from '~/utils/promisify'
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { sendMoveTokensForm, dispatchTknBalance } from '~/test/utils/transactions/moveTokens.helper' import { sendMoveTokensForm, dispatchTknBalance } from '~/test/utils/transactions/moveTokens.helper'
import { sleep } from '~/utils/timer' import { sleep } from '~/utils/timer'
@ -18,7 +17,7 @@ describe('DOM > Feature > SAFE ERC20 TOKENS', () => {
beforeEach(async () => { beforeEach(async () => {
store = aNewStore() store = aNewStore()
safeAddress = await aMinedSafe(store) safeAddress = await aMinedSafe(store)
accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) accounts = await getWeb3().eth.getAccounts()
}) })
it('sends ERC20 tokens', async () => { it('sends ERC20 tokens', async () => {

View File

@ -8,7 +8,6 @@ import { loadSafe } from '~/routes/load/container/Load'
import { safesMapSelector } from '~/routes/safeList/store/selectors' import { safesMapSelector } from '~/routes/safeList/store/selectors'
import { makeOwner, type Owner } from '~/routes/safe/store/model/owner' import { makeOwner, type Owner } from '~/routes/safe/store/model/owner'
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { promisify } from '~/utils/promisify'
import { safesInitialState } from '~/routes/safe/store/reducer/safe' import { safesInitialState } from '~/routes/safe/store/reducer/safe'
import { setOwners, OWNERS_KEY } from '~/utils/localStorage' import { setOwners, OWNERS_KEY } from '~/utils/localStorage'
@ -20,7 +19,7 @@ describe('Safe - redux load safe', () => {
store = aNewStore() store = aNewStore()
address = await aMinedSafe(store) address = await aMinedSafe(store)
localStorage.clear() localStorage.clear()
accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) accounts = await getWeb3().eth.getAccounts()
}) })
it('if safe is not present, store and persist it with default names', async () => { it('if safe is not present, store and persist it with default names', async () => {

View File

@ -2,7 +2,6 @@
import { List } from 'immutable' import { List } from 'immutable'
import { aNewStore } from '~/store' import { aNewStore } from '~/store'
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { promisify } from '~/utils/promisify'
import { confirmationsTransactionSelector, safeTransactionsSelector } from '~/routes/safe/store/selectors' import { confirmationsTransactionSelector, safeTransactionsSelector } from '~/routes/safe/store/selectors'
import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions' import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions'
import { type Safe } from '~/routes/safe/store/model/safe' import { type Safe } from '~/routes/safe/store/model/safe'
@ -103,7 +102,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
const threshold = 1 const threshold = 1
const store = aNewStore() const store = aNewStore()
const address = await aMinedSafe(store, numOwners, threshold) const address = await aMinedSafe(store, numOwners, threshold)
const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) const accounts = await getWeb3().eth.getAccounts()
const gnosisSafe = await getGnosisSafeInstanceAt(address) const gnosisSafe = await getGnosisSafeInstanceAt(address)
const values = { const values = {
@ -132,7 +131,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
const threshold = 1 const threshold = 1
const store = aNewStore() const store = aNewStore()
const address = await aMinedSafe(store, numOwners, threshold) const address = await aMinedSafe(store, numOwners, threshold)
const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) const accounts = await getWeb3().eth.getAccounts()
const gnosisSafe = await getGnosisSafeInstanceAt(address) const gnosisSafe = await getGnosisSafeInstanceAt(address)
const values = { const values = {
@ -164,7 +163,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
const threshold = 2 const threshold = 2
const store = aNewStore() const store = aNewStore()
const address = await aMinedSafe(store, numOwners, threshold) const address = await aMinedSafe(store, numOwners, threshold)
const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) const accounts = await getWeb3().eth.getAccounts()
const gnosisSafe = await getGnosisSafeInstanceAt(address) const gnosisSafe = await getGnosisSafeInstanceAt(address)
const decrease = shouldDecrease(numOwners, threshold) const decrease = shouldDecrease(numOwners, threshold)
@ -190,7 +189,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
const threshold = 2 const threshold = 2
const store = aNewStore() const store = aNewStore()
const address = await aMinedSafe(store, numOwners, threshold) const address = await aMinedSafe(store, numOwners, threshold)
const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) const accounts = await getWeb3().eth.getAccounts()
const gnosisSafe = await getGnosisSafeInstanceAt(address) const gnosisSafe = await getGnosisSafeInstanceAt(address)
const decrease = true const decrease = true
@ -215,7 +214,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
const threshold = 2 const threshold = 2
const store = aNewStore() const store = aNewStore()
const address = await aMinedSafe(store, numOwners, threshold) const address = await aMinedSafe(store, numOwners, threshold)
const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) const accounts = await getWeb3().eth.getAccounts()
const gnosisSafe = await getGnosisSafeInstanceAt(address) const gnosisSafe = await getGnosisSafeInstanceAt(address)
const decrease = shouldDecrease(numOwners, threshold) const decrease = shouldDecrease(numOwners, threshold)

View File

@ -8,7 +8,6 @@ import { makeConfirmation } from '~/routes/safe/store/model/confirmation'
import { aNewStore } from '~/store' import { aNewStore } from '~/store'
import { aMinedSafe } from '~/test/builder/safe.redux.builder' import { aMinedSafe } from '~/test/builder/safe.redux.builder'
import { getSafeFrom } from '~/test/utils/safeHelper' import { getSafeFrom } from '~/test/utils/safeHelper'
import { promisify } from '~/utils/promisify'
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { safeTransactionsSelector } from '~/routes/safe/store/selectors' import { safeTransactionsSelector } from '~/routes/safe/store/selectors'
import fetchSafe from '~/routes/safe/store/actions/fetchSafe' import fetchSafe from '~/routes/safe/store/actions/fetchSafe'
@ -20,7 +19,7 @@ describe('Transactions Suite', () => {
let safeAddress: string let safeAddress: string
let accounts: string[] let accounts: string[]
beforeAll(async () => { beforeAll(async () => {
accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) accounts = await getWeb3().eth.getAccounts()
}) })
beforeEach(async () => { beforeEach(async () => {
localStorage.clear() localStorage.clear()

View File

@ -2,7 +2,6 @@
import * as TestUtils from 'react-dom/test-utils' import * as TestUtils from 'react-dom/test-utils'
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { type Match } from 'react-router-dom' import { type Match } from 'react-router-dom'
import { promisify } from '~/utils/promisify'
import TokenComponent from '~/routes/tokens/component/Token' import TokenComponent from '~/routes/tokens/component/Token'
import { getFirstTokenContract, getSecondTokenContract } from '~/test/utils/tokenMovements' import { getFirstTokenContract, getSecondTokenContract } from '~/test/utils/tokenMovements'
import { aNewStore } from '~/store' import { aNewStore } from '~/store'
@ -24,7 +23,7 @@ describe('DOM > Feature > Add new ERC 20 Tokens', () => {
beforeAll(async () => { beforeAll(async () => {
web3 = getWeb3() web3 = getWeb3()
accounts = await promisify(cb => web3.eth.getAccounts(cb)) accounts = await web3.eth.getAccounts()
firstErc20Token = await getFirstTokenContract(web3, accounts[0]) firstErc20Token = await getFirstTokenContract(web3, accounts[0])
secondErc20Token = await getSecondTokenContract(web3, accounts[0]) secondErc20Token = await getSecondTokenContract(web3, accounts[0])

View File

@ -3,7 +3,6 @@ import * as TestUtils from 'react-dom/test-utils'
import { List } from 'immutable' import { List } from 'immutable'
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { type Match } from 'react-router-dom' import { type Match } from 'react-router-dom'
import { promisify } from '~/utils/promisify'
import TokenComponent from '~/routes/tokens/component/Token' import TokenComponent from '~/routes/tokens/component/Token'
import Checkbox from '@material-ui/core/Checkbox' import Checkbox from '@material-ui/core/Checkbox'
import { getFirstTokenContract, getSecondTokenContract, addTknTo } from '~/test/utils/tokenMovements' import { getFirstTokenContract, getSecondTokenContract, addTknTo } from '~/test/utils/tokenMovements'
@ -26,7 +25,7 @@ describe('DOM > Feature > Enable and disable default tokens', () => {
beforeAll(async () => { beforeAll(async () => {
web3 = getWeb3() web3 = getWeb3()
accounts = await promisify(cb => web3.eth.getAccounts(cb)) accounts = await web3.eth.getAccounts()
firstErc20Token = await getFirstTokenContract(web3, accounts[0]) firstErc20Token = await getFirstTokenContract(web3, accounts[0])
secondErc20Token = await getSecondTokenContract(web3, accounts[0]) secondErc20Token = await getSecondTokenContract(web3, accounts[0])
// $FlowFixMe // $FlowFixMe

View File

@ -1,7 +1,6 @@
// @flow // @flow
import * as TestUtils from 'react-dom/test-utils' import * as TestUtils from 'react-dom/test-utils'
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { promisify } from '~/utils/promisify'
import { getFirstTokenContract, getSecondTokenContract } from '~/test/utils/tokenMovements' import { getFirstTokenContract, getSecondTokenContract } from '~/test/utils/tokenMovements'
import { aNewStore } from '~/store' import { aNewStore } from '~/store'
import { aMinedSafe } from '~/test/builder/safe.redux.builder' import { aMinedSafe } from '~/test/builder/safe.redux.builder'
@ -24,7 +23,7 @@ describe('DOM > Feature > Add new ERC 20 Tokens', () => {
beforeAll(async () => { beforeAll(async () => {
web3 = getWeb3() web3 = getWeb3()
accounts = await promisify(cb => web3.eth.getAccounts(cb)) accounts = await web3.eth.getAccounts()
firstErc20Token = await getFirstTokenContract(web3, accounts[0]) firstErc20Token = await getFirstTokenContract(web3, accounts[0])
secondErc20Token = await getSecondTokenContract(web3, accounts[0]) secondErc20Token = await getSecondTokenContract(web3, accounts[0])

View File

@ -1,7 +1,6 @@
// @flow // @flow
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { type Match } from 'react-router-dom' import { type Match } from 'react-router-dom'
import { promisify } from '~/utils/promisify'
import { getFirstTokenContract, getSecondTokenContract } from '~/test/utils/tokenMovements' import { getFirstTokenContract, getSecondTokenContract } from '~/test/utils/tokenMovements'
import { aNewStore } from '~/store' import { aNewStore } from '~/store'
import { aMinedSafe } from '~/test/builder/safe.redux.builder' import { aMinedSafe } from '~/test/builder/safe.redux.builder'
@ -24,7 +23,7 @@ describe('DOM > Feature > Add new ERC 20 Tokens', () => {
beforeAll(async () => { beforeAll(async () => {
web3 = getWeb3() web3 = getWeb3()
accounts = await promisify(cb => web3.eth.getAccounts(cb)) accounts = await web3.eth.getAccounts()
firstErc20Token = await getFirstTokenContract(web3, accounts[0]) firstErc20Token = await getFirstTokenContract(web3, accounts[0])
secondErc20Token = await getSecondTokenContract(web3, accounts[0]) secondErc20Token = await getSecondTokenContract(web3, accounts[0])

View File

@ -1,7 +1,6 @@
// @flow // @flow
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { type Match } from 'react-router-dom' import { type Match } from 'react-router-dom'
import { promisify } from '~/utils/promisify'
import { getFirstTokenContract, getSecondTokenContract } from '~/test/utils/tokenMovements' import { getFirstTokenContract, getSecondTokenContract } from '~/test/utils/tokenMovements'
import { aNewStore } from '~/store' import { aNewStore } from '~/store'
import { aMinedSafe } from '~/test/builder/safe.redux.builder' import { aMinedSafe } from '~/test/builder/safe.redux.builder'
@ -11,7 +10,12 @@ import { testToken } from '~/test/builder/tokens.dom.utils'
import * as fetchTokensModule from '~/routes/tokens/store/actions/fetchTokens' import * as fetchTokensModule from '~/routes/tokens/store/actions/fetchTokens'
import * as enhancedFetchModule from '~/utils/fetch' import * as enhancedFetchModule from '~/utils/fetch'
import { TOKEN_ADRESS_PARAM } from '~/routes/tokens/component/AddToken/FirstPage' import { TOKEN_ADRESS_PARAM } from '~/routes/tokens/component/AddToken/FirstPage'
import { TOKEN_NAME_PARAM, TOKEN_DECIMALS_PARAM, TOKEN_SYMBOL_PARAM, TOKEN_LOGO_URL_PARAM } from '~/routes/tokens/component/AddToken/SecondPage' import {
TOKEN_NAME_PARAM,
TOKEN_DECIMALS_PARAM,
TOKEN_SYMBOL_PARAM,
TOKEN_LOGO_URL_PARAM,
} from '~/routes/tokens/component/AddToken/SecondPage'
import addToken from '~/routes/tokens/store/actions/addToken' import addToken from '~/routes/tokens/store/actions/addToken'
import { addTokenFnc } from '~/routes/tokens/component/AddToken' import { addTokenFnc } from '~/routes/tokens/component/AddToken'
import { activeTokensSelector, tokenListSelector } from '~/routes/tokens/store/selectors' import { activeTokensSelector, tokenListSelector } from '~/routes/tokens/store/selectors'
@ -27,7 +31,7 @@ describe('DOM > Feature > Add new ERC 20 Tokens', () => {
beforeAll(async () => { beforeAll(async () => {
web3 = getWeb3() web3 = getWeb3()
accounts = await promisify(cb => web3.eth.getAccounts(cb)) accounts = await web3.eth.getAccounts()
firstErc20Token = await getFirstTokenContract(web3, accounts[0]) firstErc20Token = await getFirstTokenContract(web3, accounts[0])
secondErc20Token = await getSecondTokenContract(web3, accounts[0]) secondErc20Token = await getSecondTokenContract(web3, accounts[0])

View File

@ -1,7 +1,6 @@
// @flow // @flow
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import abi from 'ethereumjs-abi' import abi from 'ethereumjs-abi'
import { promisify } from '~/utils/promisify'
/* /*
console.log(`to[${to}] \n\n valieInWei[${valueInWei}] \n\n console.log(`to[${to}] \n\n valieInWei[${valueInWei}] \n\n
@ -15,9 +14,12 @@ const err = await getErrorMessage(address, 0, txData, accounts[2])
*/ */
export const getErrorMessage = async (to: string, value: number, data: string, from: string) => { export const getErrorMessage = async (to: string, value: number, data: string, from: string) => {
const web3 = getWeb3() const web3 = getWeb3()
const returnData = await promisify(cb => web3.eth.call({ const returnData = await web3.eth.call({
to, from, value, data, to,
}, cb)) from,
value,
data,
})
const returnBuffer = Buffer.from(returnData.slice(2), 'hex') const returnBuffer = Buffer.from(returnData.slice(2), 'hex')
return abi.rawDecode(['string'], returnBuffer.slice(4))[0] return abi.rawDecode(['string'], returnBuffer.slice(4))[0]

View File

@ -1,16 +1,15 @@
// @flow // @flow
import contract from 'truffle-contract' import contract from 'truffle-contract'
import { getBalanceInEtherOf, getWeb3 } from '~/logic/wallets/getWeb3' import { getBalanceInEtherOf, getWeb3 } from '~/logic/wallets/getWeb3'
import { promisify } from '~/utils/promisify'
import Token from '#/test/TestToken.json' import Token from '#/test/TestToken.json'
import { ensureOnce } from '~/utils/singleton' import { ensureOnce } from '~/utils/singleton'
import { toNative } from '~/logic/wallets/tokens' import { toNative } from '~/logic/wallets/tokens'
export const addEtherTo = async (address: string, eth: string) => { export const addEtherTo = async (address: string, eth: string) => {
const web3 = getWeb3() const web3 = getWeb3()
const accounts = await promisify(cb => web3.eth.getAccounts(cb)) const accounts = await web3.eth.getAccounts()
const txData = { from: accounts[0], to: address, value: web3.toWei(eth, 'ether') } const txData = { from: accounts[0], to: address, value: web3.utils.toWei(eth, 'ether') }
return promisify(cb => web3.eth.sendTransaction(txData, cb)) return web3.eth.sendTransaction(txData)
} }
export const checkBalanceOf = async (addressToTest: string, value: string) => { export const checkBalanceOf = async (addressToTest: string, value: string) => {
@ -30,7 +29,7 @@ export const getSecondTokenContract = ensureOnce(createTokenContract)
export const addTknTo = async (safe: string, value: number, tokenContract?: any) => { export const addTknTo = async (safe: string, value: number, tokenContract?: any) => {
const web3 = getWeb3() const web3 = getWeb3()
const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) const accounts = await web3.eth.getAccounts()
const myToken = tokenContract || await getFirstTokenContract(web3, accounts[0]) const myToken = tokenContract || await getFirstTokenContract(web3, accounts[0])
const nativeValue = await toNative(value, 18) const nativeValue = await toNative(value, 18)