-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: common assets columns, #5180
- Loading branch information
Showing
10 changed files
with
159 additions
and
160 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
131 changes: 131 additions & 0 deletions
131
packages/next-common/components/assets/common/columns.jsx
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,131 @@ | ||
import { AssetIconPlaceholder } from "@osn/icons/subsquare"; | ||
import useKnownAssetHubAssetIcon, { | ||
useNativeTokenIcon, | ||
} from "next-common/components/assets/known"; | ||
import BalanceDisplay from "next-common/components/assets/balanceDisplay"; | ||
import { isNil } from "lodash-es"; | ||
import useSubAssetBalance from "next-common/components/assets/useSubAssetBalance"; | ||
import { formatBalance } from "./index"; | ||
|
||
export function TokenSymbol({ type, assetId, symbol }) { | ||
const NativeAssetIcon = useNativeTokenIcon(); | ||
const Icon = useKnownAssetHubAssetIcon(assetId); | ||
let AssetIcon = NativeAssetIcon; | ||
if (type !== "native") { | ||
AssetIcon = Icon || AssetIconPlaceholder; | ||
} | ||
|
||
return ( | ||
<div className="flex gap-[8px] items-center text14Medium text-textPrimary"> | ||
<AssetIcon width={24} height={24} /> {symbol} | ||
</div> | ||
); | ||
} | ||
|
||
export const colToken = { | ||
name: "Token", | ||
style: { textAlign: "left", width: "160px", minWidth: "160px" }, | ||
render: (item) => ( | ||
<TokenSymbol | ||
key="token" | ||
type={item.type} | ||
assetId={item.assetId} | ||
symbol={item.symbol} | ||
/> | ||
), | ||
}; | ||
|
||
export const colId = { | ||
name: "ID", | ||
style: { textAlign: "left", width: "120px", minWidth: "120px" }, | ||
render: (item) => ( | ||
<span className="text14Medium text-textTertiary"> | ||
{isNil(item.assetId) ? "-" : `#${item.assetId}`} | ||
</span> | ||
), | ||
}; | ||
|
||
export const colName = { | ||
name: "Name", | ||
style: { textAlign: "left", minWidth: "256px" }, | ||
render: (item) => ( | ||
<div | ||
key="name" | ||
className="text14Medium text-textTertiary truncate max-w-[240px]" | ||
> | ||
{item.name} | ||
</div> | ||
), | ||
}; | ||
|
||
function TotalBalance({ item, address }) { | ||
const { result } = useSubAssetBalance(item.assetId, address); | ||
|
||
return ( | ||
<span className="text14Medium text-textPrimary"> | ||
<BalanceDisplay | ||
balance={formatBalance( | ||
result?.balance || item?.balance || 0, | ||
item.decimals, | ||
)} | ||
/> | ||
</span> | ||
); | ||
} | ||
|
||
function TransferrableBalance({ item, address }) { | ||
const { result } = useSubAssetBalance(item.assetId, address); | ||
|
||
return ( | ||
<span key="transferrable" className="text14Medium text-textPrimary"> | ||
<BalanceDisplay | ||
balance={formatBalance( | ||
result?.transferrable || item.transferrable || 0, | ||
item.decimals, | ||
)} | ||
/> | ||
</span> | ||
); | ||
} | ||
|
||
export function useColTotal(address) { | ||
return { | ||
name: "Total", | ||
style: { textAlign: "right", width: "160px", minWidth: "160px" }, | ||
render: (item) => ( | ||
<TotalBalance key="total" item={item} address={address} /> | ||
), | ||
}; | ||
} | ||
|
||
export function useColTransferrable(address) { | ||
return { | ||
name: "Transferrable", | ||
style: { textAlign: "right", width: "160px", minWidth: "160px" }, | ||
render: (item) => <TransferrableBalance item={item} address={address} />, | ||
}; | ||
} | ||
|
||
export const colTotal = { | ||
name: "Total", | ||
style: { textAlign: "right", width: "160px", minWidth: "160px" }, | ||
render: (item) => ( | ||
<span key="total" className="text14Medium text-textPrimary"> | ||
<BalanceDisplay | ||
balance={formatBalance(item.balance || 0, item.decimals)} | ||
/> | ||
</span> | ||
), | ||
}; | ||
|
||
export const colTransferrable = { | ||
name: "Transferrable", | ||
style: { textAlign: "right", width: "160px", minWidth: "160px" }, | ||
render: (item) => ( | ||
<span key="transferrable" className="text14Medium text-textPrimary"> | ||
<BalanceDisplay | ||
balance={formatBalance(item.transferrable || 0, item.decimals)} | ||
/> | ||
</span> | ||
), | ||
}; |
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,8 @@ | ||
import BigNumber from "bignumber.js"; | ||
|
||
export function formatBalance(balance, decimals) { | ||
return new BigNumber(balance) | ||
.div(Math.pow(10, decimals)) | ||
.decimalPlaces(4, BigNumber.ROUND_FLOOR) | ||
.toFormat({ decimalSeparator: ".", groupSeparator: ",", groupSize: 3 }); | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/next-common/components/assets/transferHistory/columns/token.jsx
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
2 changes: 1 addition & 1 deletion
2
packages/next-common/components/popup/fields/amountInputWithHint.js
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
2 changes: 1 addition & 1 deletion
2
packages/next-common/components/popup/fields/transferAmountField.js
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
2 changes: 1 addition & 1 deletion
2
packages/next-common/components/treasury/childBounty/proposeCurator/useFeeAmount.jsx
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