-
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.
- Loading branch information
Showing
15 changed files
with
174 additions
and
21 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
37 changes: 37 additions & 0 deletions
37
src/app/components/crypto-assets/bitcoin/runes-asset-list/runes-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,37 @@ | ||
import { styled } from 'leather-styles/jsx'; | ||
|
||
import { formatBalance } from '@app/common/format-balance'; | ||
import type { RuneToken } from '@app/query/bitcoin/bitcoin-client'; | ||
import { RunesAvatarIcon } from '@app/ui/components/avatar/runes-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 RunesAssetItemLayoutProps { | ||
rune: RuneToken; | ||
} | ||
export function RunesAssetItemLayout({ rune }: RunesAssetItemLayoutProps) { | ||
const balance = rune.balance.amount.toString(); | ||
const formattedBalance = formatBalance(balance); | ||
|
||
return ( | ||
<Pressable my="space.02"> | ||
<ItemLayout | ||
flagImg={<RunesAvatarIcon />} | ||
titleLeft={rune.rune_name.toUpperCase()} | ||
captionLeft="RUNE" | ||
titleRight={ | ||
<BasicTooltip | ||
asChild | ||
label={formattedBalance.isAbbreviated ? balance : undefined} | ||
side="left" | ||
> | ||
<styled.span data-testid={rune.rune_name} fontWeight={500} textStyle="label.02"> | ||
{formattedBalance.value} | ||
</styled.span> | ||
</BasicTooltip> | ||
} | ||
/> | ||
</Pressable> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/app/components/crypto-assets/bitcoin/runes-asset-list/runes-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 { RuneToken } from '@app/query/bitcoin/bitcoin-client'; | ||
|
||
import { RunesAssetItemLayout } from './runes-asset-item.layout'; | ||
|
||
interface RunesAssetListProps { | ||
runes: RuneToken[]; | ||
} | ||
export function RunesAssetList({ runes }: RunesAssetListProps) { | ||
return runes.map(rune => <RunesAssetItemLayout key={rune.rune_id} rune={rune} />); | ||
} |
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
File renamed without changes.
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,11 @@ | ||
import type { RuneToken } from '@app/query/bitcoin/bitcoin-client'; | ||
import { useRuneTokens } from '@app/query/bitcoin/runes/runes.hooks'; | ||
|
||
interface RunesLoaderProps { | ||
address: string; | ||
children(runes: RuneToken[]): React.ReactNode; | ||
} | ||
export function RunesLoader({ address, children }: RunesLoaderProps) { | ||
const { data: runes = [] } = useRuneTokens(address); | ||
return children(runes); | ||
} |
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
19 changes: 14 additions & 5 deletions
19
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,20 +1,29 @@ | ||
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 { RunesAssetList } from '@app/components/crypto-assets/bitcoin/runes-asset-list/runes-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'; | ||
import { Brc20TokensLoader } from '@app/components/loaders/brc20-tokens-loader'; | ||
import { RunesLoader } from '@app/components/loaders/runes-loader'; | ||
import { Src20TokensLoader } from '@app/components/loaders/src20-tokens-loader'; | ||
|
||
interface BitcoinFungibleTokenAssetListProps { | ||
btcAddress: string; | ||
btcAddressNativeSegwit: string; | ||
btcAddressTaproot: string; | ||
} | ||
export function BitcoinFungibleTokenAssetList({ btcAddress }: BitcoinFungibleTokenAssetListProps) { | ||
export function BitcoinFungibleTokenAssetList({ | ||
btcAddressNativeSegwit, | ||
btcAddressTaproot, | ||
}: BitcoinFungibleTokenAssetListProps) { | ||
return ( | ||
<> | ||
<Brc20TokensLoader> | ||
{brc20Tokens => <Brc20TokenAssetList brc20Tokens={brc20Tokens} />} | ||
</Brc20TokensLoader> | ||
<Src20TokensLoader address={btcAddress}> | ||
<Src20TokensLoader address={btcAddressNativeSegwit}> | ||
{src20Tokens => <Src20TokenAssetList src20Tokens={src20Tokens} />} | ||
</Src20TokensLoader> | ||
<RunesLoader address={btcAddressTaproot}> | ||
{runes => <RunesAssetList runes={runes} />} | ||
</RunesLoader> | ||
</> | ||
); | ||
} |
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
17 changes: 13 additions & 4 deletions
17
src/app/query/bitcoin/runes/runes-wallet-balances.query.ts
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,16 +1,25 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { useConfigRunesEnabled } from '@app/query/common/remote-config/remote-config.query'; | ||
import type { AppUseQueryConfig } from '@app/query/query-config'; | ||
import { useBitcoinClient } from '@app/store/common/api-clients.hooks'; | ||
import { useCurrentNetwork } from '@app/store/networks/networks.selectors'; | ||
|
||
// ts-unused-exports:disable-next-line | ||
export function useGetRunesWalletBalancesQuery(address: string) { | ||
import type { RuneBalance } from '../bitcoin-client'; | ||
|
||
export function useGetRunesWalletBalancesQuery<T extends unknown = RuneBalance[]>( | ||
address: string, | ||
options?: AppUseQueryConfig<RuneBalance[], T> | ||
) { | ||
const client = useBitcoinClient(); | ||
const network = useCurrentNetwork(); | ||
const runesEnabled = useConfigRunesEnabled(); | ||
|
||
return useQuery({ | ||
enabled: !!(address && network.chain.bitcoin.bitcoinNetwork === 'testnet'), | ||
enabled: !!address && (network.chain.bitcoin.bitcoinNetwork === 'testnet' || runesEnabled), | ||
queryKey: ['runes-wallet-balances', address], | ||
queryFn: () => client.BestinslotApi.getRunesWalletBalances(address), | ||
queryFn: () => | ||
client.BestinslotApi.getRunesWalletBalances(address, network.chain.bitcoin.bitcoinNetwork), | ||
...options, | ||
}); | ||
} |
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 { createMoney } from '@shared/models/money.model'; | ||
|
||
import type { RuneToken } from '../bitcoin-client'; | ||
import { useGetRunesWalletBalancesQuery } from './runes-wallet-balances.query'; | ||
|
||
export function useRuneTokens(address: string) { | ||
return useGetRunesWalletBalancesQuery(address, { | ||
select: resp => | ||
resp.map(rune => { | ||
return { | ||
...rune, | ||
balance: createMoney(Number(rune.total_balance), rune.rune_name, 0), | ||
} as RuneToken; | ||
}), | ||
}); | ||
} |
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,33 @@ | ||
import { Avatar, type AvatarProps } from './avatar'; | ||
|
||
export function RunesAvatarIcon(props: AvatarProps) { | ||
return ( | ||
<Avatar.Root {...props}> | ||
<Avatar.Svg> | ||
<circle cx="16" cy="16" r="16" fill="black" /> | ||
<circle cx="16" cy="16" r="15.5" stroke="#B1977B" strokeOpacity="0.1" /> | ||
<g clipPath="url(#clip0_15326_75304)"> | ||
<rect width="18" height="17.1" transform="translate(7 7.94995)" fill="black" /> | ||
<path d="M8.61722 5.97876L23.3818 26.8953" stroke="white" strokeWidth="2.25" /> | ||
<path d="M23.3823 5.97876L8.61768 26.8953" stroke="white" strokeWidth="2.25" /> | ||
<path d="M15.9998 7.82446L15.9998 25.0499" stroke="white" strokeWidth="1.75" /> | ||
<path | ||
d="M20.0137 10.7512L22.8552 16.4273L20.0656 22.1859" | ||
stroke="white" | ||
strokeWidth="1.75" | ||
/> | ||
<path | ||
d="M11.999 10.7512L9.15748 16.4273L11.9471 22.1859" | ||
stroke="white" | ||
strokeWidth="1.75" | ||
/> | ||
</g> | ||
<defs> | ||
<clipPath id="clip0_15326_75304"> | ||
<rect width="18" height="17.1" fill="white" transform="translate(7 7.94995)" /> | ||
</clipPath> | ||
</defs> | ||
</Avatar.Svg> | ||
</Avatar.Root> | ||
); | ||
} |