Skip to content

Fallback to FullTokenList in TransactionParser #11351

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

Merged
merged 1 commit into from
Dec 1, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -502,4 +502,85 @@ describe('useTransactionParser hook', () => {
})
})
})
describe('check for token symbol', () => {
describe.each([
['ERC20Approve', TransactionType.ERC20Approve],
['ERC20Transfer', TransactionType.ERC20Transfer],
['ERC721TransferFrom', TransactionType.ERC721TransferFrom],
['ERC721SafeTransferFrom', TransactionType.ERC721SafeTransferFrom]
])('%s', (_, txType) => {
it('should be empty', () => {
const { result: { current: transactionParser } } = renderHook(() => useTransactionParser(
mockNetwork, [mockAccount], [], [mockERC20Token]
))

const mockTransactionInfo = getMockedTransactionInfo()
const parsedTransaction = transactionParser({
...mockTransactionInfo,
txType,
txData: {
...mockTransactionInfo.txData,
baseData: {
...mockTransactionInfo.txData.baseData,
to: 'test'
}
},
txArgs: [
'mockRecipient',
'0xde0b6b3a7640000'
]
})

expect(parsedTransaction.symbol).toEqual('')
})
it('Gets token symbol from visibleList, should be DOG', () => {
const { result: { current: transactionParser } } = renderHook(() => useTransactionParser(
mockNetwork, [mockAccount], [], [mockERC20Token]
))

const mockTransactionInfo = getMockedTransactionInfo()
const parsedTransaction = transactionParser({
...mockTransactionInfo,
txType,
txData: {
...mockTransactionInfo.txData,
baseData: {
...mockTransactionInfo.txData.baseData,
to: 'mockContractAddress'
}
},
txArgs: [
'mockRecipient',
'0xde0b6b3a7640000'
]
})

expect(parsedTransaction.symbol).toEqual('DOG')
})
it('Gets token symbol from fallback fullTokenList, should be DOG', () => {
const { result: { current: transactionParser } } = renderHook(() => useTransactionParser(
mockNetwork, [mockAccount], [], [], [mockERC20Token]
))

const mockTransactionInfo = getMockedTransactionInfo()
const parsedTransaction = transactionParser({
...mockTransactionInfo,
txType,
txData: {
...mockTransactionInfo.txData,
baseData: {
...mockTransactionInfo.txData.baseData,
to: 'mockContractAddress'
}
},
txArgs: [
'mockRecipient',
'0xde0b6b3a7640000'
]
})

expect(parsedTransaction.symbol).toEqual('DOG')
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ export function useTransactionParser (
const parseTransactionFees = useTransactionFeesParser(selectedNetwork, findSpotPrice(selectedNetwork.symbol))

const findToken = React.useCallback((contractAddress: string) => {
return visibleTokens.find((token) => token.contractAddress.toLowerCase() === contractAddress.toLowerCase())
}, [visibleTokens])
const checkVisibleList = visibleTokens.find((token) => token.contractAddress.toLowerCase() === contractAddress.toLowerCase())
return checkVisibleList ?? (fullTokenList?.find((token) => token.contractAddress.toLowerCase() === contractAddress.toLowerCase()))
}, [visibleTokens, fullTokenList])

/**
* Checks if a given address is a known contract address from our token
Expand Down