@swapkit/wallet-core 4.0.43 → 4.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -4
- package/src/index.ts +37 -0
- package/src/types.ts +17 -0
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "swapkit-oss",
|
|
3
|
-
"dependencies": { "@swapkit/helpers": "4.
|
|
3
|
+
"dependencies": { "@swapkit/helpers": "4.5.3" },
|
|
4
4
|
"description": "SwapKit - Wallet Core",
|
|
5
5
|
"exports": {
|
|
6
|
-
".": {
|
|
6
|
+
".": {
|
|
7
|
+
"bun": "./src/index.ts",
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"require": "./dist/index.cjs",
|
|
10
|
+
"types": "./dist/types/index.d.ts"
|
|
11
|
+
}
|
|
7
12
|
},
|
|
8
|
-
"files": ["dist/"],
|
|
13
|
+
"files": ["dist/", "src/"],
|
|
9
14
|
"homepage": "https://github.com/swapkit/SwapKit",
|
|
10
15
|
"license": "Apache-2.0",
|
|
11
16
|
"name": "@swapkit/wallet-core",
|
|
@@ -24,5 +29,5 @@
|
|
|
24
29
|
"type-check:go": "tsgo"
|
|
25
30
|
},
|
|
26
31
|
"type": "module",
|
|
27
|
-
"version": "4.0.
|
|
32
|
+
"version": "4.0.47"
|
|
28
33
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AddChainType, Chain, WalletOption } from "@swapkit/helpers";
|
|
2
|
+
|
|
3
|
+
export function createWallet<
|
|
4
|
+
ConnectParams extends any[],
|
|
5
|
+
SupportedChains extends Chain[],
|
|
6
|
+
const Name extends string,
|
|
7
|
+
WalletType extends WalletOption,
|
|
8
|
+
>({
|
|
9
|
+
connect,
|
|
10
|
+
name,
|
|
11
|
+
supportedChains,
|
|
12
|
+
walletType,
|
|
13
|
+
}: {
|
|
14
|
+
connect: (connectParams: {
|
|
15
|
+
addChain: AddChainType;
|
|
16
|
+
walletType: WalletType;
|
|
17
|
+
supportedChains: SupportedChains;
|
|
18
|
+
}) => (...params: ConnectParams) => Promise<boolean>;
|
|
19
|
+
name: Name;
|
|
20
|
+
supportedChains: SupportedChains;
|
|
21
|
+
walletType?: WalletType | string;
|
|
22
|
+
}) {
|
|
23
|
+
function connectWallet(connectParams: { addChain: AddChainType }) {
|
|
24
|
+
return connect({ ...connectParams, supportedChains, walletType: walletType as WalletType });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return { [name]: { connectWallet, supportedChains } } as unknown as {
|
|
28
|
+
[key in Name]: { connectWallet: typeof connectWallet; supportedChains: SupportedChains };
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getWalletSupportedChains<T extends ReturnType<typeof createWallet<any, any, any, any>>>(
|
|
33
|
+
wallet: T,
|
|
34
|
+
): T[keyof T]["supportedChains"] {
|
|
35
|
+
const walletName = Object.keys(wallet)?.[0] || "";
|
|
36
|
+
return wallet?.[walletName]?.supportedChains || [];
|
|
37
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AddChainType, Chain, WalletOption } from "@swapkit/helpers";
|
|
2
|
+
|
|
3
|
+
export type ConnectFunction<
|
|
4
|
+
ConnectParams extends any[],
|
|
5
|
+
SupportedChains extends Chain[],
|
|
6
|
+
WalletType extends WalletOption,
|
|
7
|
+
> = (connectParams: {
|
|
8
|
+
addChain: AddChainType;
|
|
9
|
+
walletType: WalletType;
|
|
10
|
+
supportedChains: SupportedChains;
|
|
11
|
+
}) => (...params: ConnectParams) => Promise<boolean>;
|
|
12
|
+
|
|
13
|
+
export type CreateFunction<
|
|
14
|
+
CreateParams extends any[],
|
|
15
|
+
WalletType extends WalletOption,
|
|
16
|
+
Wallets extends Record<Chain, any>,
|
|
17
|
+
> = (createParams: { walletType: WalletType }) => (...params: CreateParams) => Promise<Wallets> | Wallets;
|