Skip to content

Commit

Permalink
feat: network selection during hardware import (#18152)
Browse files Browse the repository at this point in the history
  • Loading branch information
josheleonard authored Apr 20, 2023
1 parent c6ca951 commit bf8db7d
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 181 deletions.
58 changes: 4 additions & 54 deletions components/brave_wallet_ui/common/slices/api.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ import { getTokenParam } from '../../utils/api-utils'
import { getAccountType, getAddressLabelFromRegistry } from '../../utils/account-utils'
import {
getCoinFromTxDataUnion,
getFilecoinKeyringIdFromNetwork,
hasEIP1559Support
} from '../../utils/network-utils'
import Amount from '../../utils/amount'
Expand Down Expand Up @@ -150,7 +149,7 @@ export const setApiProxyFetcher = (fetcher: () => WalletApiProxy) => {
const emptyBalance = '0x0'

type GetAccountTokenCurrentBalanceArg = {
account: Pick<AccountInfoEntity, 'address' | 'coin' | 'keyringId'>
account: Pick<AccountInfoEntity, 'address' | 'coin'>
token: GetBlockchainTokenIdArg & Pick<BraveWallet.BlockchainToken, 'isNft'>
}

Expand Down Expand Up @@ -719,37 +718,6 @@ export function createWalletApi (
},
providesTags: [{ type: 'Network', id: NETWORK_TAG_IDS.SWAP_SUPPORTED }]
}),
getDefaultNetworks: query<BraveWallet.NetworkInfo[], void>({
// We can probably remove this when all
// Transactions and Sign-Message Requests include a chainId
queryFn: async (arg, api, extraOptions, baseQuery) => {
try {
const { braveWalletService, jsonRpcService }
= baseQuery(undefined).data // apiProxy
const { originInfo } = await braveWalletService.getActiveOrigin()

const defaultChains = await Promise.all(
SupportedCoinTypes.map(async (coinType) => {
const { network }
= await jsonRpcService.getNetwork(coinType, originInfo.origin)
return network
})
)

return {
data: defaultChains
}
} catch (error) {
console.error(error)
return {
error: `Error occurred within "getDefaultNetworks": ${
error.toString() //
}`
}
}
},
providesTags: [{ type: 'Network', id: NETWORK_TAG_IDS.DEFAULTS }]
}),
getSelectedChain: query<BraveWallet.NetworkInfo, void>({
queryFn: async (arg, api, extraOptions, baseQuery) => {
try {
Expand Down Expand Up @@ -1317,18 +1285,6 @@ export function createWalletApi (
case BraveWallet.CoinType.FIL:
case BraveWallet.CoinType.ETH:
default: {
if (BraveWallet.CoinType.FIL) {
// Get network keyring id
const filecoinKeyringIdFromNetwork =
getFilecoinKeyringIdFromNetwork({
chainId: token.chainId,
coin: account.coin
})

if (account.keyringId !== filecoinKeyringIdFromNetwork) {
return { data: emptyBalanceResult }
}
}

const { balance, error, errorMessage } =
await jsonRpcService.getBalance(
Expand Down Expand Up @@ -1441,7 +1397,6 @@ export function createWalletApi (
account: {
address: account.address,
coin: account.coin,
keyringId: account.keyringId
},
token: {
chainId: asset.chainId,
Expand Down Expand Up @@ -2981,7 +2936,6 @@ export const {
useGetCombinedTokenBalanceForAllAccountsQuery,
useGetDefaultAccountAddressesQuery,
useGetDefaultFiatCurrencyQuery,
useGetDefaultNetworksQuery,
useGetERC721MetadataQuery,
useGetGasEstimation1559Query,
useGetNetworksRegistryQuery,
Expand All @@ -3005,7 +2959,6 @@ export const {
useLazyGetCombinedTokenBalanceForAllAccountsQuery,
useLazyGetDefaultAccountAddressesQuery,
useLazyGetDefaultFiatCurrencyQuery,
useLazyGetDefaultNetworksQuery,
useLazyGetERC721MetadataQuery,
useLazyGetGasEstimation1559Query,
useLazyGetNetworksRegistryQuery,
Expand Down Expand Up @@ -3402,8 +3355,7 @@ export const parseTransactionWithoutPricesAsync = async ({
{
account: {
address: account.address,
coin: account.coin,
keyringId: account.keyringId
coin: account.coin
},
token: {
chainId: nativeAsset.chainId,
Expand All @@ -3425,8 +3377,7 @@ export const parseTransactionWithoutPricesAsync = async ({
{
account: {
address: account.address,
coin: account.coin,
keyringId: account.keyringId
coin: account.coin
},
token: {
chainId: token.chainId,
Expand All @@ -3448,8 +3399,7 @@ export const parseTransactionWithoutPricesAsync = async ({
{
account: {
address: account.address,
coin: account.coin,
keyringId: account.keyringId
coin: account.coin
},
token: {
chainId: sellToken.chainId,
Expand Down
Loading

0 comments on commit bf8db7d

Please sign in to comment.