Skip to content

Commit 144f1d3

Browse files
evavirsedabegonaalvarezdcpl121
authored
feat: show total tokens in the asset list (#8249)
* feat: show token balance * fix: show total and available mana properly * fix: update balanceSummary details * fix import * improvements * feat: improve balance brekdown view, refine styles and update locales --------- Co-authored-by: Begoña Álvarez de la Cruz <balvarez@boxfish.studio> Co-authored-by: cpl121 <100352899+cpl121@users.noreply.github.com>
1 parent e806be8 commit 144f1d3

File tree

6 files changed

+91
-36
lines changed

6 files changed

+91
-36
lines changed

packages/desktop/components/popups/BalanceBreakdownPopup.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
subtitleKey={breakdownKey}
176176
amount={breakdown[breakdownKey].amount}
177177
subBreakdown={breakdown[breakdownKey].subBreakdown}
178-
isBaseToken={breakdown[breakdownKey].isBaseToken}
178+
isBaseToken={breakdownKey !== 'mana'}
179179
/>
180180
{/each}
181181
<BalanceSummarySection titleKey="totalBalance" amount={Number(walletBalance?.baseCoin?.total ?? 0)} bold />

packages/desktop/components/popups/TokenInformationPopup.svelte

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@
2323
AssetActionsModal,
2424
MeatballMenuButton,
2525
Modal,
26+
BalanceSummarySection,
2627
} from '@ui'
2728
import { TextHintVariant } from '@ui/enums'
2829
import { MANA_ID } from '@core/network'
2930
3031
export let asset: IAsset
3132
export let activityId: string = undefined
3233
34+
const balanceSummary = getBalanceSummary()
35+
3336
let modal: Modal
3437
3538
function onSkipClick(): void {
@@ -72,10 +75,20 @@
7275
overflow: true,
7376
})
7477
}
78+
79+
function getBalanceSummary(): { amount: number; details?: { [key: string]: { amount: number } } } {
80+
const totalBalance = asset?.balance?.total
81+
82+
const details = {
83+
availableAmount: { amount: asset?.balance?.available },
84+
conditionallyLocked: { amount: asset?.balance?.total - asset?.balance?.available },
85+
}
86+
return { amount: totalBalance, details }
87+
}
7588
</script>
7689

7790
{#if asset}
78-
<div class="space-y-6">
91+
<div class="space-y-6 max-h-xl scrollable-y">
7992
<div class="flex flex-row justify-between items-center space-x-3 mr-8">
8093
<Text
8194
type={TextType.h4}
@@ -127,9 +140,16 @@
127140
isCopyable
128141
/>
129142
{/if}
143+
<balance-wrapper class="flex flex-col bg-gray-50 dark:bg-gray-850 px-4 py-4 rounded-lg">
144+
<BalanceSummarySection
145+
{asset}
146+
titleKey="totalBalanceAmount"
147+
amount={balanceSummary?.amount}
148+
subBreakdown={balanceSummary?.details}
149+
/>
150+
</balance-wrapper>
130151
</div>
131152
</div>
132-
133153
<div class="flex flex-row flex-nowrap w-full space-x-4">
134154
{#if asset.verification?.status === NotVerifiedStatus.New}
135155
<Button outline classes="w-full" onClick={onSkipClick}>

packages/shared/components/BalanceSummaryRow.svelte

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,39 @@
66
export let bold: boolean = false
77
export let amount: string
88
export let convertedAmount: string
9+
export let secondaryStyle: boolean = false
910
10-
const PRIMARY_TEXT_CONFIG = {
11-
color: 'gray-800',
12-
darkColor: 'white',
13-
fontSize: '15',
14-
fontWeight: bold ? FontWeight.semibold : FontWeight.normal,
15-
lineHeight: '5',
16-
}
17-
18-
const SECONDARY_TEXT_CONFIG = {
19-
color: 'gray-600',
20-
darkColor: 'gray-400',
21-
fontSize: '13',
22-
fontWeight: FontWeight.normal,
23-
lineHeight: '4',
11+
const TEXT_CONFIG = {
12+
primary: {
13+
color: 'gray-800',
14+
darkColor: 'white',
15+
fontSize: '15',
16+
fontWeight: bold ? FontWeight.semibold : FontWeight.normal,
17+
lineHeight: '5',
18+
},
19+
secondary: {
20+
color: 'gray-600',
21+
darkColor: 'gray-400',
22+
fontSize: '13',
23+
fontWeight: FontWeight.normal,
24+
lineHeight: '4',
25+
},
2426
}
2527
</script>
2628

2729
<div class="flex flex-row justify-between flex-grow">
2830
<div class={title ? 'flex flex-col space-y-0.5' : null}>
29-
<Text {...PRIMARY_TEXT_CONFIG}>{title}</Text>
31+
<Text {...secondaryStyle ? TEXT_CONFIG.secondary : TEXT_CONFIG.primary}>
32+
{title}
33+
</Text>
3034
{#if subtitle}
31-
<Text {...SECONDARY_TEXT_CONFIG}>{subtitle}</Text>
35+
<Text {...TEXT_CONFIG.secondary}>{subtitle}</Text>
3236
{/if}
3337
</div>
3438
<div class="flex flex-col items-end space-y-0.5">
35-
<Text {...PRIMARY_TEXT_CONFIG} classes="text-right">{amount}</Text>
36-
<Text {...SECONDARY_TEXT_CONFIG} classes="text-right">{convertedAmount}</Text>
39+
<Text {...secondaryStyle ? TEXT_CONFIG.secondary : TEXT_CONFIG.primary} classes="text-right">
40+
{amount}
41+
</Text>
42+
<Text {...TEXT_CONFIG.secondary} classes="text-right">{convertedAmount}</Text>
3743
</div>
3844
</div>

packages/shared/components/BalanceSummarySection.svelte

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<script lang="ts">
22
import { formatCurrency, localize } from '@core/i18n'
33
import { getMarketAmountFromAssetValue } from '@core/market/utils'
4-
import { formatTokenAmountBestMatch, selectedWalletAssets } from '@core/wallet'
4+
import { IAsset, TokenMetadata, formatTokenAmountBestMatch, selectedWalletAssets } from '@core/wallet'
55
import { BalanceSummaryRow, Icon } from '@ui'
66
import { Icon as IconEnum } from '@auxiliary/icon'
77
import { activeProfile } from '@core/profile'
88
import { DEFAULT_MANA } from '@core/network'
99
10+
export let asset: IAsset | null = null
1011
export let titleKey: string
1112
export let subtitleKey: string = ''
1213
export let subBreakdown: { [key: string]: { amount: number } } = {}
@@ -19,8 +20,12 @@
1920
$: hasChildren = !!Object.keys(subBreakdown ?? {}).length
2021
$: ({ baseCoin } = $selectedWalletAssets?.[$activeProfile?.network?.id] ?? {})
2122
22-
function getAmount(amount: number): string {
23-
return baseCoin?.metadata ? formatTokenAmountBestMatch(amount, baseCoin?.metadata) : ''
23+
function getAmount(amount: number, asset: IAsset | null): string {
24+
if (!asset) {
25+
return baseCoin?.metadata ? formatTokenAmountBestMatch(amount, baseCoin?.metadata) : ''
26+
} else {
27+
return asset?.metadata ? formatTokenAmountBestMatch(amount, asset?.metadata) : ''
28+
}
2429
}
2530
2631
function getAmountMana(amount: number): string {
@@ -32,16 +37,28 @@
3237
}
3338
}
3439
35-
function handleAmount(isBaseToken: boolean, amount: number) {
36-
return isBaseToken ? getAmount(amount) : getAmountMana(amount)
40+
function handleAmount(isBaseToken: boolean = false, amount: number, asset: IAsset | null): string {
41+
if (!asset) {
42+
return isBaseToken ? getAmount(amount, null) : getAmountMana(amount)
43+
} else {
44+
return getAmount(amount, asset)
45+
}
3746
}
3847
39-
function handleCurrencyAmount(isBaseToken: boolean, amount: number) {
40-
return isBaseToken ? getCurrencyAmount(amount) : getAmountMana(amount)
48+
function handleCurrencyAmount(isBaseToken: boolean = false, amount: number, asset: IAsset | null): string {
49+
if (!asset) {
50+
return isBaseToken ? getCurrencyAmount(amount, null, baseCoin) : ''
51+
} else {
52+
return ''
53+
}
4154
}
4255
43-
function getCurrencyAmount(amount: number): string {
44-
return baseCoin ? formatCurrency(getMarketAmountFromAssetValue(amount, baseCoin)) : ''
56+
function getCurrencyAmount(amount: number, asset: IAsset | null, baseCoin: IAsset | null | undefined): string {
57+
if (!asset) {
58+
return baseCoin ? formatCurrency(getMarketAmountFromAssetValue(amount, baseCoin)) : ''
59+
} else {
60+
return formatTokenAmountBestMatch(amount, asset?.metadata as TokenMetadata)
61+
}
4562
}
4663
4764
function toggleExpandedView(): void {
@@ -67,8 +84,8 @@
6784
<BalanceSummaryRow
6885
title={titleKey ? localize(`popups.balanceBreakdown.${titleKey}.title`) : ''}
6986
subtitle={subtitleKey ? localize(`popups.balanceBreakdown.${subtitleKey}.subtitle`) : ''}
70-
amount={handleAmount(isBaseToken, amount)}
71-
convertedAmount={handleCurrencyAmount(isBaseToken, amount)}
87+
amount={handleAmount(isBaseToken, amount, asset)}
88+
convertedAmount={handleCurrencyAmount(isBaseToken, amount, asset)}
7289
{bold}
7390
/>
7491
</div>
@@ -77,9 +94,10 @@
7794
<balance-summary-row-expanded class="ml-8">
7895
<BalanceSummaryRow
7996
title={localize(`popups.balanceBreakdown.${breakdownKey}.title`)}
80-
subtitle={localize(`popups.balanceBreakdown.${breakdownKey}.subtitle`)}
81-
amount={handleAmount(isBaseToken, subBreakdown[breakdownKey].amount)}
82-
convertedAmount={handleCurrencyAmount(isBaseToken, subBreakdown[breakdownKey].amount)}
97+
subtitle={!asset ? localize(`popups.balanceBreakdown.${breakdownKey}.subtitle`) : undefined}
98+
amount={handleAmount(isBaseToken, subBreakdown[breakdownKey].amount, asset)}
99+
convertedAmount={handleCurrencyAmount(isBaseToken, subBreakdown[breakdownKey].amount, asset)}
100+
secondaryStyle={asset ? true : false}
83101
/>
84102
</balance-summary-row-expanded>
85103
{/each}

packages/shared/components/tiles/AssetTile.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { getMarketAmountFromAssetValue } from '@core/market/utils/getMarketAmountFromAssetValue'
77
import { getMarketPriceForAsset } from '@core/market/utils'
88
import { AssetIconSize } from '@ui/enums'
9+
import { MANA_ID } from '@core/network'
910
1011
export let asset: IAsset | undefined
1112
export let onClick: () => unknown
@@ -15,6 +16,7 @@
1516
1617
$: marketPrice = asset ? getMarketPriceForAsset(asset) : undefined
1718
$: marketBalance = asset ? getMarketAmountFromAssetValue(asset.balance?.total, asset) : undefined
19+
$: total = (asset?.id === MANA_ID ? asset?.balance?.available : asset?.balance?.total) ?? 0
1820
</script>
1921

2022
{#if asset}
@@ -46,7 +48,7 @@
4648
</div>
4749
<div class="flex flex-col text-right">
4850
<Text type={TextType.p} fontWeight={FontWeight.semibold}>
49-
{asset.metadata ? formatTokenAmountBestMatch(asset.balance?.total, asset.metadata) : '-'}
51+
{asset.metadata ? formatTokenAmountBestMatch(total, asset.metadata) : '-'}
5052
</Text>
5153
{#if !squashed}
5254
<div class="flex flex-row justify-between items-center text-right">

packages/shared/locales/en.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,15 @@
851851
"title": "Available Mana",
852852
"subtitle": "Mana available to send and issue blocks"
853853
},
854+
"totalBalanceAmount": {
855+
"title": "Total balance amount"
856+
},
857+
"availableAmount": {
858+
"title": "Available amount"
859+
},
860+
"conditionallyLocked": {
861+
"title": "Conditionally locked amount"
862+
},
854863
"minimizeStorageDepositButton": "Minimize storage deposit"
855864
},
856865
"minimizeStorageDeposit": {

0 commit comments

Comments
 (0)