@txnlab/use-wallet 2.0.0-alpha.5 → 2.0.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.
Files changed (74) hide show
  1. package/README.md +35 -29
  2. package/dist/cjs/index.js +597 -269
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/jest.config.d.ts +1 -1
  5. package/dist/cjs/src/clients/algosigner/client.d.ts +4 -3
  6. package/dist/cjs/src/clients/algosigner/types.d.ts +12 -12
  7. package/dist/cjs/src/clients/base/base.d.ts +4 -3
  8. package/dist/cjs/src/clients/daffi/client.d.ts +6 -4
  9. package/dist/cjs/src/clients/daffi/types.d.ts +7 -10
  10. package/dist/cjs/src/clients/defly/client.d.ts +6 -5
  11. package/dist/cjs/src/clients/defly/types.d.ts +8 -11
  12. package/dist/cjs/src/clients/exodus/client.d.ts +4 -3
  13. package/dist/cjs/src/clients/exodus/types.d.ts +10 -12
  14. package/dist/cjs/src/clients/kmd/client.d.ts +5 -3
  15. package/dist/cjs/src/clients/kmd/types.d.ts +8 -10
  16. package/dist/cjs/src/clients/mnemonic/client.d.ts +5 -3
  17. package/dist/cjs/src/clients/mnemonic/types.d.ts +7 -7
  18. package/dist/cjs/src/clients/myalgo/client.d.ts +4 -7
  19. package/dist/cjs/src/clients/myalgo/types.d.ts +7 -10
  20. package/dist/cjs/src/clients/pera/client.d.ts +6 -4
  21. package/dist/cjs/src/clients/pera/types.d.ts +7 -10
  22. package/dist/cjs/src/clients/walletconnect2/client.d.ts +7 -5
  23. package/dist/cjs/src/clients/walletconnect2/constants.d.ts +0 -1
  24. package/dist/cjs/src/clients/walletconnect2/types.d.ts +8 -11
  25. package/dist/cjs/src/constants/constants.d.ts +1 -1
  26. package/dist/cjs/src/hooks/useInitializeProviders.d.ts +1 -1
  27. package/dist/cjs/src/index.d.ts +1 -1
  28. package/dist/cjs/src/store/state/debugStore.d.ts +1 -1
  29. package/dist/cjs/src/store/state/walletStore.d.ts +3 -3
  30. package/dist/cjs/src/testUtils/mockClients.d.ts +1 -1
  31. package/dist/cjs/src/types/api.d.ts +3 -3
  32. package/dist/cjs/src/types/node.d.ts +8 -8
  33. package/dist/cjs/src/types/providers.d.ts +27 -15
  34. package/dist/cjs/src/types/utilities.d.ts +1 -1
  35. package/dist/cjs/src/types/wallet.d.ts +9 -12
  36. package/dist/cjs/src/utils/encodeNFDTransactionsArray.d.ts +1 -1
  37. package/dist/cjs/src/utils/reconnectProviders.d.ts +1 -1
  38. package/dist/esm/index.js +597 -269
  39. package/dist/esm/jest.config.d.ts +1 -1
  40. package/dist/esm/src/clients/algosigner/client.d.ts +4 -3
  41. package/dist/esm/src/clients/algosigner/types.d.ts +12 -12
  42. package/dist/esm/src/clients/base/base.d.ts +4 -3
  43. package/dist/esm/src/clients/daffi/client.d.ts +6 -4
  44. package/dist/esm/src/clients/daffi/types.d.ts +7 -10
  45. package/dist/esm/src/clients/defly/client.d.ts +6 -5
  46. package/dist/esm/src/clients/defly/types.d.ts +8 -11
  47. package/dist/esm/src/clients/exodus/client.d.ts +4 -3
  48. package/dist/esm/src/clients/exodus/types.d.ts +10 -12
  49. package/dist/esm/src/clients/kmd/client.d.ts +5 -3
  50. package/dist/esm/src/clients/kmd/types.d.ts +8 -10
  51. package/dist/esm/src/clients/mnemonic/client.d.ts +5 -3
  52. package/dist/esm/src/clients/mnemonic/types.d.ts +7 -7
  53. package/dist/esm/src/clients/myalgo/client.d.ts +4 -7
  54. package/dist/esm/src/clients/myalgo/types.d.ts +7 -10
  55. package/dist/esm/src/clients/pera/client.d.ts +6 -4
  56. package/dist/esm/src/clients/pera/types.d.ts +7 -10
  57. package/dist/esm/src/clients/walletconnect2/client.d.ts +7 -5
  58. package/dist/esm/src/clients/walletconnect2/constants.d.ts +0 -1
  59. package/dist/esm/src/clients/walletconnect2/types.d.ts +8 -11
  60. package/dist/esm/src/constants/constants.d.ts +1 -1
  61. package/dist/esm/src/hooks/useInitializeProviders.d.ts +1 -1
  62. package/dist/esm/src/index.d.ts +1 -1
  63. package/dist/esm/src/store/state/debugStore.d.ts +1 -1
  64. package/dist/esm/src/store/state/walletStore.d.ts +3 -3
  65. package/dist/esm/src/testUtils/mockClients.d.ts +1 -1
  66. package/dist/esm/src/types/api.d.ts +3 -3
  67. package/dist/esm/src/types/node.d.ts +8 -8
  68. package/dist/esm/src/types/providers.d.ts +27 -15
  69. package/dist/esm/src/types/utilities.d.ts +1 -1
  70. package/dist/esm/src/types/wallet.d.ts +9 -12
  71. package/dist/esm/src/utils/encodeNFDTransactionsArray.d.ts +1 -1
  72. package/dist/esm/src/utils/reconnectProviders.d.ts +1 -1
  73. package/dist/index.d.ts +180 -200
  74. package/package.json +16 -20
@@ -1,6 +1,6 @@
1
1
  import { TxnType } from './node';
2
- export declare type TransactionsArray = ['u' | 's', string][];
3
- export declare type TxnInfo = {
2
+ export type TransactionsArray = ['u' | 's', string][];
3
+ export type TxnInfo = {
4
4
  groupIndex: number;
5
5
  amount: number;
6
6
  from: string;
@@ -9,6 +9,6 @@ export declare type TxnInfo = {
9
9
  txn: string;
10
10
  signedTxn?: Uint8Array;
11
11
  };
12
- export declare type RawTxnResponse = {
12
+ export type RawTxnResponse = {
13
13
  txId: string;
14
14
  };
@@ -1,7 +1,7 @@
1
1
  import type algosdk from 'algosdk';
2
- export declare type PublicNetwork = 'betanet' | 'testnet' | 'mainnet';
3
- export declare type Network = PublicNetwork | string;
4
- export declare type Txn = {
2
+ export type PublicNetwork = 'betanet' | 'testnet' | 'mainnet';
3
+ export type Network = PublicNetwork | string;
4
+ export type Txn = {
5
5
  apaa: Uint8Array;
6
6
  apas: number[];
7
7
  apid: number;
@@ -14,7 +14,7 @@ export declare type Txn = {
14
14
  snd: Uint8Array;
15
15
  type: string;
16
16
  };
17
- export declare type ConfirmedTxn = {
17
+ export type ConfirmedTxn = {
18
18
  'confirmed-round': number;
19
19
  'global-state-delta': Record<string, unknown>[];
20
20
  'pool-error': string;
@@ -23,8 +23,8 @@ export declare type ConfirmedTxn = {
23
23
  txn: Txn;
24
24
  };
25
25
  };
26
- export declare type TxnType = 'pay' | 'keyreg' | 'acfg' | 'axfer' | 'afrz' | 'appl' | 'stpf';
27
- export declare type DecodedTransaction = {
26
+ export type TxnType = 'pay' | 'keyreg' | 'acfg' | 'axfer' | 'afrz' | 'appl' | 'stpf';
27
+ export type DecodedTransaction = {
28
28
  amt: number;
29
29
  fee: number;
30
30
  fv: number;
@@ -37,8 +37,8 @@ export declare type DecodedTransaction = {
37
37
  snd: Uint8Array;
38
38
  type: TxnType;
39
39
  };
40
- export declare type DecodedSignedTransaction = {
40
+ export type DecodedSignedTransaction = {
41
41
  sig: Uint8Array;
42
42
  txn: DecodedTransaction;
43
43
  };
44
- export declare type AlgodClientOptions = ConstructorParameters<typeof algosdk.Algodv2>;
44
+ export type AlgodClientOptions = ConstructorParameters<typeof algosdk.Algodv2>;
@@ -1,9 +1,9 @@
1
- import { PROVIDER_ID } from '../constants';
1
+ import type { PROVIDER_ID } from '../constants';
2
2
  import type { PeraWalletConnect } from '@perawallet/connect';
3
3
  import type { DeflyWalletConnect } from '@blockshake/defly-connect';
4
4
  import type { DaffiWalletConnect } from '@daffiwallet/connect';
5
5
  import type MyAlgoConnect from '@randlabs/myalgo-connect';
6
- import type { Web3ModalSign, Web3ModalSignOptions } from '@web3modal/sign-html';
6
+ import type { WalletConnectModalSign, WalletConnectModalSignOptions } from '@walletconnect/modal-sign-html';
7
7
  import type algosdk from 'algosdk';
8
8
  import type { AlgodClientOptions, Network } from './node';
9
9
  import type { PeraWalletConnectOptions } from '../clients/pera/types';
@@ -13,7 +13,8 @@ import type { KmdOptions } from '../clients/kmd/types';
13
13
  import type { MyAlgoConnectOptions } from '../clients/myalgo/types';
14
14
  import type { DaffiWalletConnectOptions } from '../clients/daffi/types';
15
15
  import type { NonEmptyArray } from './utilities';
16
- export declare type ProviderConfigMapping = {
16
+ import type BaseClient from '../clients/base';
17
+ export type ProviderConfigMapping = {
17
18
  [PROVIDER_ID.PERA]: {
18
19
  clientOptions?: PeraWalletConnectOptions;
19
20
  clientStatic?: typeof PeraWalletConnect;
@@ -27,8 +28,8 @@ export declare type ProviderConfigMapping = {
27
28
  clientStatic?: typeof DeflyWalletConnect;
28
29
  };
29
30
  [PROVIDER_ID.WALLETCONNECT]: {
30
- clientOptions?: Web3ModalSignOptions;
31
- clientStatic?: typeof Web3ModalSign;
31
+ clientOptions?: WalletConnectModalSignOptions;
32
+ clientStatic?: typeof WalletConnectModalSign;
32
33
  };
33
34
  [PROVIDER_ID.MYALGO]: {
34
35
  clientOptions?: MyAlgoConnectOptions;
@@ -36,12 +37,20 @@ export declare type ProviderConfigMapping = {
36
37
  };
37
38
  [PROVIDER_ID.EXODUS]: {
38
39
  clientOptions?: ExodusOptions;
40
+ clientStatic?: undefined;
39
41
  };
40
42
  [PROVIDER_ID.KMD]: {
41
43
  clientOptions?: KmdOptions;
44
+ clientStatic?: undefined;
45
+ };
46
+ [PROVIDER_ID.ALGOSIGNER]: {
47
+ clientOptions?: undefined;
48
+ clientStatic?: undefined;
49
+ };
50
+ [PROVIDER_ID.MNEMONIC]: {
51
+ clientOptions?: undefined;
52
+ clientStatic?: undefined;
42
53
  };
43
- [PROVIDER_ID.ALGOSIGNER]: Record<string, never>;
44
- [PROVIDER_ID.MNEMONIC]: Record<string, never>;
45
54
  };
46
55
  /**
47
56
  * Enforces correct configuration given for each provider. For example,
@@ -50,34 +59,37 @@ export declare type ProviderConfigMapping = {
50
59
  *
51
60
  * @todo install `tsd` to test TypeScript type definitions in CI
52
61
  */
53
- export declare type ProviderConfig<T extends keyof ProviderConfigMapping> = {
62
+ export type ProviderConfig<T extends keyof ProviderConfigMapping> = {
54
63
  [K in T]: {
55
64
  id: K;
56
65
  } & ProviderConfigMapping[K];
57
66
  }[T];
58
- export declare type CommonInitParams = {
67
+ export type CommonInitParams = {
59
68
  network?: Network;
60
69
  algodOptions?: AlgodClientOptions;
61
70
  algosdkStatic?: typeof algosdk;
62
71
  };
63
- export declare type NodeConfig = {
72
+ export type InitParams<T extends keyof ProviderConfigMapping> = CommonInitParams & ProviderConfigMapping[T];
73
+ export type NodeConfig = {
64
74
  network: Network;
65
75
  nodeServer: string;
66
- nodeToken?: string;
76
+ nodeToken?: string | algosdk.AlgodTokenHeader | algosdk.CustomTokenHeader | algosdk.BaseHTTPClient;
67
77
  nodePort?: string | number;
68
78
  nodeHeaders?: Record<string, string>;
69
79
  };
70
- declare type ProviderDef = (ProviderConfig<PROVIDER_ID.PERA> & {
80
+ type ProviderDef = (ProviderConfig<PROVIDER_ID.PERA> & {
71
81
  clientStatic: typeof PeraWalletConnect;
72
82
  }) | (ProviderConfig<PROVIDER_ID.DEFLY> & {
73
83
  clientStatic: typeof DeflyWalletConnect;
74
84
  }) | (ProviderConfig<PROVIDER_ID.DAFFI> & {
75
85
  clientStatic: typeof DaffiWalletConnect;
76
86
  }) | (ProviderConfig<PROVIDER_ID.WALLETCONNECT> & {
77
- clientStatic: typeof Web3ModalSign;
78
- clientOptions: Web3ModalSignOptions;
87
+ clientStatic: typeof WalletConnectModalSign;
88
+ clientOptions: WalletConnectModalSignOptions;
79
89
  }) | (ProviderConfig<PROVIDER_ID.MYALGO> & {
80
90
  clientStatic: typeof MyAlgoConnect;
81
91
  }) | ProviderConfig<PROVIDER_ID.EXODUS> | ProviderConfig<PROVIDER_ID.KMD> | PROVIDER_ID.EXODUS | PROVIDER_ID.KMD | PROVIDER_ID.ALGOSIGNER | PROVIDER_ID.MNEMONIC;
82
- export declare type ProvidersArray = NonEmptyArray<ProviderDef>;
92
+ export type ProvidersArray = NonEmptyArray<ProviderDef>;
93
+ export type WalletClient = BaseClient;
94
+ export type SupportedProviders = Partial<Record<PROVIDER_ID, WalletClient | null>>;
83
95
  export {};
@@ -1 +1 @@
1
- export declare type NonEmptyArray<T> = [T, ...T[]];
1
+ export type NonEmptyArray<T> = [T, ...T[]];
@@ -1,12 +1,11 @@
1
- import { PROVIDER_ID } from '../constants';
2
- import type BaseClient from '../clients/base';
1
+ import type { PROVIDER_ID } from '../constants';
3
2
  export interface Account {
4
3
  providerId: PROVIDER_ID;
5
4
  name: string;
6
5
  address: string;
7
6
  authAddr?: string;
8
7
  }
9
- export declare type Provider = {
8
+ export type Provider = {
10
9
  accounts: Account[];
11
10
  isActive: boolean;
12
11
  isConnected: boolean;
@@ -17,7 +16,7 @@ export declare type Provider = {
17
16
  setActiveAccount: (account: string) => void;
18
17
  metadata: Metadata;
19
18
  };
20
- export declare type Asset = {
19
+ export type Asset = {
21
20
  amount: number;
22
21
  'asset-id': number;
23
22
  creator: string;
@@ -25,32 +24,30 @@ export declare type Asset = {
25
24
  'unit-name': string;
26
25
  name: string;
27
26
  };
28
- export declare type AccountInfo = {
27
+ export type AccountInfo = {
29
28
  address: string;
30
29
  amount: number;
31
30
  'min-balance': number;
32
31
  'auth-addr'?: string;
33
32
  assets?: Asset[];
34
33
  };
35
- export declare type WalletProvider = {
34
+ export type WalletProvider = {
36
35
  id: PROVIDER_ID;
37
36
  name: string;
38
37
  icon: string;
39
38
  isWalletConnect: boolean;
40
39
  };
41
- declare type ExtendValues<Type> = {
40
+ type ExtendValues<Type> = {
42
41
  [Property in keyof Type]: Type[Property] | null;
43
42
  };
44
- export declare type Wallet = ExtendValues<WalletProvider> & {
43
+ export type Wallet = ExtendValues<WalletProvider> & {
45
44
  accounts: Account[];
46
45
  };
47
- export declare type Metadata = {
46
+ export type Metadata = {
48
47
  id: PROVIDER_ID;
49
48
  name: string;
50
49
  icon: string;
51
50
  isWalletConnect: boolean;
52
51
  };
53
- export declare type ClientOptions = Record<string, any>;
54
- export declare type WalletClient = BaseClient;
55
- export declare type SupportedProviders = Partial<Record<PROVIDER_ID, WalletClient | null>>;
52
+ export type ClientOptions = Record<string, any>;
56
53
  export {};
@@ -1,2 +1,2 @@
1
- export declare type NFDTransactionsArray = ['u' | 's', string][];
1
+ export type NFDTransactionsArray = ['u' | 's', string][];
2
2
  export declare function encodeNFDTransactionsArray(transactionsArray: NFDTransactionsArray): Uint8Array[];
@@ -1,2 +1,2 @@
1
- import type { SupportedProviders } from '../types';
1
+ import type { SupportedProviders } from '../types/providers';
2
2
  export declare const reconnectProviders: (providers: SupportedProviders) => Promise<void>;