Skip to content

Commit

Permalink
feat: improves core and sdk typing (#1134)
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 16, 2024
1 parent 69fbebe commit a9b122b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .changeset/sweet-countries-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@swapkit/core": patch
"@swapkit/sdk": patch
---

Type improvements for using core / sdk
11 changes: 6 additions & 5 deletions packages/swapkit/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ import {
getExplorerTxUrl as getTxUrl,
} from "./helpers/explorerUrls";

type PluginsType = {
export type PluginsType = {
[key in string]: {
plugin: (params: SwapKitPluginParams<any>) => any;
config?: any;
};
};

export type WalletsType = {
[key in string]: SwapKitWallet<any[]>;
};

export type SwapKitParams<P, W> = {
apis?: ChainApis;
config?: ConnectConfig;
Expand All @@ -51,10 +55,7 @@ export type SwapKitParams<P, W> = {
wallets?: W;
};

export function SwapKit<
Plugins extends PluginsType,
Wallets extends { [key in string]: SwapKitWallet<any[]> },
>({
export function SwapKit<Plugins extends PluginsType, Wallets extends WalletsType>({
apis = {},
config = {},
plugins,
Expand Down
13 changes: 8 additions & 5 deletions packages/swapkit/sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SwapKit, type SwapKitParams } from "@swapkit/core";
import { type PluginsType, SwapKit, type SwapKitParams, type WalletsType } from "@swapkit/core";
import { ChainflipPlugin } from "@swapkit/plugin-chainflip";
import { EVMPlugin } from "@swapkit/plugin-evm";
import { KadoPlugin } from "@swapkit/plugin-kado";
Expand All @@ -18,15 +18,18 @@ export const defaultPlugins = {
...RadixPlugin,
};

export const createSwapKit = <P extends typeof defaultPlugins, W extends typeof defaultWallets>({
export const createSwapKit = <
P extends PluginsType = typeof defaultPlugins,
W extends WalletsType = typeof defaultWallets,
>({
plugins,
wallets,
...extendParams
}: SwapKitParams<P, W> = {}) => {
return SwapKit({
return SwapKit<P, W>({
...extendParams,
wallets: wallets || defaultWallets,
plugins: plugins || defaultPlugins,
wallets: (wallets || defaultWallets) as W,
plugins: (plugins || defaultPlugins) as P,
});
};

Expand Down

0 comments on commit a9b122b

Please sign in to comment.