Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse transaction data correctly #3050

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions app/components/Nav/Main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import I18n, { strings } from '../../../../locales/i18n';
import { colors } from '../../../styles/common';
import LockManager from '../../../core/LockManager';
import FadeOutOverlay from '../../UI/FadeOutOverlay';
import { hexToBN, fromWei, renderFromTokenMinimalUnit } from '../../../util/number';
import { hexToBN, fromWei } from '../../../util/number';
import { setEtherTransaction, setTransactionObject } from '../../../actions/transaction';
import PersonalSign from '../../UI/PersonalSign';
import TypedSign from '../../UI/TypedSign';
Expand All @@ -33,9 +33,12 @@ import Device from '../../../util/device';
import {
getMethodData,
TOKEN_METHOD_TRANSFER,
decodeTransferData,
APPROVE_FUNCTION_SIGNATURE,
decodeApproveData,
getTokenValueParam,
getTokenAddressParam,
calcTokenAmount,
getTokenValueParamAsHex,
} from '../../../util/transactions';
import { BN } from 'ethereumjs-util';
import Logger from '../../../util/Logger';
Expand Down Expand Up @@ -66,6 +69,10 @@ import { ANALYTICS_EVENT_OPTS } from '../../../util/analytics';
import BigNumber from 'bignumber.js';
import { setInfuraAvailabilityBlocked, setInfuraAvailabilityNotBlocked } from '../../../actions/infuraAvailability';
import { toLowerCaseEquals } from '../../../util/general';
import { ethers } from 'ethers';
import abi from 'human-standard-token-abi';

const hstInterface = new ethers.utils.Interface(abi);

const styles = StyleSheet.create({
flex: {
Expand Down Expand Up @@ -362,13 +369,14 @@ const Main = (props) => {
}
}

const decodedData = decodeTransferData('transfer', data);
transactionMeta.transaction.value = hexToBN(decodedData[2]);
transactionMeta.transaction.readableValue = renderFromTokenMinimalUnit(
hexToBN(decodedData[2]),
asset.decimals
);
transactionMeta.transaction.to = decodedData[0];
const tokenData = hstInterface.parseTransaction({ data });
const tokenValue = getTokenValueParam(tokenData);
const toAddress = getTokenAddressParam(tokenData);
const tokenAmount = tokenData && calcTokenAmount(tokenValue, asset.decimals).toFixed();

transactionMeta.transaction.value = hexToBN(getTokenValueParamAsHex(tokenData));
transactionMeta.transaction.readableValue = tokenAmount;
transactionMeta.transaction.to = toAddress;

setTransactionObject({
type: 'INDIVIDUAL_TOKEN_TRANSACTION',
Expand Down
16 changes: 8 additions & 8 deletions app/components/UI/AccountApproval/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ const initialState = {
engine: {
backgroundState: {
AccountTrackerController: {
accounts: { '0x2': { balance: '0' } }
accounts: { '0x2': { balance: '0' } },
},
NetworkController: {
provider: {
type: ROPSTEN
}
type: ROPSTEN,
},
},
TokensController: {
tokens: []
tokens: [],
},
PreferencesController: {
selectedAddress: '0xe7E125654064EEa56229f273dA586F10DF96B0a1',
identities: { '0xe7E125654064EEa56229f273dA586F10DF96B0a1': { name: 'Account 1' } }
}
}
}
identities: { '0xe7E125654064EEa56229f273dA586F10DF96B0a1': { name: 'Account 1' } },
},
},
},
};
const store = mockStore(initialState);

Expand Down
22 changes: 11 additions & 11 deletions app/components/UI/AccountInfoCard/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ const initialState = {
AccountTrackerController: {
accounts: {
'0x0': {
balance: 200
}
}
balance: 200,
},
},
},
PreferencesController: {
selectedAddress: '0x0',
identities: {
address: '0x0',
name: 'Account 1'
}
name: 'Account 1',
},
},
CurrencyRateController: {
conversionRate: 10,
currentCurrency: 'inr'
currentCurrency: 'inr',
},
NetworkController: {
provider: {
ticker: 'eth'
}
}
}
}
ticker: 'eth',
},
},
},
},
};
const store = mockStore(initialState);

Expand Down
10 changes: 5 additions & 5 deletions app/components/UI/AccountList/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ const store = mockStore({
backgroundState: {
AccountTrackerController: {
accounts: {
[address]: { name: 'account 1', address, balance: 0 }
}
}
}
}
[address]: { name: 'account 1', address, balance: 0 },
},
},
},
},
});

describe('Accounts', () => {
Expand Down
8 changes: 4 additions & 4 deletions app/components/UI/AccountRightButton/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ const store = mockStore({
engine: {
backgroundState: {
PreferencesController: {
selectedAddress: '0xe7E125654064EEa56229f273dA586F10DF96B0a1'
}
}
}
selectedAddress: '0xe7E125654064EEa56229f273dA586F10DF96B0a1',
},
},
},
});

describe('AccountRightButton', () => {
Expand Down
20 changes: 10 additions & 10 deletions app/components/UI/ApproveTransactionReview/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ const initialState = {
engine: {
backgroundState: {
AccountTrackerController: {
accounts: { '0x2': { balance: '0' } }
accounts: { '0x2': { balance: '0' } },
},
CurrencyRateController: {
conversionRate: 5
conversionRate: 5,
},
NetworkController: {
provider: {
ticker: 'ETH',
type: 'ETH'
}
type: 'ETH',
},
},
TokensController: {
tokens: []
}
}
tokens: [],
},
},
},
transaction: {},
settings: {
primaryCurrency: 'fiat'
primaryCurrency: 'fiat',
},
browser: {
activeTab: 1605778647042,
tabs: [{ id: 1605778647042, url: 'https://metamask.github.io/test-dapp/' }]
}
tabs: [{ id: 1605778647042, url: 'https://metamask.github.io/test-dapp/' }],
},
};
const store = mockStore(initialState);

Expand Down
10 changes: 5 additions & 5 deletions app/components/UI/CollectibleContractOverview/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ const initialState = {
engine: {
backgroundState: {
CollectiblesController: {
collectibles: []
}
}
}
collectibles: [],
},
},
},
};
const store = mockStore(initialState);

Expand All @@ -26,7 +26,7 @@ describe('CollectibleContractOverview', () => {
symbol: 'symbol',
description: 'description',
address: '0x123',
totalSupply: 1
totalSupply: 1,
}}
/>
</Provider>
Expand Down
24 changes: 12 additions & 12 deletions app/components/UI/CollectibleContracts/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import { Provider } from 'react-redux';
const mockStore = configureMockStore();
const initialState = {
collectibles: {
favorites: {}
favorites: {},
},
engine: {
backgroundState: {
NetworkController: {
provider: {
chainId: 1
}
chainId: 1,
},
},
PreferencesController: {
selectedAddress: '0x1'
selectedAddress: '0x1',
},
CollectiblesController: {
collectibleContracts: [
Expand All @@ -27,20 +27,20 @@ const initialState = {
address: '0x0',
symbol: 'NM',
description: 'description',
totalSupply: 10
}
totalSupply: 10,
},
],
collectibles: [
{
address: '0x0',
tokenId: 10,
name: 'name',
image: 'image'
}
]
}
}
}
image: 'image',
},
],
},
},
},
};
const store = mockStore(initialState);

Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/CollectibleModal/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe('CollectibleModal', () => {
route={{
params: {
contractName: 'Opensea',
collectible: { name: 'Leopard', tokenId: 6904, address: '0x123' }
}
collectible: { name: 'Leopard', tokenId: 6904, address: '0x123' },
},
}}
/>
</Provider>
Expand Down
16 changes: 8 additions & 8 deletions app/components/UI/CollectibleOverview/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import { Provider } from 'react-redux';
const mockStore = configureMockStore();
const initialState = {
collectibles: {
favorites: {}
favorites: {},
},
engine: {
backgroundState: {
NetworkController: {
provider: {
chainId: 1
}
chainId: 1,
},
},
PreferencesController: {
selectedAddress: '0x1'
}
}
}
selectedAddress: '0x1',
},
},
},
};
const store = mockStore(initialState);

Expand All @@ -34,7 +34,7 @@ describe('CollectibleOverview', () => {
tokenId: 6904,
address: '0x06012c8cf97BEaD5deAe237070F9587f8E7A266d',
externalLink: 'https://nft.example.com',
tradable: true
tradable: true,
}}
/>
</Provider>
Expand Down
10 changes: 5 additions & 5 deletions app/components/UI/NetworkList/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import { Provider } from 'react-redux';
const mockStore = configureMockStore();
const initialState = {
privacy: {
approvedHosts: {}
approvedHosts: {},
},
engine: {
backgroundState: {
NetworkController: {
provider: { type: 'mainnet', rpcTarget: 'http://10.0.2.2:8545' }
provider: { type: 'mainnet', rpcTarget: 'http://10.0.2.2:8545' },
},
PreferencesController: { frequentRpcList: ['http://10.0.2.2:8545'] }
}
}
PreferencesController: { frequentRpcList: ['http://10.0.2.2:8545'] },
},
},
};
const store = mockStore(initialState);

Expand Down
16 changes: 8 additions & 8 deletions app/components/UI/OnboardingWizard/Step3/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ const initialState = {
backgroundState: {
PreferencesController: {
selectedAddress: '0xe7E125654064EEa56229f273dA586F10DF96B0a1',
identities: { '0xe7E125654064EEa56229f273dA586F10DF96B0a1': { name: 'Account 1' } }
identities: { '0xe7E125654064EEa56229f273dA586F10DF96B0a1': { name: 'Account 1' } },
},
AccountTrackerController: {
accounts: {
'0xe7E125654064EEa56229f273dA586F10DF96B0a1': {
name: 'account 1',
address: '0xe7E125654064EEa56229f273dA586F10DF96B0a1',
balance: 0
}
}
balance: 0,
},
},
},
CurrencyRateController: {
currentCurrecy: 'USD'
}
}
}
currentCurrecy: 'USD',
},
},
},
};
const store = mockStore(initialState);

Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/OptinMetrics/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { Provider } from 'react-redux';
const mockStore = configureMockStore();
const initialState = {
onboarding: {
event: 'event'
}
event: 'event',
},
};
const store = mockStore(initialState);

Expand Down
Loading