Skip to content

Commit

Permalink
feat: export types and improves url creation (#1122)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
towanTG and github-actions[bot] authored Dec 10, 2024
1 parent c6ca262 commit ad33986
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 71 deletions.
5 changes: 5 additions & 0 deletions .changeset/sweet-mayflies-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@swapkit/plugin-kado": minor
---

Exports typing and helpers and changes kado url creation
2 changes: 2 additions & 0 deletions packages/plugins/kado/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from "./helpers";
export * from "./plugin";
export * from "./types";
84 changes: 13 additions & 71 deletions packages/plugins/kado/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import type { SwapKitPluginParams, SwapParams } from "@swapkit/helpers";
import { ChainToKadoChain } from "./helpers";
import type {
KadoBlockchainsResponse,
KadoFiatCurrency,
KadoFiatMethod,
KadoQuoteRequest,
Expand Down Expand Up @@ -119,62 +120,9 @@ function mapKadoQuoteToQuoteResponse({
};
}

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;
}[];
};
};

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;
}[];
};
};

function plugin({ config: { kadoApiKey } }: SwapKitPluginParams<{ kadoApiKey: string }>) {
function plugin({
config: { kadoApiKey },
}: Exclude<SwapKitPluginParams<{ kadoApiKey: string }>, SwapKitPluginParams["getWallet"]>) {
async function fetchProviderQuote({
sellAsset,
buyAsset,
Expand Down Expand Up @@ -294,39 +242,35 @@ function plugin({ config: { kadoApiKey } }: SwapKitPluginParams<{ kadoApiKey: st
function getKadoWidgetUrl({
sellAsset,
buyAsset,
supportedAssets,
recipient,
type,
sender,
widgetMode,
}: {
sellAsset: AssetValue;
buyAsset: AssetValue;
supportedAssets: AssetValue[];
recipient: string;
sender: string;
type: "BUY" | "SELL";
typeList: "BUY" | "SELL";
recipient?: string;
sender?: string;
type: "buy" | "sell";
widgetMode: "minimal" | "full";
}) {
const urlParams = new URLSearchParams({
apiKey: kadoApiKey,
...(type === "BUY"
...(type === "buy"
? {
onPayAmount: sellAsset.getValue("string"),
onPayCurrency: sellAsset.symbol,
onRevCurrency: buyAsset.symbol,
onToAddress: recipient,
...(recipient ? { onToAddress: recipient } : {}),
}
: {
offPayAmount: sellAsset.getValue("string"),
offPayCurrency: sellAsset.symbol,
offRevCurrency: buyAsset.symbol,
offFromAddress: sender,
...(sender ? { offFromAddress: sender } : {}),
}),
cryptoList: supportedAssets.map((asset) => asset.symbol).join(","),
network: ChainToKadoChain(type === "BUY" ? buyAsset.chain : sellAsset.chain).toUpperCase(),
product: type,
network: ChainToKadoChain(type === "buy" ? buyAsset.chain : sellAsset.chain).toUpperCase(),
product: type.toUpperCase(),
mode: widgetMode,
});

Expand Down Expand Up @@ -379,16 +323,14 @@ function plugin({ config: { kadoApiKey } }: SwapKitPluginParams<{ kadoApiKey: st
const buyAsset = AssetValue.from({ asset: route.buyAsset });

// Determine if this is a buy or sell operation
const type = sellAsset.chain === Chain.Fiat ? "BUY" : "SELL";
const type = sellAsset.chain === Chain.Fiat ? "buy" : "sell";

const url = getKadoWidgetUrl({
sellAsset,
buyAsset,
supportedAssets: [sellAsset, buyAsset],
recipient: route.destinationAddress,
sender: route.sourceAddress,
type,
typeList: type,
widgetMode: "minimal",
});

Expand Down

0 comments on commit ad33986

Please sign in to comment.