-
Notifications
You must be signed in to change notification settings - Fork 147
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
7 changed files
with
91 additions
and
17 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
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,15 +1,20 @@ | ||
import { isDefined } from '@shared/utils'; | ||
|
||
import type { RuneToken } from '@app/query/bitcoin/bitcoin-client'; | ||
import { useGetRunesWalletBalancesByAddressesQuery } from '@app/query/bitcoin/runes/runes-wallet-balances.query'; | ||
import { useRuneTokens } from '@app/query/bitcoin/runes/runes.hooks'; | ||
|
||
interface RunesLoaderProps { | ||
addresses: string[]; | ||
children(runes: RuneToken[]): React.ReactNode; | ||
} | ||
export function RunesLoader({ addresses, children }: RunesLoaderProps) { | ||
const runes = useRuneTokens(addresses) | ||
const runesBalances = useGetRunesWalletBalancesByAddressesQuery(addresses) | ||
.flatMap(query => query.data) | ||
.filter(isDefined); | ||
return children(runes); | ||
const runesWithTickerInfo = runesBalances | ||
.map(balance => useRuneTokens(balance, balance.rune_name)) | ||
.flatMap(query => query.data) | ||
.filter(isDefined); | ||
return children(runesWithTickerInfo); | ||
} |
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,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'; | ||
|
||
import type { RuneTickerInfo } from '../bitcoin-client'; | ||
|
||
export function useGetRunesTickerInfoQuery<T extends unknown = RuneTickerInfo>( | ||
runeName: string, | ||
options?: AppUseQueryConfig<RuneTickerInfo, T> | ||
) { | ||
const client = useBitcoinClient(); | ||
const network = useCurrentNetwork(); | ||
const runesEnabled = useConfigRunesEnabled(); | ||
|
||
return useQuery({ | ||
enabled: network.chain.bitcoin.bitcoinNetwork === 'testnet' || runesEnabled, | ||
queryKey: ['runes-ticker-info', runeName], | ||
queryFn: () => | ||
client.BestinslotApi.getRunesTickerInfo(runeName, 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 |
---|---|---|
@@ -1,17 +1,22 @@ | ||
import { createMoney } from '@shared/models/money.model'; | ||
|
||
import type { RuneBalance, RuneToken } from '../bitcoin-client'; | ||
import { useGetRunesWalletBalancesByAddressesQuery } from './runes-wallet-balances.query'; | ||
import type { RuneBalance, RuneTickerInfo, RuneToken } from '../bitcoin-client'; | ||
import { useGetRunesTickerInfoQuery } from './runes-ticker-info.query'; | ||
|
||
function makeRuneToken(rune: RuneBalance): RuneToken { | ||
function makeRuneToken(runeBalance: RuneBalance, tickerInfo: RuneTickerInfo): RuneToken { | ||
return { | ||
...rune, | ||
balance: createMoney(Number(rune.total_balance), rune.rune_name, 0), | ||
...runeBalance, | ||
...tickerInfo, | ||
balance: createMoney( | ||
Number(runeBalance.total_balance), | ||
tickerInfo.rune_name, | ||
tickerInfo.decimals | ||
), | ||
}; | ||
} | ||
|
||
export function useRuneTokens(addresses: string[]) { | ||
return useGetRunesWalletBalancesByAddressesQuery(addresses, { | ||
select: resp => resp.map(makeRuneToken), | ||
export function useRuneTokens(runeBalance: RuneBalance, runeName: string) { | ||
return useGetRunesTickerInfoQuery(runeName, { | ||
select: resp => makeRuneToken(runeBalance, resp), | ||
}); | ||
} |
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