-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
frontend/account-summary: add coins total balance
Before this update, the account summary didn't show total coin balances, especially when managing multiple wallets with the watch-only feature. This commit addresses that by adding a new coin balances table below the chart. It appears only when there are multiple wallets in the portfolio.
- Loading branch information
Showing
6 changed files
with
243 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
frontends/web/src/routes/account/summary/coinbalance.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/** | ||
* Copyright 2023 Shift Crypto AG | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { useTranslation } from 'react-i18next'; | ||
import * as accountApi from '../../../api/account'; | ||
import { SubTotalCoinRow } from './subtotalrow'; | ||
import { Amount } from '../../../components/amount/amount'; | ||
import { Skeleton } from '../../../components/skeleton/skeleton'; | ||
import style from './accountssummary.module.css'; | ||
|
||
type TProps = { | ||
accounts: accountApi.IAccount[], | ||
summaryData?: accountApi.ISummary, | ||
coinsBalances?: accountApi.TCoinsTotalBalance, | ||
} | ||
|
||
type TAccountCoinMap = { | ||
[code in accountApi.CoinCode]: accountApi.IAccount[]; | ||
}; | ||
|
||
export function CoinBalance ({ | ||
accounts, | ||
summaryData, | ||
coinsBalances, | ||
}: TProps) { | ||
const { t } = useTranslation(); | ||
|
||
const getAccountsPerCoin = () => { | ||
return accounts.reduce((accountPerCoin, account) => { | ||
accountPerCoin[account.coinCode] | ||
? accountPerCoin[account.coinCode].push(account) | ||
: accountPerCoin[account.coinCode] = [account]; | ||
return accountPerCoin; | ||
}, {} as TAccountCoinMap); | ||
}; | ||
|
||
const accountsPerCoin = getAccountsPerCoin(); | ||
const coins = Object.keys(accountsPerCoin) as accountApi.CoinCode[]; | ||
|
||
return ( | ||
<div className={style.balanceTable}> | ||
<table className={style.table}> | ||
<colgroup> | ||
<col width="33%" /> | ||
<col width="33%" /> | ||
<col width="*" /> | ||
</colgroup> | ||
<thead> | ||
<tr> | ||
<th>{t('accountSummary.coin')}</th> | ||
<th>{t('accountSummary.balance')}</th> | ||
<th>{t('accountSummary.fiatBalance')}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{ accounts.length > 0 ? ( | ||
coins.map(coinCode => { | ||
if (accountsPerCoin[coinCode]?.length > 1) { | ||
const account = accountsPerCoin[coinCode][0]; | ||
return ( | ||
<SubTotalCoinRow | ||
key={account.coinCode} | ||
coinCode={account.coinCode} | ||
coinName={account.coinName} | ||
balance={coinsBalances && coinsBalances[coinCode]} | ||
/> | ||
); | ||
} | ||
return ( | ||
<tr> | ||
<td colSpan={3} className={style.noAccount}> | ||
{t('accountSummary.noAccount')} | ||
</td> | ||
</tr> | ||
); | ||
})) : ( | ||
<tr> | ||
<td colSpan={3} className={style.noAccount}> | ||
{t('accountSummary.noAccount')} | ||
</td> | ||
</tr> | ||
)} | ||
</tbody> | ||
<tfoot> | ||
<tr> | ||
<th> | ||
<strong>{t('accountSummary.total')}</strong> | ||
</th> | ||
<td colSpan={2}> | ||
{(summaryData && summaryData.formattedChartTotal !== null) ? ( | ||
<> | ||
<strong> | ||
<Amount amount={summaryData.formattedChartTotal} unit={summaryData.chartFiat}/> | ||
</strong> | ||
{' '} | ||
<span className={style.coinUnit}> | ||
{summaryData.chartFiat} | ||
</span> | ||
</> | ||
) : (<Skeleton />) } | ||
</td> | ||
</tr> | ||
</tfoot> | ||
</table> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters