@txnlab/use-wallet 2.1.2 → 2.2.0
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/README.md +82 -0
- package/dist/cjs/index.js +102 -25
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/src/clients/custom/client.d.ts +18 -0
- package/dist/cjs/src/clients/custom/constants.d.ts +1 -0
- package/dist/cjs/src/clients/custom/index.d.ts +2 -0
- package/dist/cjs/src/clients/custom/types.d.ts +25 -0
- package/dist/cjs/src/clients/index.d.ts +4 -2
- package/dist/cjs/src/constants/constants.d.ts +1 -0
- package/dist/cjs/src/testUtils/mockClients.d.ts +3 -0
- package/dist/cjs/src/types/providers.d.ts +7 -1
- package/dist/esm/index.js +102 -26
- package/dist/esm/src/clients/custom/client.d.ts +18 -0
- package/dist/esm/src/clients/custom/constants.d.ts +1 -0
- package/dist/esm/src/clients/custom/index.d.ts +2 -0
- package/dist/esm/src/clients/custom/types.d.ts +25 -0
- package/dist/esm/src/clients/index.d.ts +4 -2
- package/dist/esm/src/constants/constants.d.ts +1 -0
- package/dist/esm/src/testUtils/mockClients.d.ts +3 -0
- package/dist/esm/src/types/providers.d.ts +7 -1
- package/dist/index.d.ts +43 -2
- package/package.json +5 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import BaseClient from '../base';
|
|
2
|
+
import { PROVIDER_ID } from '../../constants';
|
|
3
|
+
import type { Network } from '../../types/node';
|
|
4
|
+
import type { InitParams } from '../../types/providers';
|
|
5
|
+
import type { Metadata, Wallet } from '../../types/wallet';
|
|
6
|
+
import type { CustomProvider, CustomWalletClientConstructor } from './types';
|
|
7
|
+
declare class CustomWalletClient extends BaseClient {
|
|
8
|
+
network: Network;
|
|
9
|
+
providerProxy: CustomProvider;
|
|
10
|
+
static metadata: Metadata;
|
|
11
|
+
constructor({ providerProxy, metadata, algosdk, algodClient, network }: CustomWalletClientConstructor);
|
|
12
|
+
static init({ clientOptions, algodOptions, algosdkStatic, network }: InitParams<PROVIDER_ID.CUSTOM>): Promise<BaseClient | null>;
|
|
13
|
+
connect(): Promise<Wallet>;
|
|
14
|
+
disconnect(): Promise<void>;
|
|
15
|
+
reconnect(): Promise<Wallet | null>;
|
|
16
|
+
signTransactions(connectedAccounts: string[], txnGroups: Uint8Array[] | Uint8Array[][], indexesToSign?: number[], returnGroup?: boolean): Promise<Uint8Array[]>;
|
|
17
|
+
}
|
|
18
|
+
export default CustomWalletClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ICON = "data:image/svg+xml,%3Csvg fill='%23000000' width='800px' height='800px' viewBox='0 0 24 24' id='wallet' data-name='Flat Line' xmlns='http://www.w3.org/2000/svg' class='icon flat-line'%3E%3Cpath id='secondary' d='M16,12h5V8H5A2,2,0,0,1,3,6V19a1,1,0,0,0,1,1H20a1,1,0,0,0,1-1V16H16a1,1,0,0,1-1-1V13A1,1,0,0,1,16,12Z' style='fill: rgb(44, 169, 188); stroke-width: 2;'%3E%3C/path%3E%3Cpath id='primary' d='M19,4H5A2,2,0,0,0,3,6H3A2,2,0,0,0,5,8H21' style='fill: none; stroke: rgb(0, 0, 0); stroke-linecap: round; stroke-linejoin: round; stroke-width: 2;'%3E%3C/path%3E%3Cpath id='primary-2' data-name='primary' d='M21,8V19a1,1,0,0,1-1,1H4a1,1,0,0,1-1-1V6A2,2,0,0,0,5,8Zm0,4H16a1,1,0,0,0-1,1v2a1,1,0,0,0,1,1h5Z' style='fill: none; stroke: rgb(0, 0, 0); stroke-linecap: round; stroke-linejoin: round; stroke-width: 2;'%3E%3C/path%3E%3C/svg%3E";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type algosdk from 'algosdk';
|
|
2
|
+
import type { Network } from '../../types/node';
|
|
3
|
+
import type { Metadata, Wallet } from '../../types/wallet';
|
|
4
|
+
export type CustomOptions = {
|
|
5
|
+
name: string;
|
|
6
|
+
icon?: string;
|
|
7
|
+
getProvider: (params: {
|
|
8
|
+
network?: Network;
|
|
9
|
+
algod?: algosdk.Algodv2;
|
|
10
|
+
algosdkStatic?: typeof algosdk;
|
|
11
|
+
}) => CustomProvider;
|
|
12
|
+
};
|
|
13
|
+
export type CustomProvider = {
|
|
14
|
+
connect(metadata: Metadata): Promise<Wallet>;
|
|
15
|
+
disconnect(): Promise<void>;
|
|
16
|
+
reconnect(metadata: Metadata): Promise<Wallet | null>;
|
|
17
|
+
signTransactions(connectedAccounts: string[], txnGroups: Uint8Array[] | Uint8Array[][], indexesToSign?: number[], returnGroup?: boolean): Promise<Uint8Array[]>;
|
|
18
|
+
};
|
|
19
|
+
export type CustomWalletClientConstructor = {
|
|
20
|
+
providerProxy: CustomProvider;
|
|
21
|
+
metadata: Metadata;
|
|
22
|
+
algosdk: typeof algosdk;
|
|
23
|
+
algodClient: algosdk.Algodv2;
|
|
24
|
+
network: Network;
|
|
25
|
+
};
|
|
@@ -7,8 +7,10 @@ import algosigner from './algosigner';
|
|
|
7
7
|
import walletconnect from './walletconnect2';
|
|
8
8
|
import kmd from './kmd';
|
|
9
9
|
import mnemonic from './mnemonic';
|
|
10
|
-
|
|
10
|
+
import { CustomProvider } from './custom/types';
|
|
11
|
+
import custom from './custom';
|
|
12
|
+
export { pera, myalgo, defly, exodus, algosigner, walletconnect, kmd, mnemonic, custom, CustomProvider };
|
|
11
13
|
declare const _default: {
|
|
12
|
-
[x: string]: typeof pera | typeof myalgo | typeof defly | typeof exodus | typeof algosigner | typeof walletconnect | typeof kmd | typeof mnemonic | typeof daffi;
|
|
14
|
+
[x: string]: typeof pera | typeof myalgo | typeof defly | typeof exodus | typeof algosigner | typeof walletconnect | typeof kmd | typeof mnemonic | typeof custom | typeof daffi;
|
|
13
15
|
};
|
|
14
16
|
export default _default;
|
|
@@ -9,8 +9,10 @@ import PeraWalletClient from '../clients/pera/client';
|
|
|
9
9
|
import WalletConnectClient from '../clients/walletconnect2/client';
|
|
10
10
|
import { PROVIDER_ID } from '../constants';
|
|
11
11
|
import type { Account, ClientOptions } from '../types';
|
|
12
|
+
import CustomWalletClient from '../clients/custom/client';
|
|
12
13
|
type ClientTypeMap = {
|
|
13
14
|
[PROVIDER_ID.ALGOSIGNER]: AlgoSignerClient;
|
|
15
|
+
[PROVIDER_ID.CUSTOM]: CustomWalletClient;
|
|
14
16
|
[PROVIDER_ID.DAFFI]: DaffiWalletClient;
|
|
15
17
|
[PROVIDER_ID.DEFLY]: DeflyWalletClient;
|
|
16
18
|
[PROVIDER_ID.EXODUS]: ExodusClient;
|
|
@@ -26,6 +28,7 @@ export declare const createDaffiMockInstance: (clientOptions?: ClientOptions, ac
|
|
|
26
28
|
export declare const createDeflyMockInstance: (clientOptions?: ClientOptions, accounts?: Array<Account>) => DeflyWalletClient;
|
|
27
29
|
export declare const createExodusMockInstance: (clientOptions?: ClientOptions, accounts?: Array<Account>) => ExodusClient;
|
|
28
30
|
export declare const createKmdMockInstance: (clientOptions?: ClientOptions, accounts?: Array<Account>) => KMDWalletClient;
|
|
31
|
+
export declare const createCustomMockInstance: (clientOptions?: ClientOptions, accounts?: Array<Account>) => CustomWalletClient;
|
|
29
32
|
export declare const createMnemonicMockInstance: (clientOptions?: ClientOptions, accounts?: Array<Account>) => MnemonicWalletClient;
|
|
30
33
|
export declare const createMyAlgoMockInstance: (clientOptions?: ClientOptions, accounts?: Array<Account>) => MyAlgoWalletClient;
|
|
31
34
|
export declare const createPeraMockInstance: (clientOptions?: ClientOptions, accounts?: Array<Account>) => PeraWalletClient;
|
|
@@ -14,6 +14,7 @@ import type { MyAlgoConnectOptions } from '../clients/myalgo/types';
|
|
|
14
14
|
import type { DaffiWalletConnectOptions } from '../clients/daffi/types';
|
|
15
15
|
import type { NonEmptyArray } from './utilities';
|
|
16
16
|
import type BaseClient from '../clients/base';
|
|
17
|
+
import type { CustomOptions } from '../clients/custom/types';
|
|
17
18
|
export type ProviderConfigMapping = {
|
|
18
19
|
[PROVIDER_ID.PERA]: {
|
|
19
20
|
clientOptions?: PeraWalletConnectOptions;
|
|
@@ -50,6 +51,11 @@ export type ProviderConfigMapping = {
|
|
|
50
51
|
clientStatic?: undefined;
|
|
51
52
|
getDynamicClient?: undefined;
|
|
52
53
|
};
|
|
54
|
+
[PROVIDER_ID.CUSTOM]: {
|
|
55
|
+
clientOptions?: CustomOptions;
|
|
56
|
+
clientStatic?: undefined;
|
|
57
|
+
getDynamicClient?: undefined;
|
|
58
|
+
};
|
|
53
59
|
[PROVIDER_ID.ALGOSIGNER]: {
|
|
54
60
|
clientOptions?: undefined;
|
|
55
61
|
clientStatic?: undefined;
|
|
@@ -97,7 +103,7 @@ type DynamicClient<T> = {
|
|
|
97
103
|
type OneOfStaticOrDynamicClient<T> = StaticClient<T> | DynamicClient<T>;
|
|
98
104
|
type ProviderDef = (ProviderConfig<PROVIDER_ID.PERA> & OneOfStaticOrDynamicClient<typeof PeraWalletConnect>) | (ProviderConfig<PROVIDER_ID.DEFLY> & OneOfStaticOrDynamicClient<typeof DeflyWalletConnect>) | (ProviderConfig<PROVIDER_ID.DAFFI> & OneOfStaticOrDynamicClient<typeof DaffiWalletConnect>) | (ProviderConfig<PROVIDER_ID.WALLETCONNECT> & OneOfStaticOrDynamicClient<typeof WalletConnectModalSign> & {
|
|
99
105
|
clientOptions: WalletConnectModalSignOptions;
|
|
100
|
-
}) | (ProviderConfig<PROVIDER_ID.MYALGO> & OneOfStaticOrDynamicClient<typeof MyAlgoConnect>) | ProviderConfig<PROVIDER_ID.EXODUS> | ProviderConfig<PROVIDER_ID.KMD> | PROVIDER_ID.EXODUS | PROVIDER_ID.KMD | PROVIDER_ID.ALGOSIGNER | PROVIDER_ID.MNEMONIC;
|
|
106
|
+
}) | (ProviderConfig<PROVIDER_ID.MYALGO> & OneOfStaticOrDynamicClient<typeof MyAlgoConnect>) | ProviderConfig<PROVIDER_ID.EXODUS> | ProviderConfig<PROVIDER_ID.KMD> | ProviderConfig<PROVIDER_ID.CUSTOM> | PROVIDER_ID.EXODUS | PROVIDER_ID.KMD | PROVIDER_ID.ALGOSIGNER | PROVIDER_ID.MNEMONIC | PROVIDER_ID.CUSTOM;
|
|
101
107
|
export type ProvidersArray = NonEmptyArray<ProviderDef>;
|
|
102
108
|
export type WalletClient = BaseClient;
|
|
103
109
|
export type SupportedProviders = Partial<Record<PROVIDER_ID, WalletClient | null>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ type RawTxnResponse = {
|
|
|
69
69
|
|
|
70
70
|
declare enum PROVIDER_ID {
|
|
71
71
|
KMD = "kmd",
|
|
72
|
+
CUSTOM = "custom",
|
|
72
73
|
PERA = "pera",
|
|
73
74
|
DAFFI = "daffi",
|
|
74
75
|
MYALGO = "myalgo",
|
|
@@ -280,6 +281,29 @@ declare abstract class BaseClient {
|
|
|
280
281
|
keepWCAliveStop(): void;
|
|
281
282
|
}
|
|
282
283
|
|
|
284
|
+
type CustomOptions = {
|
|
285
|
+
name: string;
|
|
286
|
+
icon?: string;
|
|
287
|
+
getProvider: (params: {
|
|
288
|
+
network?: Network;
|
|
289
|
+
algod?: algosdk.Algodv2;
|
|
290
|
+
algosdkStatic?: typeof algosdk;
|
|
291
|
+
}) => CustomProvider;
|
|
292
|
+
};
|
|
293
|
+
type CustomProvider = {
|
|
294
|
+
connect(metadata: Metadata): Promise<Wallet>;
|
|
295
|
+
disconnect(): Promise<void>;
|
|
296
|
+
reconnect(metadata: Metadata): Promise<Wallet | null>;
|
|
297
|
+
signTransactions(connectedAccounts: string[], txnGroups: Uint8Array[] | Uint8Array[][], indexesToSign?: number[], returnGroup?: boolean): Promise<Uint8Array[]>;
|
|
298
|
+
};
|
|
299
|
+
type CustomWalletClientConstructor = {
|
|
300
|
+
providerProxy: CustomProvider;
|
|
301
|
+
metadata: Metadata;
|
|
302
|
+
algosdk: typeof algosdk;
|
|
303
|
+
algodClient: algosdk.Algodv2;
|
|
304
|
+
network: Network;
|
|
305
|
+
};
|
|
306
|
+
|
|
283
307
|
type ProviderConfigMapping = {
|
|
284
308
|
[PROVIDER_ID.PERA]: {
|
|
285
309
|
clientOptions?: PeraWalletConnectOptions;
|
|
@@ -316,6 +340,11 @@ type ProviderConfigMapping = {
|
|
|
316
340
|
clientStatic?: undefined;
|
|
317
341
|
getDynamicClient?: undefined;
|
|
318
342
|
};
|
|
343
|
+
[PROVIDER_ID.CUSTOM]: {
|
|
344
|
+
clientOptions?: CustomOptions;
|
|
345
|
+
clientStatic?: undefined;
|
|
346
|
+
getDynamicClient?: undefined;
|
|
347
|
+
};
|
|
319
348
|
[PROVIDER_ID.ALGOSIGNER]: {
|
|
320
349
|
clientOptions?: undefined;
|
|
321
350
|
clientStatic?: undefined;
|
|
@@ -363,7 +392,7 @@ type DynamicClient<T> = {
|
|
|
363
392
|
type OneOfStaticOrDynamicClient<T> = StaticClient<T> | DynamicClient<T>;
|
|
364
393
|
type ProviderDef = (ProviderConfig<PROVIDER_ID.PERA> & OneOfStaticOrDynamicClient<typeof PeraWalletConnect>) | (ProviderConfig<PROVIDER_ID.DEFLY> & OneOfStaticOrDynamicClient<typeof DeflyWalletConnect>) | (ProviderConfig<PROVIDER_ID.DAFFI> & OneOfStaticOrDynamicClient<typeof DaffiWalletConnect>) | (ProviderConfig<PROVIDER_ID.WALLETCONNECT> & OneOfStaticOrDynamicClient<typeof WalletConnectModalSign> & {
|
|
365
394
|
clientOptions: WalletConnectModalSignOptions;
|
|
366
|
-
}) | (ProviderConfig<PROVIDER_ID.MYALGO> & OneOfStaticOrDynamicClient<typeof MyAlgoConnect>) | ProviderConfig<PROVIDER_ID.EXODUS> | ProviderConfig<PROVIDER_ID.KMD> | PROVIDER_ID.EXODUS | PROVIDER_ID.KMD | PROVIDER_ID.ALGOSIGNER | PROVIDER_ID.MNEMONIC;
|
|
395
|
+
}) | (ProviderConfig<PROVIDER_ID.MYALGO> & OneOfStaticOrDynamicClient<typeof MyAlgoConnect>) | ProviderConfig<PROVIDER_ID.EXODUS> | ProviderConfig<PROVIDER_ID.KMD> | ProviderConfig<PROVIDER_ID.CUSTOM> | PROVIDER_ID.EXODUS | PROVIDER_ID.KMD | PROVIDER_ID.ALGOSIGNER | PROVIDER_ID.MNEMONIC | PROVIDER_ID.CUSTOM;
|
|
367
396
|
type ProvidersArray = NonEmptyArray<ProviderDef>;
|
|
368
397
|
type WalletClient = BaseClient;
|
|
369
398
|
type SupportedProviders = Partial<Record<PROVIDER_ID, WalletClient | null>>;
|
|
@@ -677,6 +706,18 @@ declare class MnemonicWalletClient extends BaseClient {
|
|
|
677
706
|
signEncodedTransactions(_transactions: TransactionsArray): Promise<Uint8Array[]>;
|
|
678
707
|
}
|
|
679
708
|
|
|
709
|
+
declare class CustomWalletClient extends BaseClient {
|
|
710
|
+
network: Network;
|
|
711
|
+
providerProxy: CustomProvider;
|
|
712
|
+
static metadata: Metadata;
|
|
713
|
+
constructor({ providerProxy, metadata, algosdk, algodClient, network }: CustomWalletClientConstructor);
|
|
714
|
+
static init({ clientOptions, algodOptions, algosdkStatic, network }: InitParams<PROVIDER_ID.CUSTOM>): Promise<BaseClient | null>;
|
|
715
|
+
connect(): Promise<Wallet>;
|
|
716
|
+
disconnect(): Promise<void>;
|
|
717
|
+
reconnect(): Promise<Wallet | null>;
|
|
718
|
+
signTransactions(connectedAccounts: string[], txnGroups: Uint8Array[] | Uint8Array[][], indexesToSign?: number[], returnGroup?: boolean): Promise<Uint8Array[]>;
|
|
719
|
+
}
|
|
720
|
+
|
|
680
721
|
declare function useWallet(): {
|
|
681
722
|
clients: Partial<Record<PROVIDER_ID, BaseClient | null>> | null;
|
|
682
723
|
providers: Provider[] | null;
|
|
@@ -714,4 +755,4 @@ interface InitializeProvidersOptions {
|
|
|
714
755
|
}
|
|
715
756
|
declare function useInitializeProviders({ providers, nodeConfig, algosdkStatic, debug }: InitializeProvidersOptions): Partial<Record<PROVIDER_ID, BaseClient | null>> | null;
|
|
716
757
|
|
|
717
|
-
export { Account, AccountInfo, AlgodClientOptions, Asset, ClientOptions, CommonInitParams, ConfirmedTxn, DEFAULT_NETWORK, DEFAULT_NODE_BASEURL, DEFAULT_NODE_PORT, DEFAULT_NODE_TOKEN, DecodedSignedTransaction, DecodedTransaction, InitParams, Metadata, Network, NodeConfig, PROVIDER_ID, Provider, ProviderConfig, ProviderConfigMapping, ProvidersArray, PublicNetwork, RawTxnResponse, SupportedProviders, TransactionsArray, Txn, TxnInfo, TxnType, Wallet, WalletClient, _default as WalletProvider, AlgoSignerClient as algosigner, DeflyWalletClient as defly, encodeNFDTransactionsArray, ExodusClient as exodus, KMDWalletClient as kmd, MnemonicWalletClient as mnemonic, MyAlgoWalletClient as myalgo, PeraWalletClient as pera, reconnectProviders, useInitializeProviders, useWallet, WalletConnectClient as walletconnect };
|
|
758
|
+
export { Account, AccountInfo, AlgodClientOptions, Asset, ClientOptions, CommonInitParams, ConfirmedTxn, CustomProvider, DEFAULT_NETWORK, DEFAULT_NODE_BASEURL, DEFAULT_NODE_PORT, DEFAULT_NODE_TOKEN, DecodedSignedTransaction, DecodedTransaction, InitParams, Metadata, Network, NodeConfig, PROVIDER_ID, Provider, ProviderConfig, ProviderConfigMapping, ProvidersArray, PublicNetwork, RawTxnResponse, SupportedProviders, TransactionsArray, Txn, TxnInfo, TxnType, Wallet, WalletClient, _default as WalletProvider, AlgoSignerClient as algosigner, CustomWalletClient as custom, DeflyWalletClient as defly, encodeNFDTransactionsArray, ExodusClient as exodus, KMDWalletClient as kmd, MnemonicWalletClient as mnemonic, MyAlgoWalletClient as myalgo, PeraWalletClient as pera, reconnectProviders, useInitializeProviders, useWallet, WalletConnectClient as walletconnect };
|
package/package.json
CHANGED
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
"url": "https://github.com/txnlab/use-wallet/issues"
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://txnlab.github.io/use-wallet",
|
|
15
|
-
"version": "2.
|
|
15
|
+
"version": "2.2.0",
|
|
16
16
|
"description": "React hooks for using Algorand compatible wallets in dApps.",
|
|
17
17
|
"scripts": {
|
|
18
18
|
"dev": "yarn storybook",
|
|
19
|
-
"build": "
|
|
19
|
+
"build": "rimraf dist && rollup -c",
|
|
20
20
|
"test": "jest",
|
|
21
21
|
"lint": "eslint '**/*.{js,ts,tsx}'",
|
|
22
22
|
"format": "prettier --check '**/*.{js,ts,tsx}'",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@perawallet/connect": "^1.2.1",
|
|
42
42
|
"@randlabs/myalgo-connect": "^1.4.2",
|
|
43
43
|
"@release-it/conventional-changelog": "^7.0.0",
|
|
44
|
-
"@rollup/plugin-commonjs": "^
|
|
44
|
+
"@rollup/plugin-commonjs": "^25.0.0",
|
|
45
45
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
46
46
|
"@storybook/addon-actions": "^6.5.16",
|
|
47
47
|
"@storybook/addon-essentials": "^6.5.16",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"algosdk": "^2.1.0",
|
|
61
61
|
"babel-jest": "^29.1.2",
|
|
62
62
|
"babel-loader": "^9.0.0",
|
|
63
|
+
"buffer": "^6.0.3",
|
|
63
64
|
"commitizen": "4.3.0",
|
|
64
65
|
"css-loader": "^6.5.1",
|
|
65
66
|
"cz-conventional-changelog": "3.3.0",
|
|
@@ -80,6 +81,7 @@
|
|
|
80
81
|
"react-dom": "^18.2.0",
|
|
81
82
|
"release-it": "^16.1.0",
|
|
82
83
|
"require-from-string": "^2.0.2",
|
|
84
|
+
"rimraf": "^5.0.1",
|
|
83
85
|
"rollup": "^3.3.0",
|
|
84
86
|
"rollup-plugin-analyzer": "^4.0.0",
|
|
85
87
|
"rollup-plugin-dts": "^5.0.0",
|