From d1682fd965926efdb7543dd29622cb4535a91f21 Mon Sep 17 00:00:00 2001 From: Matias Poblete Date: Mon, 13 May 2024 19:23:47 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Improve=20native=20token=20support?= =?UTF-8?q?=20to=20BalancesTable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Balances.tsx | 23 ++++++++++++++++++- .../BalancesTable/BalancesTable.tsx | 8 +++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/components/Balances.tsx b/src/components/Balances.tsx index 7cefeedc..1f552223 100644 --- a/src/components/Balances.tsx +++ b/src/components/Balances.tsx @@ -9,6 +9,7 @@ import BalancesTable from './BalancesTable/BalancesTable'; import { ButtonPrimary } from './Buttons/Button'; import { WalletButton } from './Buttons/WalletButton'; import { MintCustomToken } from './MintCustomToken'; +import { xlmTokenList } from 'constants/xlmToken'; const PageWrapper = styled(Paper)` background: ${({ theme }) => `linear-gradient(${theme.palette.customBackground.bg2}, ${ @@ -37,6 +38,26 @@ export function Balances() { const [currentMintingToken, setCurrentMintingToken] = useState(null); const [isMinting, setIsMinting] = useState(false); + const getNetwork = () => { + switch (sorobanContext.activeChain?.networkPassphrase) { + case Networks.TESTNET: + return 'testnet'; + case Networks.PUBLIC: + return 'mainnet'; + case Networks.STANDALONE: + return 'standalone'; + case Networks.FUTURENET: + return 'futurenet'; + default: + return 'Unknown'; + } + } + + const getNativeToken = () => { + const network = getNetwork(); + const nativeToken = xlmTokenList.find((token) => token.network === network); + return nativeToken?.assets[0]; + } const handleMint = () => { setIsMinting(true); @@ -104,7 +125,7 @@ export function Balances() { )} - + )} diff --git a/src/components/BalancesTable/BalancesTable.tsx b/src/components/BalancesTable/BalancesTable.tsx index 06c45a61..bad2e8b9 100644 --- a/src/components/BalancesTable/BalancesTable.tsx +++ b/src/components/BalancesTable/BalancesTable.tsx @@ -119,15 +119,15 @@ function BalancesTableHead(props: BalancesTableProps) { ); } -export default function BalancesTable() { +export default function BalancesTable(props: any) { + const { nativeToken } = props; const { tokens, tokenBalancesResponse } = useGetMyBalances(); - const rows = - tokenBalancesResponse?.balances?.map((x) => ({ + tokenBalancesResponse?.balances?.map((x) => ({ ...x, type: x.issuer ? 'Stellar Classic Asset' - : x.name == 'Stellar Lumens' + : (x.contract === nativeToken.contract && x.code === nativeToken.code) ? 'Native' : 'Soroban Token', })) ?? [];