-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add new currencies * add new flags and standardize to iso flag code * use latest core * use hook * rename useCoinRates * use latest core * use correct core
- Loading branch information
Showing
59 changed files
with
794 additions
and
104 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
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
31 changes: 12 additions & 19 deletions
31
src/app/hooks/queries/useCoinRates.ts → ...pp/hooks/queries/useSupportedCoinRates.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,50 +1,43 @@ | ||
import useXverseApi from '@hooks/apiClients/useXverseApi'; | ||
import useWalletSelector from '@hooks/useWalletSelector'; | ||
import { | ||
fetchBtcToCurrencyRate, | ||
fetchStxToBtcRate, | ||
type NetworkType, | ||
type SupportedCurrency, | ||
} from '@secretkeylabs/xverse-core'; | ||
import { type SupportedCurrency } from '@secretkeylabs/xverse-core'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
const useGetRates = (fiatCurrency: SupportedCurrency, networkType: NetworkType) => { | ||
const useGetSupportedRates = (fiatCurrency: SupportedCurrency) => { | ||
const xverseApi = useXverseApi(); | ||
const fetchCoinRates = async () => { | ||
try { | ||
const btcFiatRate = await fetchBtcToCurrencyRate(networkType, { | ||
const btcFiatRate = await xverseApi.fetchBtcToCurrencyRate({ | ||
fiatCurrency, | ||
}); | ||
|
||
const btcUsdRate = | ||
fiatCurrency === 'USD' | ||
? btcFiatRate | ||
: await fetchBtcToCurrencyRate(networkType, { | ||
: await xverseApi.fetchBtcToCurrencyRate({ | ||
fiatCurrency: 'USD' as SupportedCurrency, | ||
}); | ||
|
||
const stxBtcRate = await fetchStxToBtcRate(networkType); | ||
const stxBtcRate = await xverseApi.fetchStxToBtcRate(); | ||
return { stxBtcRate, btcFiatRate, btcUsdRate }; | ||
} catch (e: any) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
|
||
return useQuery({ | ||
queryKey: ['coin_rates', fiatCurrency, networkType], | ||
queryKey: ['coin_rates', fiatCurrency], | ||
queryFn: fetchCoinRates, | ||
staleTime: 5 * 60 * 1000, // 5 min | ||
}); | ||
}; | ||
|
||
const useCoinRates = () => { | ||
const { fiatCurrency, network } = useWalletSelector(); | ||
|
||
const { data } = useGetRates(fiatCurrency, network.type); | ||
|
||
const useSupportedCoinRates = () => { | ||
const { fiatCurrency } = useWalletSelector(); | ||
const { data } = useGetSupportedRates(fiatCurrency); | ||
const stxBtcRate = data?.stxBtcRate.toString() || '0'; | ||
const btcFiatRate = data?.btcFiatRate.toString() || '0'; | ||
const btcUsdRate = data?.btcUsdRate?.toString() || '0'; | ||
|
||
return { stxBtcRate, btcFiatRate, btcUsdRate }; | ||
}; | ||
|
||
export default useCoinRates; | ||
export default useSupportedCoinRates; |
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
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.