import { Env } from '@lombard.finance/sdk-common'; import type { Meta, StoryObj } from '@storybook/react'; import { envToNetwork, getConfig } from '../../const/getConfig'; import { Button, CodeBlock, ErrorDisplay } from '../../stories/components'; import { functionType } from '../../stories/decorators/function-type'; import useQuery from '../../stories/hooks/useQuery'; import { getMinRedeemAmountSolana, getMinRedeemAmountWithFeeSolana, getMintingFeeSolana, getRedeemFeeSolana, getTokenFeeConfig, } from './getTokenFeeConfig'; type TokenChoice = 'LBTC' | 'BTC.b'; interface StoryArgs { environment: Env; token: TokenChoice; } function resolveTokenMint(token: TokenChoice, env: Env): string | undefined { const config = getConfig(env); return token === 'LBTC' ? config.lbtcTokenMint : (config.btcbTokenMint ?? undefined); } export function StoryView({ environment, token }: StoryArgs) { const network = envToNetwork[environment]; const tokenMint = resolveTokenMint(token, environment); const params = { network, env: environment, tokenMint }; const configQuery = useQuery( () => getTokenFeeConfig(params), [environment, token], false, ); const redeemFeeQuery = useQuery( () => getRedeemFeeSolana(params), [environment, token], false, ); const mintingFeeQuery = useQuery( () => getMintingFeeSolana(params), [environment, token], false, ); const minRedeemQuery = useQuery( () => getMinRedeemAmountSolana(params), [environment, token], false, ); const minRedeemWithFeeQuery = useQuery( () => getMinRedeemAmountWithFeeSolana(params), [environment, token], false, ); const isLoading = configQuery.isLoading || redeemFeeQuery.isLoading || mintingFeeQuery.isLoading || minRedeemQuery.isLoading || minRedeemWithFeeQuery.isLoading; const fetchAll = () => { configQuery.refetch(); redeemFeeQuery.refetch(); mintingFeeQuery.refetch(); minRedeemQuery.refetch(); minRedeemWithFeeQuery.refetch(); }; const error = configQuery.error || redeemFeeQuery.error || mintingFeeQuery.error || minRedeemQuery.error || minRedeemWithFeeQuery.error; const summary = configQuery.data ? { redeemFee: configQuery.data.redeemFee.toFormat(), redeemForBtcMinAmount: configQuery.data.redeemForBtcMinAmount.toFormat(), maxMintCommission: configQuery.data.maxMintCommission.toFormat(), toNativeCommission: configQuery.data.toNativeCommission.toFormat(), 'getRedeemFeeSolana (toNative + redeem)': redeemFeeQuery.data?.toFormat(), getMintingFeeSolana: mintingFeeQuery.data?.toFormat(), getMinRedeemAmountSolana: minRedeemQuery.data?.toFormat(), getMinRedeemAmountWithFeeSolana: minRedeemWithFeeQuery.data?.toFormat(), } : undefined; return (
Network: {network} | Token: {token} {tokenMint ? ` (${tokenMint})` : ' — not configured'}
{summary &&