-
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: stacks ft fiat values from alex-sdk
- Loading branch information
Showing
19 changed files
with
120 additions
and
95 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
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
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
5 changes: 2 additions & 3 deletions
5
src/app/pages/swap/components/swap-choose-asset/components/swap-asset-item.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
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
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,36 @@ | ||
import { useCallback, useState } from 'react'; | ||
|
||
import { AlexSDK, type Currency } from 'alex-sdk'; | ||
import BigNumber from 'bignumber.js'; | ||
|
||
import { logger } from '@shared/logger'; | ||
import { createMoney } from '@shared/models/money.model'; | ||
import { isDefined } from '@shared/utils'; | ||
|
||
import { convertAmountToFractionalUnit } from '@app/common/money/calculate-money'; | ||
import { pullContractIdFromIdentity } from '@app/common/utils'; | ||
|
||
import { useAlexSdkLatestPricesQuery } from './latest-prices.query'; | ||
import { useAlexSdkSwappableCurrencyQuery } from './swappable-currency.query'; | ||
|
||
export function useAlexSdKCurrencyPriceAsMoney() { | ||
const alexSDK = useState(() => new AlexSDK())[0]; | ||
const { data: supportedCurrencies = [] } = useAlexSdkSwappableCurrencyQuery(alexSDK); | ||
const { data: prices } = useAlexSdkLatestPricesQuery(alexSDK); | ||
|
||
return useCallback( | ||
(principal: string) => { | ||
if (!prices) { | ||
logger.error('Latest prices could not be found'); | ||
return createMoney(0, 'USD'); | ||
} | ||
const tokenInfo = supportedCurrencies | ||
.filter(isDefined) | ||
.find(token => pullContractIdFromIdentity(token.contractAddress) === principal); | ||
const currency = tokenInfo?.id as Currency; | ||
const price = convertAmountToFractionalUnit(new BigNumber(prices[currency] ?? 0), 2); | ||
return createMoney(price, 'USD'); | ||
}, | ||
[prices, supportedCurrencies] | ||
); | ||
} |
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,12 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { AlexSDK } from 'alex-sdk'; | ||
|
||
export function useAlexSdkLatestPricesQuery(alexSDK: AlexSDK) { | ||
return useQuery(['alex-sdk-latest-prices'], async () => alexSDK.getLatestPrices(), { | ||
refetchOnMount: false, | ||
refetchOnReconnect: false, | ||
refetchOnWindowFocus: false, | ||
retryDelay: 1000 * 60, | ||
staleTime: 1000 * 60 * 10, | ||
}); | ||
} |
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,12 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { AlexSDK } from 'alex-sdk'; | ||
|
||
export function useAlexSdkSwappableCurrencyQuery(alexSDK: AlexSDK) { | ||
return useQuery(['alex-sdk-swappable-currencies'], async () => alexSDK.fetchSwappableCurrency(), { | ||
refetchOnMount: false, | ||
refetchOnReconnect: false, | ||
refetchOnWindowFocus: false, | ||
retryDelay: 1000 * 60, | ||
staleTime: 1000 * 60 * 10, | ||
}); | ||
} |
16 changes: 0 additions & 16 deletions
16
src/app/query/common/alex-swaps/swappable-currency.query.ts
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.