Skip to content

Commit

Permalink
Fix approval tx receipts (#3971)
Browse files Browse the repository at this point in the history
* Fix some issues with receipts

* Fix tests

* Fix whitespace
  • Loading branch information
FrederikBolding authored May 21, 2021
1 parent 9fba72e commit d03e5e1
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 34 deletions.
12 changes: 3 additions & 9 deletions jest_config/__fixtures__/approveErc20TxResponse.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
{
"nonce": 1,
"gasPrice": {
"_hex": "0x4a817c800"
},
"gasLimit": {
"_hex": "0x0249f0"
},
"gasPrice": "0x4a817c80",
"gasLimit": "0x0249f0",
"to": "0xfE5443FaC29fA621cFc33D41D1927fd0f5E0bB7c",
"value": {
"_hex": "0x0"
},
"value": "0x00",
"data": "0x095ea7b3000000000000000000000000221657776846890989a759ba2973e427dff5c9bb0000000000000000000000000000000000000000000000003782dace9d900000",
"chainId": 1,
"v": 41,
Expand Down
12 changes: 3 additions & 9 deletions jest_config/__fixtures__/repMigrationTxResponse.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
{
"nonce": 2,
"gasPrice": {
"_hex": "0x4a817c800"
},
"gasLimit": {
"_hex": "0x07a120"
},
"gasPrice": "0x4a817c800",
"gasLimit": "0x07a120",
"to": "0x221657776846890989a759BA2973e427DfF5C9bB",
"value": {
"_hex": "0x0"
},
"value": "0x00",
"data": "0x75d9aa1a",
"chainId": 1,
"v": 41,
Expand Down
22 changes: 22 additions & 0 deletions jest_config/__fixtures__/txParcels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@ export default ([
_uuid: '908acd15-f870-5652-9104-6a97b0cb98dd',
status: 'CONFIRMED',
txHash: '0x15f1a20e5ad8fdf50abaffaa09114d90e011406c8c888140da9595685d9de5e6',
txResponse: {
hash: '0x15f1a20e5ad8fdf50abaffaa09114d90e011406c8c888140da9595685d9de5e6',
type: 0,
accessList: null,
blockHash: '0x954aea9cd92c9d167a033bc94af2c95192e8a80b81c9856f529db45fd3264c00',
blockNumber: 9717420,
transactionIndex: 53,
confirmations: 2759837,
from: '0xfEAC75A09662396283f4bB50F0a9249576A81866',
gasPrice: '0x01dcd65000',
gasLimit: '0x0a2e36',
to: '0x3d7b19C37d422B43c07C7Ba6353ED2D1689540FD',
value: '0x038d7ea4c68000',
nonce: 139,
data:
'0x5d46ec34000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000d8775f648430679a709e98d2b0cb6250d2887ef00000000000000000000000000000000000000000000000000038d7ea4c680000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c0000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000003800000000000000000000000000000000000000000000000000d5704e2379762bd00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000bd19f30adde367fe06c0076d690d434bf945a8fc000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000124f0843ba9000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000038d7ea4c6800000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000005000000000000000000000000c0829421c1d260bd3cb3e0f06cfe2d52db2ce315000000000000000000000000b1cd6e4153b2a390cf00a6556b0fc1458c4a55330000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c000000000000000000000000131da075a2832549128e93acc2b54174045232cf0000000000000000000000000d8775f648430679a709e98d2b0cb6250d2887ef00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000124000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000038d7ea4c68000',
r: '0x3000efc622faf7d1ca11a954f6e37f80186c129a8ea16e33f58667930d5a381d',
s: '0x4e931f0efe6d400b56bff23fabac6616fc80f0bf85bb6edf7e3e0a688c46e197',
v: 37,
creates: null,
chainId: 1
},
txReceipt: {
to: '0x3d7b19C37d422B43c07C7Ba6353ED2D1689540FD',
from: '0xfEAC75A09662396283f4bB50F0a9249576A81866',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react';

import { MultiTxReceipt } from '@components/TransactionFlow';
import { getFiat } from '@config/fiats';
import { makeTxItem } from '@helpers';
import { makeTxConfigFromTxResponse, makeTxItem } from '@helpers';
import { useAssets, useRates, useSettings } from '@services';
import { ITokenMigrationConfig, StoreAccount, TxParcel } from '@types';
import { ITokenMigrationConfig, ITxType, StoreAccount, TxParcel } from '@types';

import { makeTokenMigrationTxConfig } from '../helpers';

Expand All @@ -24,11 +24,14 @@ export default function TokenMigrationReceipt({
onComplete
}: TokenMigrationReceiptProps) {
const { settings } = useSettings();
const { getAssetByUUID } = useAssets();
const { getAssetByUUID, assets } = useAssets();
const { getAssetRate } = useRates();
const txItems = transactions.map((tx, idx) => {
const txConfig = makeTokenMigrationTxConfig(tx.txRaw, account, amount)(flowConfig);
const txType = flowConfig.txConstructionConfigs[idx].txType;
const txConfig =
txType === ITxType.APPROVAL
? makeTxConfigFromTxResponse(tx.txResponse!, assets, account.network, [account])
: makeTokenMigrationTxConfig(tx.txRaw, account, amount)(flowConfig);
return makeTxItem(txType, txConfig, tx.txHash!, tx.txReceipt);
});

Expand Down
2 changes: 1 addition & 1 deletion src/features/SendAssets/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const parseTransactionQueryParams = (queryParams: any) => (

// This is labeled as "guess" because we can only identify simple erc20 transfers for now. If this is incorrect, It only affects displayed amounts - not the actual tx.
const ercType = guessERC20Type(i.data);
const isERC20 = ercType !== ERCType.NONE;
const isERC20 = ercType === ERCType.TRANSFER;

const { to, amount, receiverAddress } = deriveTxRecipientsAndAmount(
ercType,
Expand Down
19 changes: 11 additions & 8 deletions src/features/SwapAssets/components/SwapTransactionReceipt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import pick from 'ramda/src/pick';
import { MultiTxReceipt, TxReceipt } from '@components/TransactionFlow';
import { SwapFromToDiagram } from '@components/TransactionFlow/displays';
import { getFiat } from '@config/fiats';
import { makeTxItem } from '@helpers';
import { makeTxConfigFromTxResponse, makeTxItem } from '@helpers';
import { StoreContext, useAssets, useRates, useSettings } from '@services';
import { translateRaw } from '@translations';
import { ITxType, StoreAccount, TxParcel } from '@types';
Expand All @@ -28,7 +28,7 @@ export default function SwapTransactionReceipt({
onSuccess
}: Props) {
const { assets: getAssets } = useContext(StoreContext);
const { getAssetByUUID } = useAssets();
const { getAssetByUUID, assets } = useAssets();
const { settings } = useSettings();
const { getAssetRate } = useRates();
const swapDisplay: SwapDisplayData = pick(
Expand All @@ -38,13 +38,16 @@ export default function SwapTransactionReceipt({
const currentAssets = getAssets();
// @todo: refactor this to be based on status of tx from StoreProvider
const txItems = transactions.map((tx, idx) => {
const txConfig = makeSwapTxConfig(currentAssets)(
tx.txRaw,
account,
assetPair.fromAsset,
assetPair.fromAmount.toString()
);
const txType = idx === transactions.length - 1 ? ITxType.SWAP : ITxType.APPROVAL;
const txConfig =
txType === ITxType.SWAP
? makeSwapTxConfig(currentAssets)(
tx.txRaw,
account,
assetPair.fromAsset,
assetPair.fromAmount.toString()
)
: makeTxConfigFromTxResponse(tx.txResponse!, assets, account.network, [account]);
return makeTxItem(txType, txConfig, tx.txHash!, tx.txReceipt);
});

Expand Down
4 changes: 2 additions & 2 deletions src/helpers/transaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ describe('deriveTxFields', () => {
expect(result).toStrictEqual({
to: toAddress,
receiverAddress: toAddress,
amount: '0',
asset: fRopDAI
amount: '0.0',
asset: fAssets[1]
});
});
it("interprets an eth tx's fields correctly", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export const deriveTxFields = (
baseAsset: Asset,
contractAsset?: Asset
) => {
const isERC20 = ercType !== ERCType.NONE;
const isERC20 = ercType === ERCType.TRANSFER;
const { to, amount: rawAmount, receiverAddress } = deriveTxRecipientsAndAmount(
ercType,
data,
Expand Down

0 comments on commit d03e5e1

Please sign in to comment.