From b61f228033e60a21a4cc2cad734a1d4bd78e8541 Mon Sep 17 00:00:00 2001 From: vvvvvv1vvvvvv <86296331+vvvvvv1vvvvvv@users.noreply.github.com> Date: Wed, 13 Nov 2024 16:26:15 +0800 Subject: [PATCH] feat: + is_core for total_balance (#2621) --- package.json | 2 +- src/background/controller/wallet.ts | 13 ++++++++++++- src/constant/index.ts | 6 ++++++ yarn.lock | 8 ++++---- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index b53b0897a0b..386ac085320 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "@rabby-wallet/gnosis-sdk": "1.3.9", "@rabby-wallet/page-provider": "0.4.2", "@rabby-wallet/rabby-action": "0.1.4", - "@rabby-wallet/rabby-api": "0.8.4", + "@rabby-wallet/rabby-api": "0.8.5", "@rabby-wallet/rabby-security-engine": "2.0.7", "@rabby-wallet/rabby-swap": "0.0.42", "@rabby-wallet/widgets": "1.0.9", diff --git a/src/background/controller/wallet.ts b/src/background/controller/wallet.ts index 57e89aad4c1..b8f789732ab 100644 --- a/src/background/controller/wallet.ts +++ b/src/background/controller/wallet.ts @@ -47,6 +47,7 @@ import { KEYRING_CLASS, DBK_CHAIN_ID, DBK_NFT_CONTRACT_ADDRESS, + CORE_KEYRING_TYPES, } from 'consts'; import { ERC20ABI } from 'consts/abi'; import { Account, IHighlightedAddress } from '../service/preference'; @@ -1562,7 +1563,17 @@ export class WalletController extends BaseController { private getTotalBalanceCached = cached( 'getTotalBalanceCached', async (address: string) => { - const data = await openapiService.getTotalBalance(address); + const addresses = await keyringService.getAllAdresses(); + const filtered = addresses.filter((item) => + isSameAddress(item.address, address) + ); + let core = false; + if ( + filtered.some((item) => CORE_KEYRING_TYPES.includes(item.type as any)) + ) { + core = true; + } + const data = await openapiService.getTotalBalance(address, core); preferenceService.updateBalanceAboutCache(address, { totalBalance: data, }); diff --git a/src/constant/index.ts b/src/constant/index.ts index eb673d2b050..4aea5c850f4 100644 --- a/src/constant/index.ts +++ b/src/constant/index.ts @@ -261,6 +261,12 @@ export const KEYRING_CLASS = { Coinbase: 'Coinbase', } as const; +export const CORE_KEYRING_TYPES = [ + KEYRING_CLASS.MNEMONIC, + KEYRING_CLASS.PRIVATE_KEY, + ...Object.values(KEYRING_CLASS.HARDWARE), +]; + export const KEYRING_WITH_INDEX = [ KEYRING_CLASS.HARDWARE.LEDGER, KEYRING_CLASS.HARDWARE.GRIDPLUS, diff --git a/yarn.lock b/yarn.lock index 78130aa34e3..dc66542e19e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4781,10 +4781,10 @@ resolved "https://registry.yarnpkg.com/@rabby-wallet/rabby-action/-/rabby-action-0.1.4.tgz#c82e7c8b538b7dfd94506c4f89f78aca7ca880ef" integrity sha512-6ttnlpGHcO2v/qyYo8epBbSutfS9OZXfXr9mfapuveoBvzqUwvE6ej3bsmdtc+qFhFeH7HeiwASpY6xaTM4E1w== -"@rabby-wallet/rabby-api@0.8.4": - version "0.8.4" - resolved "https://registry.yarnpkg.com/@rabby-wallet/rabby-api/-/rabby-api-0.8.4.tgz#ef1979eea94eb5fe4e07fe123444a7213178ce15" - integrity sha512-pN6fL6YHhmW7MTmtJEftfvkljYdgcEtJKk2hX2uBfHJQVRXU+jiGOPhSHPE1yfKV4LNwptdV1jtBv3KaYyKa8Q== +"@rabby-wallet/rabby-api@0.8.5": + version "0.8.5" + resolved "https://registry.yarnpkg.com/@rabby-wallet/rabby-api/-/rabby-api-0.8.5.tgz#b2c7820c52ffe2aa8cb3226304593eaca1231b88" + integrity sha512-yykwK/pZA/5eCn/QCRwgP6uDQQhOdG3Zl1CAjFqK5AVNyc5DE1BCcZWkABWzXjt63KJHePVcAX7rP8rhzbmsTQ== dependencies: "@rabby-wallet/rabby-sign" "0.4.0" axios "^0.27.2"