@txnlab/use-wallet 2.3.0 → 2.3.1
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/dist/cjs/index.js +15 -14
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/src/context/WalletContext.d.ts +8 -0
- package/dist/cjs/src/index.d.ts +1 -1
- package/dist/cjs/src/store/index.d.ts +0 -1
- package/dist/esm/index.js +15 -14
- package/dist/esm/src/context/WalletContext.d.ts +8 -0
- package/dist/esm/src/index.d.ts +1 -1
- package/dist/esm/src/store/index.d.ts +0 -1
- package/dist/index.d.ts +35 -31
- package/package.json +1 -1
- package/dist/cjs/src/store/state/clientStore.d.ts +0 -5
- package/dist/cjs/src/testUtils/createWrapper.d.ts +0 -6
- package/dist/esm/src/store/state/clientStore.d.ts +0 -5
- package/dist/esm/src/testUtils/createWrapper.d.ts +0 -6
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { SupportedProviders } from '../types/providers';
|
|
3
|
+
export declare const useWalletContext: () => SupportedProviders | null;
|
|
4
|
+
export interface WalletProviderProps {
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
value: SupportedProviders | null;
|
|
7
|
+
}
|
|
8
|
+
export declare const WalletProvider: ({ children, value }: WalletProviderProps) => React.JSX.Element;
|
package/dist/cjs/src/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1360,9 +1360,6 @@ const useDebugStore = create((set) => ({
|
|
|
1360
1360
|
setDebug: (debug) => set({ debug })
|
|
1361
1361
|
}));
|
|
1362
1362
|
|
|
1363
|
-
const ClientContext = createContext(null);
|
|
1364
|
-
var clientStore = ClientContext.Provider;
|
|
1365
|
-
|
|
1366
1363
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1367
1364
|
const debugLog = (...args) => {
|
|
1368
1365
|
const { debug } = useDebugStore.getState();
|
|
@@ -2939,6 +2936,18 @@ function encodeNFDTransactionsArray(transactionsArray) {
|
|
|
2939
2936
|
});
|
|
2940
2937
|
}
|
|
2941
2938
|
|
|
2939
|
+
const WalletContext = createContext(null);
|
|
2940
|
+
const useWalletContext = () => {
|
|
2941
|
+
const context = useContext(WalletContext);
|
|
2942
|
+
if (context === undefined) {
|
|
2943
|
+
throw new Error('useWallet must be used within the WalletProvider');
|
|
2944
|
+
}
|
|
2945
|
+
return context;
|
|
2946
|
+
};
|
|
2947
|
+
const WalletProvider = ({ children, value }) => {
|
|
2948
|
+
return require$$0.createElement(WalletContext.Provider, { value: value }, children);
|
|
2949
|
+
};
|
|
2950
|
+
|
|
2942
2951
|
function shallow(objA, objB) {
|
|
2943
2952
|
if (Object.is(objA, objB)) {
|
|
2944
2953
|
return true;
|
|
@@ -2977,19 +2986,11 @@ function shallow(objA, objB) {
|
|
|
2977
2986
|
}
|
|
2978
2987
|
return true;
|
|
2979
2988
|
}
|
|
2980
|
-
var shallow$1 = (objA, objB) => {
|
|
2981
|
-
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
|
|
2982
|
-
console.warn(
|
|
2983
|
-
"[DEPRECATED] Default export is deprecated. Instead use `import { shallow } from 'zustand/shallow'`."
|
|
2984
|
-
);
|
|
2985
|
-
}
|
|
2986
|
-
return shallow(objA, objB);
|
|
2987
|
-
};
|
|
2988
2989
|
|
|
2989
2990
|
function useWallet() {
|
|
2990
2991
|
const [providers, setProviders] = useState(null);
|
|
2991
|
-
const clients =
|
|
2992
|
-
const { activeAccount, accounts: connectedAccounts, setActiveAccount: _setActiveAccount, addAccounts } = useHydratedWalletStore(walletStoreSelector, shallow
|
|
2992
|
+
const clients = useWalletContext();
|
|
2993
|
+
const { activeAccount, accounts: connectedAccounts, setActiveAccount: _setActiveAccount, addAccounts } = useHydratedWalletStore(walletStoreSelector, shallow);
|
|
2993
2994
|
const getAccountsByProvider = (id) => {
|
|
2994
2995
|
return connectedAccounts.filter((account) => account.providerId === id);
|
|
2995
2996
|
};
|
|
@@ -3192,4 +3193,4 @@ function useInitializeProviders({ providers, nodeConfig, algosdkStatic, debug =
|
|
|
3192
3193
|
return walletProviders;
|
|
3193
3194
|
}
|
|
3194
3195
|
|
|
3195
|
-
export { DEFAULT_NETWORK, DEFAULT_NODE_BASEURL, DEFAULT_NODE_PORT, DEFAULT_NODE_TOKEN, PROVIDER_ID,
|
|
3196
|
+
export { DEFAULT_NETWORK, DEFAULT_NODE_BASEURL, DEFAULT_NODE_PORT, DEFAULT_NODE_TOKEN, PROVIDER_ID, 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 };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { SupportedProviders } from '../types/providers';
|
|
3
|
+
export declare const useWalletContext: () => SupportedProviders | null;
|
|
4
|
+
export interface WalletProviderProps {
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
value: SupportedProviders | null;
|
|
7
|
+
}
|
|
8
|
+
export declare const WalletProvider: ({ children, value }: WalletProviderProps) => React.JSX.Element;
|
package/dist/esm/src/index.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { DeflyWalletConnect } from '@blockshake/defly-connect';
|
|
|
4
4
|
import { DaffiWalletConnect } from '@daffiwallet/connect';
|
|
5
5
|
import MyAlgoConnect from '@randlabs/myalgo-connect';
|
|
6
6
|
import { WalletConnectModalSignOptions, WalletConnectModalSign } from '@walletconnect/modal-sign-html';
|
|
7
|
-
import
|
|
7
|
+
import React from 'react';
|
|
8
8
|
import * as zustand_middleware from 'zustand/middleware';
|
|
9
9
|
import * as immer_dist_internal from 'immer/dist/internal';
|
|
10
10
|
import * as zustand from 'zustand';
|
|
@@ -116,7 +116,7 @@ type AccountInfo = {
|
|
|
116
116
|
'auth-addr'?: string;
|
|
117
117
|
assets?: Asset[];
|
|
118
118
|
};
|
|
119
|
-
type WalletProvider = {
|
|
119
|
+
type WalletProvider$1 = {
|
|
120
120
|
id: PROVIDER_ID;
|
|
121
121
|
name: string;
|
|
122
122
|
icon: string;
|
|
@@ -125,7 +125,7 @@ type WalletProvider = {
|
|
|
125
125
|
type ExtendValues<Type> = {
|
|
126
126
|
[Property in keyof Type]: Type[Property] | null;
|
|
127
127
|
};
|
|
128
|
-
type Wallet = ExtendValues<WalletProvider> & {
|
|
128
|
+
type Wallet = ExtendValues<WalletProvider$1> & {
|
|
129
129
|
accounts: Account[];
|
|
130
130
|
};
|
|
131
131
|
type Metadata = {
|
|
@@ -402,33 +402,11 @@ declare const reconnectProviders: (providers: SupportedProviders) => Promise<voi
|
|
|
402
402
|
type NFDTransactionsArray = ['u' | 's', string][];
|
|
403
403
|
declare function encodeNFDTransactionsArray(transactionsArray: NFDTransactionsArray): Uint8Array[];
|
|
404
404
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
addAccounts: (accounts: Account[]) => void;
|
|
411
|
-
removeAccounts: (providerId: PROVIDER_ID) => void;
|
|
412
|
-
};
|
|
413
|
-
declare const useWalletStore: zustand.UseBoundStore<Omit<Omit<Omit<zustand.StoreApi<WalletStore>, "setState"> & {
|
|
414
|
-
setState(nextStateOrUpdater: WalletStore | Partial<WalletStore> | ((state: immer_dist_internal.WritableDraft<WalletStore>) => void), shouldReplace?: boolean | undefined): void;
|
|
415
|
-
}, "persist"> & {
|
|
416
|
-
persist: {
|
|
417
|
-
setOptions: (options: Partial<zustand_middleware.PersistOptions<WalletStore, WalletStore>>) => void;
|
|
418
|
-
clearStorage: () => void;
|
|
419
|
-
rehydrate: () => void | Promise<void>;
|
|
420
|
-
hasHydrated: () => boolean;
|
|
421
|
-
onHydrate: (fn: (state: WalletStore) => void) => () => void;
|
|
422
|
-
onFinishHydration: (fn: (state: WalletStore) => void) => () => void;
|
|
423
|
-
getOptions: () => Partial<zustand_middleware.PersistOptions<WalletStore, WalletStore>>;
|
|
424
|
-
};
|
|
425
|
-
}, "setState"> & {
|
|
426
|
-
setState<A extends string | {
|
|
427
|
-
type: unknown;
|
|
428
|
-
}>(nextStateOrUpdater: WalletStore | Partial<WalletStore> | ((state: immer_dist_internal.WritableDraft<WalletStore>) => void), shouldReplace?: boolean | undefined, action?: A | undefined): void;
|
|
429
|
-
}>;
|
|
430
|
-
|
|
431
|
-
declare const _default: react.Provider<Partial<Record<PROVIDER_ID, BaseClient | null>> | null>;
|
|
405
|
+
interface WalletProviderProps {
|
|
406
|
+
children: React.ReactNode;
|
|
407
|
+
value: SupportedProviders | null;
|
|
408
|
+
}
|
|
409
|
+
declare const WalletProvider: ({ children, value }: WalletProviderProps) => React.JSX.Element;
|
|
432
410
|
|
|
433
411
|
declare class PeraWalletClient extends BaseClient {
|
|
434
412
|
#private;
|
|
@@ -542,6 +520,32 @@ declare class ExodusClient extends BaseClient {
|
|
|
542
520
|
signTransactions(connectedAccounts: string[], txnGroups: Uint8Array[] | Uint8Array[][], indexesToSign?: number[], returnGroup?: boolean): Promise<Uint8Array[]>;
|
|
543
521
|
}
|
|
544
522
|
|
|
523
|
+
type WalletStore = {
|
|
524
|
+
accounts: Account[];
|
|
525
|
+
activeAccount: Account | null | undefined;
|
|
526
|
+
setActiveAccount: (account: Account) => void;
|
|
527
|
+
clearActiveAccount: (id: PROVIDER_ID) => void;
|
|
528
|
+
addAccounts: (accounts: Account[]) => void;
|
|
529
|
+
removeAccounts: (providerId: PROVIDER_ID) => void;
|
|
530
|
+
};
|
|
531
|
+
declare const useWalletStore: zustand.UseBoundStore<Omit<Omit<Omit<zustand.StoreApi<WalletStore>, "setState"> & {
|
|
532
|
+
setState(nextStateOrUpdater: WalletStore | Partial<WalletStore> | ((state: immer_dist_internal.WritableDraft<WalletStore>) => void), shouldReplace?: boolean | undefined): void;
|
|
533
|
+
}, "persist"> & {
|
|
534
|
+
persist: {
|
|
535
|
+
setOptions: (options: Partial<zustand_middleware.PersistOptions<WalletStore, WalletStore>>) => void;
|
|
536
|
+
clearStorage: () => void;
|
|
537
|
+
rehydrate: () => void | Promise<void>;
|
|
538
|
+
hasHydrated: () => boolean;
|
|
539
|
+
onHydrate: (fn: (state: WalletStore) => void) => () => void;
|
|
540
|
+
onFinishHydration: (fn: (state: WalletStore) => void) => () => void;
|
|
541
|
+
getOptions: () => Partial<zustand_middleware.PersistOptions<WalletStore, WalletStore>>;
|
|
542
|
+
};
|
|
543
|
+
}, "setState"> & {
|
|
544
|
+
setState<A extends string | {
|
|
545
|
+
type: unknown;
|
|
546
|
+
}>(nextStateOrUpdater: WalletStore | Partial<WalletStore> | ((state: immer_dist_internal.WritableDraft<WalletStore>) => void), shouldReplace?: boolean | undefined, action?: A | undefined): void;
|
|
547
|
+
}>;
|
|
548
|
+
|
|
545
549
|
type GenesisId = 'betanet-v1.0' | 'testnet-v1.0' | 'mainnet-v1.0' | string;
|
|
546
550
|
type EnableParams = {
|
|
547
551
|
genesisID?: GenesisId;
|
|
@@ -755,4 +759,4 @@ interface InitializeProvidersOptions {
|
|
|
755
759
|
}
|
|
756
760
|
declare function useInitializeProviders({ providers, nodeConfig, algosdkStatic, debug }: InitializeProvidersOptions): Partial<Record<PROVIDER_ID, BaseClient | null>> | null;
|
|
757
761
|
|
|
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,
|
|
762
|
+
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, 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,7 +12,7 @@
|
|
|
12
12
|
"url": "https://github.com/txnlab/use-wallet/issues"
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://txnlab.github.io/use-wallet",
|
|
15
|
-
"version": "2.3.
|
|
15
|
+
"version": "2.3.1",
|
|
16
16
|
"description": "React hooks for using Algorand compatible wallets in dApps.",
|
|
17
17
|
"scripts": {
|
|
18
18
|
"dev": "yarn storybook",
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
declare const ClientContext: import("react").Context<Partial<Record<import("../..").PROVIDER_ID, import("../../clients/base/base").default | null>> | null>;
|
|
3
|
-
export { ClientContext };
|
|
4
|
-
declare const _default: import("react").Provider<Partial<Record<import("../..").PROVIDER_ID, import("../../clients/base/base").default | null>> | null>;
|
|
5
|
-
export default _default;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
declare const ClientContext: import("react").Context<Partial<Record<import("../..").PROVIDER_ID, import("../../clients/base/base").default | null>> | null>;
|
|
3
|
-
export { ClientContext };
|
|
4
|
-
declare const _default: import("react").Provider<Partial<Record<import("../..").PROVIDER_ID, import("../../clients/base/base").default | null>> | null>;
|
|
5
|
-
export default _default;
|