Skip to content

Commit

Permalink
fix available balance toggle on custom network (#8503)
Browse files Browse the repository at this point in the history
Co-authored-by: Begoña Álvarez de la Cruz <balvarez@boxfish.studio>
Co-authored-by: cpl121 <100352899+cpl121@users.noreply.github.com>
  • Loading branch information
3 people authored May 7, 2024
1 parent b0f7249 commit 2f3f38c
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import { formatTokenAmountBestMatch, IAsset } from '@core/wallet'
import { formatCurrency, localize } from '@core/i18n'
import { getMarketAmountFromAssetValue } from '@core/market/utils'
import { NetworkId } from '@core/network'
import { activeProfile } from '@core/profile'
export let asset: IAsset
$: availableMarketValue = getMarketAmountFromAssetValue(asset?.balance?.available, asset)
$: totalMarketValue = getMarketAmountFromAssetValue(asset?.balance?.total, asset)
$: disabled = Number.isNaN(totalMarketValue) || Number.isNaN(availableMarketValue)
$: isCustomNetwork = $activeProfile?.network?.id === NetworkId.Custom
let isToggled = false
function toggle(): void {
Expand All @@ -20,16 +23,17 @@
<button on:click={toggle} type="button" {disabled}>
<div class="flex flex-col flex-wrap items-start space-y-1">
<Text type={TextType.h1} fontWeight={FontWeight.semibold}>
{isToggled
{isToggled && !isCustomNetwork
? formatCurrency(totalMarketValue)
: formatTokenAmountBestMatch(asset?.balance?.total, asset?.metadata)}
</Text>
<Text type={TextType.p} fontWeight={FontWeight.medium} color="gray-600" darkColor="gray-500">
{localize('general.availableBalanceWithValue', {
values: {
balance: isToggled
? formatCurrency(availableMarketValue)
: formatTokenAmountBestMatch(asset?.balance?.available, asset?.metadata),
balance:
isToggled && !isCustomNetwork
? formatCurrency(availableMarketValue)
: formatTokenAmountBestMatch(asset?.balance?.available, asset?.metadata),
},
})}
</Text>
Expand Down

0 comments on commit 2f3f38c

Please sign in to comment.