diff --git a/src/app/utils/__tests__/getEthAccountAddress.test.ts b/src/app/utils/__tests__/getEthAccountAddress.test.ts deleted file mode 100644 index 6bd36401aa..0000000000 --- a/src/app/utils/__tests__/getEthAccountAddress.test.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { getEthAccountAddressFromPreimage, getEthAddressForAccount } from '../helpers' -import { suggestedEmptyAccount, suggestedParsedAccount } from '../test-fixtures' - -describe('getEthAccountAddress', () => { - // TODO: enable when jest fixes "TypeError: Expected Uint8Array" - // https://github.com/facebook/jest/issues/4422 - it.skip('should convert preimage to evm addresses', () => { - expect(getEthAccountAddressFromPreimage(suggestedParsedAccount.address_preimage)).toEqual( - suggestedParsedAccount.address_eth, - ) - }) - - it('should return input address on empty account', () => { - const validEthAddress = suggestedParsedAccount.address_eth - expect(getEthAddressForAccount(suggestedEmptyAccount, validEthAddress)).toBe( - '0xBA504818FdD8D3dBA2Ef8fD9B4F4D5c71aD1d1D3', - ) - }) - - it('should return undefined on empty account with invalid ETH address', () => { - expect(getEthAddressForAccount(suggestedEmptyAccount, '0x0')).toBeUndefined() - }) - - it('should return undefined on empty account with undefined supplied as ETH address', () => { - expect(getEthAddressForAccount(suggestedEmptyAccount, undefined)).toBeUndefined() - }) - - it('should valid address from preimage', () => { - expect(getEthAddressForAccount(suggestedParsedAccount, undefined)).toBe( - suggestedParsedAccount.address_eth, - ) - }) -}) diff --git a/src/app/utils/__tests__/getEthAccountAddressFromPreimage.test.ts b/src/app/utils/__tests__/getEthAccountAddressFromPreimage.test.ts new file mode 100644 index 0000000000..d7da68f2e5 --- /dev/null +++ b/src/app/utils/__tests__/getEthAccountAddressFromPreimage.test.ts @@ -0,0 +1,14 @@ +import { getEthAccountAddressFromPreimage } from '../helpers' +import { suggestedEmptyAccount, suggestedParsedAccount } from '../test-fixtures' + +describe('getEthAccountAddressFromPreimage', () => { + it('should convert preimage to evm addresses', () => { + expect(getEthAccountAddressFromPreimage(suggestedParsedAccount.address_preimage)).toEqual( + suggestedParsedAccount.address_eth, + ) + }) + + it('should return undefined on empty account', () => { + expect(getEthAccountAddressFromPreimage(suggestedEmptyAccount.address_preimage)).toBeUndefined() + }) +}) diff --git a/src/app/utils/helpers.ts b/src/app/utils/helpers.ts index 663df76835..c68ef31b9c 100644 --- a/src/app/utils/helpers.ts +++ b/src/app/utils/helpers.ts @@ -3,7 +3,7 @@ import { Buffer } from 'buffer' import * as oasis from '@oasisprotocol/client' import * as oasisRT from '@oasisprotocol/client-rt' // eslint-disable-next-line no-restricted-imports -import { AddressPreimage, RuntimeAccount } from '../../oasis-nexus/generated/api' +import { AddressPreimage } from '../../oasis-nexus/generated/api' import { validateMnemonic } from 'bip39' import { sha512_256 } from 'js-sha512' @@ -94,16 +94,6 @@ export function getEthAccountAddressFromPreimage(preimage: AddressPreimage | und return getEthAccountAddressFromBase64(preimage.address_data) } -export function getEthAddressForAccount( - account: RuntimeAccount, - possibleEthAddress?: string, -): string | undefined { - // In case of an empty account - if (possibleEthAddress && isValidEthAddress(possibleEthAddress)) return possibleEthAddress - - return getEthAccountAddressFromPreimage(account.address_preimage) -} - export function uniq(input: T[] | undefined): T[] { return input === undefined ? [] : [...new Set(input)] } diff --git a/src/oasis-nexus/api.ts b/src/oasis-nexus/api.ts index a67d1eba7a..c6d0746aa0 100644 --- a/src/oasis-nexus/api.ts +++ b/src/oasis-nexus/api.ts @@ -18,7 +18,7 @@ import { } from './generated/api' import { getAccountSize, - getEthAddressForAccount, + getEthAccountAddressFromPreimage, getOasisAddressOrNull, isValidEthAddress, } from '../app/utils/helpers' @@ -448,7 +448,9 @@ export const useGetRuntimeAccountsAddress: typeof generated.useGetRuntimeAccount if (status !== 200) return data return groupAccountTokenBalances({ ...data, - address_eth: getEthAddressForAccount(data, address), + address_eth: + getEthAccountAddressFromPreimage(data.address_preimage) || + fallbackEthAddress(data.address, address), evm_contract: data.evm_contract && { ...data.evm_contract, eth_creation_tx: data.evm_contract.eth_creation_tx