Skip to content

Commit

Permalink
Remove get preimage helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Oct 11, 2024
1 parent 781d415 commit 93a9aa5
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 61 deletions.
33 changes: 0 additions & 33 deletions src/app/utils/__tests__/getEthAccountAddress.test.ts

This file was deleted.

21 changes: 0 additions & 21 deletions src/app/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,6 @@ export function getEthAccountAddressFromBase64(base64Address: string): string {
return toChecksumAddress(base64ToHex(base64Address))
}

export function getEthAccountAddressFromPreimage(preimage: AddressPreimage | undefined): string | undefined {
if (preimage?.context !== 'oasis-runtime-sdk/address: secp256k1eth' || !preimage.address_data) {
// We can only determine the ETH address if there was a preimage,
// and the generation context was secp256k1eth
return undefined
}
// We need to convert from base64 to hex, add the prefix, and convert to checksum address
return getEthAccountAddressFromBase64(preimage.address_data)
}

export function getEthAddressForAccount(
account: RuntimeAccount,
possibleEthAddress?: string,
): string | undefined {
// In case of an empty account
if (account.stats.num_txns <= 0 && possibleEthAddress && isValidEthAddress(possibleEthAddress))
return possibleEthAddress

return getEthAccountAddressFromPreimage(account.address_preimage)
}

export function uniq<T>(input: T[] | undefined): T[] {
return input === undefined ? [] : [...new Set(input)]
}
Expand Down
9 changes: 2 additions & 7 deletions src/oasis-nexus/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ import {
RuntimeAccount,
RuntimeEventType,
} from './generated/api'
import {
getAccountSize,
getEthAddressForAccount,
getOasisAddressOrNull,
isValidEthAddress,
} from '../app/utils/helpers'
import { getAccountSize, getOasisAddressOrNull, isValidEthAddress } from '../app/utils/helpers'
import { getCancelTitle, getParameterChangeTitle, getProposalTitle } from '../app/utils/proposals'
import { Network } from '../types/network'
import { SearchScope } from '../types/searchScope'
Expand Down Expand Up @@ -438,7 +433,7 @@ export const useGetRuntimeAccountsAddress: typeof generated.useGetRuntimeAccount
if (status !== 200) return data
return groupAccountTokenBalances({
...data,
address_eth: isValidEthAddress(address) ? address : getEthAddressForAccount(data, address),
address_eth: isValidEthAddress(address) ? address : undefined,
evm_contract: data.evm_contract && {
...data.evm_contract,
eth_creation_tx: data.evm_contract.eth_creation_tx
Expand Down

0 comments on commit 93a9aa5

Please sign in to comment.