diff --git a/packages/shared/lib/wallet.ts b/packages/shared/lib/wallet.ts index 90d57f0f8e7..b84f6a1cada 100644 --- a/packages/shared/lib/wallet.ts +++ b/packages/shared/lib/wallet.ts @@ -424,6 +424,26 @@ export const updateBalanceOverview = (balance: number, incoming: number, outgoin }); }; +/** + * Updates balance overview fiat value + * + * @method updateBalanceOverviewFiat + * + * @returns {void} + */ +export const updateBalanceOverviewFiat = (): void => { + const { balanceOverview } = get(wallet); + balanceOverview.update((overview) => { + return Object.assign>({} as BalanceOverview, overview, { + balanceFiat: `${convertToFiat( + overview.balanceRaw, + get(currencies)[CurrencyTypes.USD], + get(exchangeRates)[get(activeProfile).settings.currency] + )} ${get(activeProfile).settings.currency}`, + }); + }); +} + /** * Updates accounts information after a successful sync accounts operation * @@ -468,6 +488,28 @@ function mergeProps(existingPayload: T[], newPayload: T[], prop: string): T[] return Object.values(Object.assign({}, existingPayloadMap, newPayloadMap)) } +/** + * Updates balance fiat value for every account + * + * @method updateAccountBalanceEquiv + * + * @returns {void} + */ +export const updateAccountsBalanceEquiv = (): void => { + const { accounts } = get(wallet) + accounts.update((storedAccounts) => { + return storedAccounts.map((storedAccount) => { + return Object.assign>({} as WalletAccount, storedAccount, { + balanceEquiv: `${convertToFiat( + storedAccount.rawIotaBalance, + get(currencies)[CurrencyTypes.USD], + get(exchangeRates)[get(activeProfile).settings.currency] + )} ${get(activeProfile).settings.currency}`, + }) + }) + }) +} + /** * Gets balance history for each account in market data timestamps * diff --git a/packages/shared/routes/dashboard/settings/views/General.svelte b/packages/shared/routes/dashboard/settings/views/General.svelte index 62698acb6ae..7a842388332 100644 --- a/packages/shared/routes/dashboard/settings/views/General.svelte +++ b/packages/shared/routes/dashboard/settings/views/General.svelte @@ -3,6 +3,7 @@ import { darkMode } from 'shared/lib/app' import { Text, Radio, Dropdown, Checkbox } from 'shared/components' import { exchangeRates } from 'shared/lib/currency' + import { updateAccountsBalanceEquiv, updateBalanceOverviewFiat } from 'shared/lib/wallet' import { addProfileCurrencyPriceData } from 'shared/lib/marketData' import { locales, setupI18n } from 'shared/lib/i18n' import { activeProfile, updateProfile } from 'shared/lib/profile' @@ -24,6 +25,8 @@ const handleCurrencySelect = (item) => { updateProfile('settings.currency', item.value) addProfileCurrencyPriceData() + updateBalanceOverviewFiat() + updateAccountsBalanceEquiv() }