-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add src-20 token balances, closes #3751
- Loading branch information
Showing
11 changed files
with
117 additions
and
42 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
39 changes: 39 additions & 0 deletions
39
...components/crypto-assets/bitcoin/src20-token-asset-list/src20-token-asset-item.layout.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,39 @@ | ||
import { styled } from 'leather-styles/jsx'; | ||
|
||
import { createMoney } from '@shared/models/money.model'; | ||
|
||
import { formatBalance } from '@app/common/format-balance'; | ||
import type { Src20Token } from '@app/query/bitcoin/stamps/stamps-by-address.query'; | ||
import { Src20AvatarIcon } from '@app/ui/components/avatar/src20-avatar-icon'; | ||
import { ItemLayout } from '@app/ui/components/item-layout/item-layout'; | ||
import { BasicTooltip } from '@app/ui/components/tooltip/basic-tooltip'; | ||
import { Pressable } from '@app/ui/pressable/pressable'; | ||
|
||
interface Src20TokenAssetItemLayoutProps { | ||
token: Src20Token; | ||
} | ||
export function Src20TokenAssetItemLayout({ token }: Src20TokenAssetItemLayoutProps) { | ||
const balance = createMoney(Number(token.amt), token.tick, 0).amount.toString(); | ||
const formattedBalance = formatBalance(balance); | ||
|
||
return ( | ||
<Pressable my="space.02"> | ||
<ItemLayout | ||
flagImg={<Src20AvatarIcon />} | ||
titleLeft={token.tick.toUpperCase()} | ||
captionLeft="SRC-20" | ||
titleRight={ | ||
<BasicTooltip | ||
asChild | ||
label={formattedBalance.isAbbreviated ? balance : undefined} | ||
side="left" | ||
> | ||
<styled.span data-testid={token.tick} fontWeight={500} textStyle="label.02"> | ||
{formattedBalance.value} | ||
</styled.span> | ||
</BasicTooltip> | ||
} | ||
/> | ||
</Pressable> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/app/components/crypto-assets/bitcoin/src20-token-asset-list/src20-token-asset-list.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,10 @@ | ||
import type { Src20Token } from '@app/query/bitcoin/stamps/stamps-by-address.query'; | ||
|
||
import { Src20TokenAssetItemLayout } from './src20-token-asset-item.layout'; | ||
|
||
interface Src20TokenAssetListProps { | ||
src20Tokens: Src20Token[]; | ||
} | ||
export function Src20TokenAssetList({ src20Tokens = [] }: Src20TokenAssetListProps) { | ||
return src20Tokens.map(token => <Src20TokenAssetItemLayout key={token.id} token={token} />); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { ReactNode } from 'react'; | ||
|
||
import { useSrc20TokensByAddress } from '@app/query/bitcoin/stamps/stamps-by-address.hooks'; | ||
import type { Src20Token } from '@app/query/bitcoin/stamps/stamps-by-address.query'; | ||
|
||
interface Src20TokensLoaderProps { | ||
address: string; | ||
children(src20Tokens: Src20Token[]): ReactNode; | ||
} | ||
|
||
export function Src20TokensLoader({ address, children }: Src20TokensLoaderProps) { | ||
const { data: src20Tokens } = useSrc20TokensByAddress(address); | ||
|
||
if (!src20Tokens) return null; | ||
return children(src20Tokens); | ||
} |
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
27 changes: 14 additions & 13 deletions
27
src/app/features/asset-list/components/bitcoin-fungible-tokens-asset-list.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 |
---|---|---|
@@ -1,19 +1,20 @@ | ||
import { Stack } from 'leather-styles/jsx'; | ||
|
||
import { Brc20TokenAssetItemLayout } from '@app/components/crypto-assets/bitcoin/brc20-token-asset-list/components/brc20-token-asset-item.layout'; | ||
import { Brc20Token } from '@app/query/bitcoin/bitcoin-client'; | ||
import { Brc20TokensLoader } from '@app/components/brc20-tokens-loader'; | ||
import { Brc20TokenAssetList } from '@app/components/crypto-assets/bitcoin/brc20-token-asset-list/brc20-token-asset-list'; | ||
import { Src20TokenAssetList } from '@app/components/crypto-assets/bitcoin/src20-token-asset-list/src20-token-asset-list'; | ||
import { Src20TokensLoader } from '@app/components/src20-tokens-loader'; | ||
|
||
interface BitcoinFungibleTokenAssetListProps { | ||
brc20Tokens?: Brc20Token[]; | ||
btcAddress: string; | ||
} | ||
export function BitcoinFungibleTokenAssetList({ brc20Tokens }: BitcoinFungibleTokenAssetListProps) { | ||
if (!brc20Tokens) return null; | ||
|
||
export function BitcoinFungibleTokenAssetList({ btcAddress }: BitcoinFungibleTokenAssetListProps) { | ||
return ( | ||
<Stack gap="space.05"> | ||
{brc20Tokens.map(token => ( | ||
<Brc20TokenAssetItemLayout key={token.ticker} token={token} /> | ||
))} | ||
</Stack> | ||
<> | ||
<Brc20TokensLoader> | ||
{brc20Tokens => <Brc20TokenAssetList brc20Tokens={brc20Tokens} />} | ||
</Brc20TokensLoader> | ||
<Src20TokensLoader address={btcAddress}> | ||
{src20Tokens => <Src20TokenAssetList src20Tokens={src20Tokens} />} | ||
</Src20TokensLoader> | ||
</> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useStampsByAddressQuery } from './stamps-by-address.query'; | ||
|
||
export function useStampsByAddress(address: string) { | ||
return useStampsByAddressQuery(address, { | ||
select(data) { | ||
return data.data.stamps; | ||
}, | ||
}); | ||
} | ||
|
||
export function useSrc20TokensByAddress(address: string) { | ||
return useStampsByAddressQuery(address, { | ||
select(data) { | ||
return data.data.src20; | ||
}, | ||
}); | ||
} |
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