Skip to content

Commit

Permalink
feat: remove unused function & modify the controller for balance cach…
Browse files Browse the repository at this point in the history
…e update
  • Loading branch information
oho-mu committed Sep 12, 2024
1 parent 9f23dd1 commit f862c13
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
16 changes: 14 additions & 2 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1636,8 +1636,20 @@ export class WalletController extends BaseController {
return this.getTotalBalanceCached.isExpired(address);
};

updateAddressBalanceCache = (address: string, balance: string) => {
preferenceService.updateAddressUSDValueCache(address, Number(balance));
updateAddressBalanceCache = async (address: string, balance: string) => {
let totalBalance = this.getAddressCacheBalance(address);

// if not in cache, fetch from openapi
if (!totalBalance) {
totalBalance = await openapiService.getTotalBalance(address);
}
// update balance
preferenceService.updateBalanceAboutCache(address, {
totalBalance: {
...totalBalance,
total_usd_value: Number(balance),
},
});
};
getAddressCacheBalance = (address: string | undefined, isTestnet = false) => {
if (!address) return null;
Expand Down
12 changes: 0 additions & 12 deletions src/background/service/preference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,18 +467,6 @@ class PreferenceService {

getPopupOpen = () => this.popupOpen;

updateAddressUSDValueCache = (address: string, balance: number) => {
const balanceMap = this.store.balanceMap || {};
const before = this.store.balanceMap[address.toLowerCase()];
this.store.balanceMap = {
...balanceMap,
[address.toLowerCase()]: {
total_usd_value: balance,
chain_list: before.chain_list || [],
},
};
};

updateTestnetAddressBalance = (
address: string,
data: TotalBalanceResponse
Expand Down

0 comments on commit f862c13

Please sign in to comment.