Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions packages/shared/lib/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BalanceOverview, BalanceOverview, Partial<BalanceOverview>>({} 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
*
Expand Down Expand Up @@ -468,6 +488,28 @@ function mergeProps<T>(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<WalletAccount, WalletAccount, Partial<WalletAccount>>({} 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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -24,6 +25,8 @@
const handleCurrencySelect = (item) => {
updateProfile('settings.currency', item.value)
addProfileCurrencyPriceData()
updateBalanceOverviewFiat()
updateAccountsBalanceEquiv()
}
</script>

Expand Down