From af4bb99a40b6648aa24518e2771a83b8d5bbf90d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 20 Nov 2024 11:53:52 +0400 Subject: [PATCH] feat: WIP kado plugin updates --- packages/plugins/kado/src/plugin.ts | 336 ++++++++++++------ packages/plugins/radix/src/index.ts | 2 +- packages/plugins/thorchain/src/tcPlugin.ts | 3 +- packages/swapkit/core/src/client.ts | 19 +- packages/swapkit/helpers/src/types/chains.ts | 9 +- .../swapkit/helpers/src/types/commonTypes.ts | 4 +- .../helpers/src/types/derivationPath.ts | 3 +- packages/swapkit/helpers/src/types/wallet.ts | 8 +- packages/wallets/ledger/src/ledgerLive.ts | 7 +- playgrounds/vite/src/App.tsx | 14 +- playgrounds/vite/src/Send/index.tsx | 18 +- playgrounds/vite/src/Swap/SwapInputs.tsx | 6 +- playgrounds/vite/src/Wallet.tsx | 4 +- 13 files changed, 285 insertions(+), 148 deletions(-) diff --git a/packages/plugins/kado/src/plugin.ts b/packages/plugins/kado/src/plugin.ts index 923221a40..86a544863 100644 --- a/packages/plugins/kado/src/plugin.ts +++ b/packages/plugins/kado/src/plugin.ts @@ -1,121 +1,242 @@ import { type AssetValue, - type Chain, + Chain, ProviderName, RequestClient, type SwapKitPluginParams, } from "@swapkit/helpers"; import { ChainToKadoChain } from "./helpers"; -type KadoQuoteRequest = { +export type KadoFiatCurrency = + | "USD" + | "CAD" + | "GBP" + | "EUR" + | "MXN" + | "COP" + | "INR" + | "CHF" + | "AUD" + | "ARS" + | "BRL" + | "CLP" + | "JPY" + | "KRW" + | "PEN" + | "PHP" + | "SGD" + | "TRY" + | "UYU" + | "TWD" + | "VND" + | "CRC" + | "SEK" + | "PLN" + | "DKK" + | "NOK" + | "NZD"; + +export type KadoFiatMethod = + | "ach" + | "debit_card" + | "credit_card" + | "apple_pay_credit" + | "apple_pay_debit" + | "wire" + | "sepa" + | "pix" + | "koywe"; + +export type KadoQuoteRequest = { transactionType: "buy" | "sell"; - fiatMethod: - | "ach" - | "debit_card" - | "credit_card" - | "apple_pay_credit" - | "apple_pay_debit" - | "wire" - | "sepa" - | "pix" - | "koywe"; + fiatMethod: KadoFiatMethod; partner: "fortress"; amount: string; asset: string; blockchain: string; - currency: - | "USD" - | "CAD" - | "GBP" - | "EUR" - | "MXN" - | "COP" - | "INR" - | "CHF" - | "AUD" - | "ARS" - | "BRL" - | "CLP" - | "JPY" - | "KRW" - | "PEN" - | "PHP" - | "SGD" - | "TRY" - | "UYU" - | "TWD" - | "VND" - | "CRC" - | "SEK" - | "PLN" - | "DKK" - | "NOK" - | "NZD"; + currency: KadoFiatCurrency; }; -function plugin({ - getWallet, - config: { kadoApiKey }, -}: SwapKitPluginParams<{ kadoApiKey: string }>) { - async function onRampQuote(assetValue: AssetValue, fiatCurrency: KadoQuoteRequest["currency"]) { - const blockchain = ChainToKadoChain(assetValue.chain); - if (!blockchain) { - throw new Error(`Asset chain ${assetValue.chain} not supported by Kado`); - } - debugger; - try { - const quoteRequest: KadoQuoteRequest = { - transactionType: "buy", - fiatMethod: "sepa", // Default to SEPA, can be made configurable - partner: "fortress", - amount: assetValue.getValue("string"), - asset: assetValue.symbol, - blockchain, - currency: fiatCurrency, +export type KadoBlockchainsResponse = { + success: boolean; + message: string; + data: { + blockchains: { + _id: string; + supportedEnvironment: string; + network: string; + origin: string; + label: string; + associatedAssets: { + _id: string; + name: string; + description: string; + label: string; + supportedProviders: string[]; + stablecoin: boolean; + liveOnRamp: boolean; + createdAt: string; + updatedAt: string; + __v: number; + priority: number; }; + avgTransactionTimeSeconds: number; + usesAvaxRouter: boolean; + liveOnRamp: boolean; + createdAt: string; + updatedAt: string; + __v: number; + priority: number; + }[]; + }; +}; - const quote = await RequestClient.get<{ - success: boolean; - message: string; - data: { - quote: { - receiveAmount: number; - networkFee: number; - processingFee: number; - totalFee: number; - }; - }; - }>("https://api.kado.money/v2/ramp/quote", { - searchParams: quoteRequest, - headers: { - "X-Widget-Id": kadoApiKey, - }, - }); +export type KadoSupportedAssetsResponse = { + success: boolean; + message: string; + data: { + assets: { + _id: string; + name: string; + description: string; + label: string; + symbol: string; + supportedProviders: string[]; + stablecoin: boolean; + liveOnRamp: boolean; + createdAt: string; + updatedAt: string; + __v: number; + priority: number; + }[]; + }; +}; - if (!quote.success) { - throw new Error(quote.message); - } +function plugin({ config: { kadoApiKey } }: SwapKitPluginParams<{ kadoApiKey: string }>) { + // async function onRampQuote( + // assetValue: AssetValue, + // fiatCurrency: KadoFiatCurrency, + // fiatMethod: KadoFiatMethod, + // ) { + // const blockchain = ChainToKadoChain(assetValue.chain); + // if (!blockchain) { + // throw new Error(`Asset chain ${assetValue.chain} not supported by Kado`); + // } - return quote.data.quote; - } catch (error) { - throw new Error("core_swap_quote_error"); - } - } + // try { + // const quoteRequest: KadoQuoteRequest = { + // transactionType: "buy", + // fiatMethod, // Default to SEPA, can be made configurable + // partner: "fortress", + // amount: assetValue.getValue("string"), + // asset: assetValue.symbol, + // blockchain, + // currency: fiatCurrency, + // }; - async function offRampQuote(assetValue: AssetValue, fiatCurrency: KadoQuoteRequest["currency"]) { - const blockchain = ChainToKadoChain(assetValue.chain); - if (!blockchain) { - throw new Error("asset chain not supported"); - } + // const quote = await RequestClient.get<{ + // success: boolean; + // message: string; + // data: { + // quote: { + // receiveAmount: number; + // networkFee: number; + // processingFee: number; + // totalFee: number; + // }; + // }; + // }>("https://api.kado.money/v2/ramp/quote", { + // searchParams: quoteRequest, + // headers: { + // "X-Widget-Id": kadoApiKey, + // }, + // }); + + // if (!quote.success) { + // throw new Error(quote.message); + // } + + // return quote.data.quote; + // } catch (error) { + // throw new Error("core_swap_quote_error"); + // } + // } + + // async function offRampQuote( + // sellAsset: AssetValue, + // buyAsset: AssetValue, + // fiatCurrency: KadoFiatCurrency, + // fiatMethod: KadoFiatMethod, + // ) { + // const blockchain = ChainToKadoChain(assetValue.chain); + // if (!blockchain) { + // throw new Error("asset chain not supported"); + // } + // try { + // const quoteRequest: KadoQuoteRequest = { + // transactionType: "sell", + // fiatMethod: "sepa", // Default to SEPA, can be made configurable + // partner: "fortress", + // amount: assetValue.getValue("string"), + // asset: assetValue.symbol, + // blockchain, + // currency: fiatCurrency, + // }; + + // const quote = await RequestClient.get<{ + // success: boolean; + // message: string; + // data: { + // quote: { + // receiveAmount: number; + // networkFee: number; + // processingFee: number; + // totalFee: number; + // }; + // }; + // }>("https://api.kado.money/v2/ramp/quote", { + // json: quoteRequest, + // headers: { + // "X-Widget-Id": kadoApiKey, + // }, + // }); + + // if (!quote.success) { + // throw new Error(quote.message); + // } + + // return quote.data.quote; + // } catch (error) { + // throw new Error("core_swap_quote_error"); + // } + // } + + async function fetchProviderQuote({ + sellAsset, + buyAsset, + fiatMethod, + }: { + sellAsset: AssetValue; + buyAsset: AssetValue; + fiatMethod: KadoFiatMethod; + }) { try { + const transactionType = sellAsset.chain === Chain.Fiat ? "sell" : "buy"; + + const currency = ( + sellAsset.chain === Chain.Fiat ? sellAsset.symbol : buyAsset.symbol + ) as KadoFiatCurrency; + + const asset = sellAsset.chain === Chain.Fiat ? buyAsset : sellAsset; + const quoteRequest: KadoQuoteRequest = { - transactionType: "sell", - fiatMethod: "sepa", // Default to SEPA, can be made configurable + transactionType, + fiatMethod, partner: "fortress", - amount: assetValue.getBaseValue("number"), - asset: assetValue.symbol, - blockchain, - currency: fiatCurrency, + amount: buyAsset.getValue("string"), + asset: asset.symbol, + blockchain: asset.chain, + currency, }; const quote = await RequestClient.get<{ @@ -141,7 +262,7 @@ function plugin({ } return quote.data.quote; - } catch (error) { + } catch (_) { throw new Error("core_swap_quote_error"); } } @@ -239,14 +360,14 @@ function plugin({ } return response.data.order; - } catch (error) { + } catch (_error) { throw new Error("Failed to get order status"); } } function getKadoWidgetUrl({ - sellAssetValue, - buyAssetValue, + sellAsset, + buyAsset, supportedAssets, recipient, networkList, @@ -254,8 +375,8 @@ function plugin({ typeList, widgetMode, }: { - sellAssetValue: AssetValue; - buyAssetValue: AssetValue; + sellAsset: AssetValue; + buyAsset: AssetValue; supportedAssets: AssetValue[]; recipient: string; networkList: Chain[]; @@ -264,12 +385,12 @@ function plugin({ widgetMode: "minimal" | "full"; }) { const urlParams = new URLSearchParams({ - onPayAmount: sellAssetValue.getValue("string"), - onPayCurrency: sellAssetValue.symbol, - onRevCurrency: buyAssetValue.symbol, + onPayAmount: sellAsset.getValue("string"), + onPayCurrency: sellAsset.symbol, + onRevCurrency: buyAsset.symbol, cryptoList: supportedAssets.map((asset) => asset.symbol).join(","), onToAddress: recipient, - network: ChainToKadoChain(buyAssetValue.chain).toUpperCase(), + network: ChainToKadoChain(buyAsset.chain).toUpperCase(), networkList: networkList.map((chain) => ChainToKadoChain(chain).toUpperCase()).join(","), product: type, productList: typeList, @@ -280,8 +401,9 @@ function plugin({ } return { - onRampQuote, - offRampQuote, + // onRampQuote, + // offRampQuote, + fetchProviderQuote, getBlockchains, getAssets, getOrderStatus, diff --git a/packages/plugins/radix/src/index.ts b/packages/plugins/radix/src/index.ts index 501ea15c6..9c48291c4 100644 --- a/packages/plugins/radix/src/index.ts +++ b/packages/plugins/radix/src/index.ts @@ -29,7 +29,7 @@ function plugin({ getWallet }: SwapKitPluginParams) { // await convertInstructionsToManifest({ network: RadixMainnet })( // route.transaction as Instructions, // ) - // ).value as string; + // ).value as string;c return wallet.signAndBroadcast({ manifest: route.transaction as string, }); diff --git a/packages/plugins/thorchain/src/tcPlugin.ts b/packages/plugins/thorchain/src/tcPlugin.ts index c3dd2e96b..1e04407d1 100644 --- a/packages/plugins/thorchain/src/tcPlugin.ts +++ b/packages/plugins/thorchain/src/tcPlugin.ts @@ -20,6 +20,7 @@ import { TCBscDepositABI, TCEthereumVaultAbi, type UTXOChain, + type WalletChain, getMemoForLoan, lowercasedContractAbiMapping, } from "@swapkit/helpers"; @@ -158,7 +159,7 @@ function plugin({ getWallet, stagenet = false }: SwapKitPluginParams) { getMemoForLoan(type === "open" ? MemoType.OPEN_LOAN : MemoType.CLOSE_LOAN, { asset: assetValue.toString(), minAmount: minAmount.toString(), - address: getWallet(assetValue.chain).address, + address: getWallet(assetValue.chain as WalletChain).address, }), }); } diff --git a/packages/swapkit/core/src/client.ts b/packages/swapkit/core/src/client.ts index 4f9a893d5..b2f477e57 100644 --- a/packages/swapkit/core/src/client.ts +++ b/packages/swapkit/core/src/client.ts @@ -104,7 +104,7 @@ export function SwapKit< return plugin; } - function addChain(connectWallet: ChainWallet) { + function addChain(connectWallet: ChainWallet) { const currentWallet = getWallet(connectWallet.chain); connectedWallets[connectWallet.chain] = { ...currentWallet, ...connectWallet }; @@ -163,7 +163,7 @@ export function SwapKit< /** * @Public */ - function getWallet(chain: T) { + function getWallet(chain: T) { return connectedWallets[chain]; } @@ -171,7 +171,7 @@ export function SwapKit< return { ...connectedWallets }; } - function getAddress(chain: T) { + function getAddress(chain: T) { return getWallet(chain)?.address || ""; } @@ -183,7 +183,7 @@ export function SwapKit< return approve({ assetValue, contractAddress, type: ApproveMode.CheckOnly }); } - function disconnectChain(chain: T) { + function disconnectChain(chain: T) { const wallet = getWallet(chain); wallet?.disconnect?.(); delete connectedWallets[chain]; @@ -195,7 +195,7 @@ export function SwapKit< } } - function getBalance( + function getBalance( chain: T, refresh?: R, ): ConditionalAssetValueReturn { @@ -216,7 +216,7 @@ export function SwapKit< }); } - async function getWalletWithBalance(chain: T, potentialScamFilter = true) { + async function getWalletWithBalance(chain: T, potentialScamFilter = true) { const defaultBalance = [AssetValue.from({ chain })]; const wallet = getWallet(chain); @@ -254,14 +254,14 @@ export function SwapKit< assetValue, ...params }: UTXOTransferParams | EVMTransferParams | CosmosTransferParams) { - const chain = assetValue.chain as WalletChain; + const chain = assetValue.chain as Exclude; const wallet = getWallet(chain); if (!wallet) throw new SwapKitError("core_wallet_connection_not_found"); return wallet.transfer({ ...params, assetValue }); } - function signMessage({ chain, message }: { chain: Chain; message: string }) { + function signMessage({ chain, message }: { chain: WalletChain; message: string }) { const wallet = getWallet(chain); if (!wallet) throw new SwapKitError("core_wallet_connection_not_found"); @@ -315,7 +315,8 @@ export function SwapKit< const { assetValue } = params; const { chain } = assetValue; - if (!getWallet(chain)) throw new SwapKitError("core_wallet_connection_not_found"); + if (!getWallet(chain as WalletChain)) + throw new SwapKitError("core_wallet_connection_not_found"); const baseValue = AssetValue.from({ chain }); diff --git a/packages/swapkit/helpers/src/types/chains.ts b/packages/swapkit/helpers/src/types/chains.ts index 58c8e17d6..8d9ba901f 100644 --- a/packages/swapkit/helpers/src/types/chains.ts +++ b/packages/swapkit/helpers/src/types/chains.ts @@ -9,6 +9,7 @@ export enum Chain { Dash = "DASH", Dogecoin = "DOGE", Ethereum = "ETH", + Fiat = "FIAT", Kujira = "KUJI", Litecoin = "LTC", Maya = "MAYA", @@ -26,7 +27,7 @@ export enum StagenetChain { Maya = "MAYA_STAGENET", } -export type WalletChain = Exclude; +export type WalletChain = Exclude; export enum ChainId { Arbitrum = "42161", @@ -46,6 +47,7 @@ export enum ChainId { Kujira = "kaiyo-1", Ethereum = "1", EthereumHex = "0x1", + Fiat = "fiat", Litecoin = "litecoin", Maya = "mayachain-mainnet-v1", MayaStagenet = "mayachain-stagenet-v1", @@ -76,6 +78,7 @@ export const ChainIdToChain: Record = { [ChainId.Dash]: Chain.Dash, [ChainId.Dogecoin]: Chain.Dogecoin, [ChainId.EthereumHex]: Chain.Ethereum, + [ChainId.Fiat]: Chain.Fiat, [ChainId.Kujira]: Chain.Kujira, [ChainId.Ethereum]: Chain.Ethereum, [ChainId.Litecoin]: Chain.Litecoin, @@ -107,6 +110,7 @@ export const BaseDecimal: Record = { DOGE: 8, DOT: 10, ETH: 18, + FIAT: 2, FLIP: 18, GAIA: 6, KUJI: 6, @@ -190,6 +194,7 @@ export const RPC_URLS: Record = { [Chain.Dash]: "https://dash-rpc.publicnode.com", [Chain.Dogecoin]: "https://node-router.thorswap.net/dogecoin", [Chain.Ethereum]: "https://ethereum-rpc.publicnode.com", + [Chain.Fiat]: "", [Chain.Kujira]: "https://rpc-kujira.synergynodes.com/", [Chain.Litecoin]: "https://node-router.thorswap.net/litecoin", [Chain.Maya]: "https://tendermint.mayachain.info", @@ -227,6 +232,7 @@ export const FALLBACK_URLS: Record = { [Chain.Dash]: ["https://dash-rpc.publicnode.com"], [Chain.Dogecoin]: ["https://doge.getblock.io/mainnet", "https://dogecoin.publicnode.com"], [Chain.Ethereum]: ["https://eth.llamarpc.com", "https://rpc.ankr.com/eth"], + [Chain.Fiat]: [], [Chain.Kujira]: ["https://kujira-rpc.polkachu.com", "https://kujira-rpc.ibs.team"], [Chain.Litecoin]: ["https://ltc.getblock.io/mainnet", "https://litecoin.publicnode.com"], [Chain.Maya]: ["https://tendermint.mayachain.info", "https://maya-tendermint.publicnode.com"], @@ -255,6 +261,7 @@ export const EXPLORER_URLS: Record = { [Chain.Dash]: "https://blockchair.com/dash", [Chain.Dogecoin]: "https://blockchair.com/dogecoin", [Chain.Ethereum]: "https://etherscan.io", + [Chain.Fiat]: "", [Chain.Kujira]: "https://finder.kujira.network/kaiyo-1", [Chain.Litecoin]: "https://blockchair.com/litecoin", [Chain.Maya]: "https://www.mayascan.org", diff --git a/packages/swapkit/helpers/src/types/commonTypes.ts b/packages/swapkit/helpers/src/types/commonTypes.ts index 2a180647b..575f6a742 100644 --- a/packages/swapkit/helpers/src/types/commonTypes.ts +++ b/packages/swapkit/helpers/src/types/commonTypes.ts @@ -1,5 +1,5 @@ import type { RadixNetwork } from "@swapkit/toolbox-radix"; -import type { Chain } from "./chains"; +import type { Chain, WalletChain } from "./chains"; import type { ChainApis } from "./sdk"; import type { ChainWallet } from "./wallet"; @@ -77,7 +77,7 @@ export type ConnectConfig = { }; export type ConnectWalletParams = { - addChain: (params: ChainWallet & M) => void; + addChain: (params: ChainWallet & M) => void; apis: ChainApis; config: ConnectConfig; rpcUrls: { [chain in Chain]?: string }; diff --git a/packages/swapkit/helpers/src/types/derivationPath.ts b/packages/swapkit/helpers/src/types/derivationPath.ts index 19f1ae2b4..4b8942f17 100644 --- a/packages/swapkit/helpers/src/types/derivationPath.ts +++ b/packages/swapkit/helpers/src/types/derivationPath.ts @@ -55,7 +55,8 @@ export const NetworkDerivationPath: Record = { THOR: [44, 931, 0, 0, 0], // Polkadot and related network derivation path is not number based - XRD: [0, 0, 0, 0, 0], DOT: [0, 0, 0, 0, 0], + FIAT: [0, 0, 0, 0, 0], FLIP: [0, 0, 0, 0, 0], + XRD: [0, 0, 0, 0, 0], }; diff --git a/packages/swapkit/helpers/src/types/wallet.ts b/packages/swapkit/helpers/src/types/wallet.ts index 6f68f6a3a..04fa797e4 100644 --- a/packages/swapkit/helpers/src/types/wallet.ts +++ b/packages/swapkit/helpers/src/types/wallet.ts @@ -7,7 +7,7 @@ import type { UTXOWallets } from "@swapkit/toolbox-utxo"; import type { Eip1193Provider } from "ethers"; import type { AssetValue } from "../modules/assetValue"; -import type { Chain } from "./chains"; +import type { Chain, WalletChain } from "./chains"; import type { ConnectWalletParams } from "./commonTypes"; declare global { @@ -66,9 +66,9 @@ export type ChainWallet = { signMessage?: (message: string) => Promise; }; -export type EmptyWallet = { [key in Chain]?: unknown }; +export type EmptyWallet = { [key in WalletChain]?: unknown }; export type BaseWallet> = { - [key in Chain]: ChainWallet & (T extends EmptyWallet ? T[key] : never); + [key in WalletChain]: ChainWallet & (T extends EmptyWallet ? T[key] : never); }; export type FullWallet = BaseWallet< @@ -91,7 +91,7 @@ export type SwapKitWallet = ( ) => (...connectParams: ConnectParams) => boolean | Promise; export type SwapKitPluginParams = { - getWallet: (chain: T) => FullWallet[T]; + getWallet: (chain: T) => FullWallet[T]; stagenet?: boolean; config: Config; }; diff --git a/packages/wallets/ledger/src/ledgerLive.ts b/packages/wallets/ledger/src/ledgerLive.ts index 51a333e9c..f13f541fb 100644 --- a/packages/wallets/ledger/src/ledgerLive.ts +++ b/packages/wallets/ledger/src/ledgerLive.ts @@ -14,9 +14,10 @@ import { FeeOption, SwapKitError, SwapKitNumber, + type WalletChain, WalletOption, setRequestClientConfig, -} from "@swapkit/sdk"; +} from "@swapkit/helpers"; import { ETHToolbox, getProvider } from "@swapkit/toolbox-evm"; import type { UTXOTransferParams } from "@swapkit/toolbox-utxo"; import { BigNumber as BigNumberJS } from "bignumber.js"; @@ -37,14 +38,14 @@ export enum LedgerLiveChain { ATOM = "cosmos", } -export const LEDGER_LIVE_SUPPORTED_CHAINS: Chain[] = [ +export const LEDGER_LIVE_SUPPORTED_CHAINS = [ Chain.Bitcoin, Chain.Ethereum, Chain.Cosmos, Chain.Litecoin, Chain.Dogecoin, Chain.BitcoinCash, -]; +] as WalletChain[]; export const ChainToLedgerLiveChain: Partial> = { [Chain.Arbitrum]: LedgerLiveChain.ARB, diff --git a/playgrounds/vite/src/App.tsx b/playgrounds/vite/src/App.tsx index ea1b6249b..4ba395a34 100644 --- a/playgrounds/vite/src/App.tsx +++ b/playgrounds/vite/src/App.tsx @@ -1,4 +1,4 @@ -import { AssetValue, type Chain, type FullWallet } from "@swapkit/core"; +import { AssetValue, type FullWallet, type WalletChain } from "@swapkit/core"; import { useCallback, useEffect, useMemo, useState } from "react"; import { WalletWidget } from "@swapkit/wallet-exodus"; @@ -14,7 +14,7 @@ import { getSwapKitClient } from "./swapKitClient"; const apiKeys = ["walletConnectProjectId"] as const; -type WalletDataType = FullWallet[Chain] | FullWallet[Chain][] | null; +type WalletDataType = FullWallet[WalletChain] | FullWallet[WalletChain][] | null; const App = () => { const [widgetType, setWidgetType] = useState<"swap" | "loan" | "earn">("swap"); @@ -62,7 +62,7 @@ const App = () => { [inputAsset, outputAsset], ); - const disconnectChain = (chain: Chain) => { + const disconnectChain = (chain: WalletChain) => { if (!skClient) return; skClient.disconnectChain(chain); setWallet(Object.values(skClient.getAllWallets())); @@ -154,15 +154,17 @@ const App = () => { key={`${walletData?.address}-${walletData?.balance?.[0]?.chain}`} setAsset={setAsset} walletData={walletData} - disconnect={() => disconnectChain(walletData?.balance?.[0]?.chain as Chain)} + disconnect={() => + disconnectChain(walletData?.balance?.[0]?.chain as WalletChain) + } /> )) ) : ( disconnectChain(wallet?.balance?.[0]?.chain as Chain)} + walletData={wallet as FullWallet[WalletChain]} + disconnect={() => disconnectChain(wallet?.balance?.[0]?.chain as WalletChain)} /> )} diff --git a/playgrounds/vite/src/Send/index.tsx b/playgrounds/vite/src/Send/index.tsx index ab8b51390..c5494519e 100644 --- a/playgrounds/vite/src/Send/index.tsx +++ b/playgrounds/vite/src/Send/index.tsx @@ -1,4 +1,4 @@ -import type { AssetValue, WalletChain } from "@swapkit/core"; +import type { AssetValue, Chain, WalletChain } from "@swapkit/core"; import { useCallback, useState } from "react"; import type { SwapKitClient } from "../swapKitClient"; @@ -22,13 +22,15 @@ export default function Send({ const handleSend = useCallback(async () => { if (!(inputAsset && inputAssetValue?.gt(0) && skClient)) return; - const from = skClient.getAddress(inputAsset.chain); - const txHash = await skClient.getWallet(inputAssetValue.chain as WalletChain).transfer({ - from, - assetValue: inputAssetValue, - memo: "", - recipient, - }); + const from = skClient.getAddress(inputAsset.chain as WalletChain); + const txHash = await skClient + .getWallet(inputAssetValue.chain as Exclude) + .transfer({ + from, + assetValue: inputAssetValue, + memo: "", + recipient, + }); window.open( `${skClient.getExplorerTxUrl({ chain: inputAssetValue.chain, txHash: txHash as string })}`, diff --git a/playgrounds/vite/src/Swap/SwapInputs.tsx b/playgrounds/vite/src/Swap/SwapInputs.tsx index 5bf613a2a..bfd2270cb 100644 --- a/playgrounds/vite/src/Swap/SwapInputs.tsx +++ b/playgrounds/vite/src/Swap/SwapInputs.tsx @@ -1,5 +1,5 @@ "use client"; -import type { AssetValue, QuoteResponseRoute, SwapKit } from "@swapkit/sdk"; +import type { AssetValue, QuoteResponseRoute, SwapKit, WalletChain } from "@swapkit/sdk"; import { ProviderName, SwapKitApi, SwapKitNumber } from "@swapkit/sdk"; import { useCallback, useState } from "react"; @@ -34,8 +34,8 @@ export const SwapInputs = ({ skClient, inputAsset, outputAsset, handleSwap }: Pr setLoading(true); setRoutes([]); - const sourceAddress = skClient.getAddress(inputAsset.chain); - const destinationAddress = skClient.getAddress(outputAsset.chain); + const sourceAddress = skClient.getAddress(inputAsset.chain as WalletChain); + const destinationAddress = skClient.getAddress(outputAsset.chain as WalletChain); // const providers = Object.values(ProviderName); try { diff --git a/playgrounds/vite/src/Wallet.tsx b/playgrounds/vite/src/Wallet.tsx index 92c1684a2..a1b8aec0c 100644 --- a/playgrounds/vite/src/Wallet.tsx +++ b/playgrounds/vite/src/Wallet.tsx @@ -1,7 +1,7 @@ -import { type Chain, type FullWallet, SwapKitApi } from "@swapkit/sdk"; +import { type FullWallet, SwapKitApi, type WalletChain } from "@swapkit/sdk"; type Props = { - walletData: FullWallet[Chain]; + walletData: FullWallet[WalletChain]; setAsset: (asset: any) => void; disconnect: () => void; };