Skip to content

Commit

Permalink
Merge pull request #82 from dappforce/fix-balances
Browse files Browse the repository at this point in the history
Fix balances in balances table
  • Loading branch information
samchuk-vlad authored Oct 23, 2023
2 parents 47501d5 + 1876bcf commit f3470b0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
22 changes: 16 additions & 6 deletions src/components/identity/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,22 @@ export type Info = {

export type InfoKeys = keyof Info

export const identityInfoKeys: InfoKeys[] = [ 'display', 'legal', 'web', 'riot', 'email', 'twitter' ]
export const identityInfoKeys: InfoKeys[] = [
'display',
'legal',
'web',
'riot',
'email',
'twitter',
]

export type AccountInfoByChain = {
accountId: string
totalBalance: string
freeBalance: string
frozenFee: string
reservedBalance: string
frozenMisc: string
frozenBalance: string
freeBalance: string
lockedBalance: string
}

export type AccountInfoItem = {
Expand All @@ -41,7 +48,10 @@ export type CrowdloansContributions = {
contribution: string
}

export type CrowdloansContributionsByParaId = Record<string, CrowdloansContributions>
export type CrowdloansContributionsByParaId = Record<
string,
CrowdloansContributions
>

export type CrowdloanInfo = {
depositor?: string
Expand Down Expand Up @@ -79,4 +89,4 @@ export type SubsocialProfile = {
experimental: Record<string, string>
}

export type AccountIdentities = Record<string, SubsocialProfile | Identity>
export type AccountIdentities = Record<string, SubsocialProfile | Identity>
12 changes: 4 additions & 8 deletions src/components/table/balancesTable/parseBalanceInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,18 @@ import { FiSend } from 'react-icons/fi'
import { LinksButton } from '../links/Links'

const getAccountData = (info: AccountInfoByChain, t: TFunction) => {
const { reservedBalance, frozenFee, freeBalance, frozenMisc } = info

const transferableBalance = new BN(freeBalance || 0)
.minus(new BN(frozenMisc || frozenFee || 0))
.toString()
const { reservedBalance, frozenBalance, freeBalance, lockedBalance } = info

return [
{
key: 'frozen',
label: t('table.balances.frozen'),
value: frozenFee?.toString() || '0',
value: frozenBalance?.toString() || '0',
},
{
key: 'locked',
label: t('table.balances.locked'),
value: frozenMisc?.toString() || '0',
value: lockedBalance?.toString() || '0',
},
{
key: 'reserved',
Expand All @@ -65,7 +61,7 @@ const getAccountData = (info: AccountInfoByChain, t: TFunction) => {
{
key: 'free',
label: t('table.balances.free'),
value: transferableBalance,
value: freeBalance,
},
]
}
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@
},
"table": {
"balances": {
"frozen": "Frozen fee",
"frozen": "Frozen",
"locked": "Locked balance",
"reserved": "Reserved balance",
"free": "Transferable",
Expand Down
8 changes: 5 additions & 3 deletions src/utils/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import BN from 'bn.js'
import { BN_ZERO } from '@polkadot/util'
import { AccountInfoByChain } from 'src/components/identity/types'

export const getTransferableBalance = (data: AccountInfoByChain | undefined) => {
export const getTransferableBalance = (
data: AccountInfoByChain | undefined
) => {
if (!data) return BN_ZERO
const { freeBalance, frozenMisc, frozenFee } = data
return new BN(freeBalance).sub(new BN(frozenMisc || frozenFee || BN_ZERO))
const { freeBalance } = data
return new BN(freeBalance)
}
1 change: 1 addition & 0 deletions tsconfig.tsbuildinfo

Large diffs are not rendered by default.

0 comments on commit f3470b0

Please sign in to comment.