Skip to content

Commit

Permalink
Merge pull request #450 from soroswap/fix/nativeTokenInBalances
Browse files Browse the repository at this point in the history
✨ Improve native token support to BalancesTable
  • Loading branch information
joaquinsoza authored May 15, 2024
2 parents 7cfc63c + d1682fd commit 4eb2454
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
23 changes: 22 additions & 1 deletion src/components/Balances.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}, ${
Expand Down Expand Up @@ -37,6 +38,26 @@ export function Balances() {

const [currentMintingToken, setCurrentMintingToken] = useState<TokenType | null>(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);
Expand Down Expand Up @@ -104,7 +125,7 @@ export function Balances() {
)}
</Box>
<Box>
<BalancesTable />
<BalancesTable nativeToken={getNativeToken()} />
</Box>
</>
)}
Expand Down
8 changes: 4 additions & 4 deletions src/components/BalancesTable/BalancesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})) ?? [];
Expand Down

0 comments on commit 4eb2454

Please sign in to comment.