@txnlab/use-wallet 2.2.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/README.md +1 -1
- package/dist/cjs/index.js +28 -17
- 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 +28 -17
- 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();
|
|
@@ -2633,13 +2630,23 @@ class KMDWalletClient extends BaseClient {
|
|
|
2633
2630
|
return;
|
|
2634
2631
|
}
|
|
2635
2632
|
// Not to be signed by our signer, skip it
|
|
2636
|
-
else
|
|
2637
|
-
|
|
2633
|
+
else {
|
|
2634
|
+
const senderAddress = this.algosdk.encodeAddress(dtxn.snd);
|
|
2635
|
+
const rekeyAddress = dtxn.rekey ? this.algosdk.encodeAddress(dtxn.rekey) : null;
|
|
2636
|
+
const isSignerConnected = rekeyAddress
|
|
2637
|
+
? connectedAccounts.includes(rekeyAddress) && connectedAccounts.includes(senderAddress)
|
|
2638
|
+
: connectedAccounts.includes(senderAddress);
|
|
2639
|
+
if (!isSignerConnected) {
|
|
2640
|
+
return;
|
|
2641
|
+
}
|
|
2638
2642
|
}
|
|
2639
2643
|
// overwrite with an empty blob
|
|
2640
2644
|
signedTxns[idx] = new Uint8Array();
|
|
2641
2645
|
const txn = this.algosdk.Transaction.from_obj_for_encoding(dtxn);
|
|
2642
|
-
|
|
2646
|
+
const promise = txn.reKeyTo
|
|
2647
|
+
? this.#client.signTransactionWithSpecificPublicKey(token, pw, txn, txn.reKeyTo.publicKey)
|
|
2648
|
+
: this.#client.signTransaction(token, pw, txn);
|
|
2649
|
+
signingPromises.push(promise);
|
|
2643
2650
|
});
|
|
2644
2651
|
const signingResults = await Promise.all(signingPromises);
|
|
2645
2652
|
// Restore the newly signed txns in the correct order
|
|
@@ -2929,6 +2936,18 @@ function encodeNFDTransactionsArray(transactionsArray) {
|
|
|
2929
2936
|
});
|
|
2930
2937
|
}
|
|
2931
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
|
+
|
|
2932
2951
|
function shallow(objA, objB) {
|
|
2933
2952
|
if (Object.is(objA, objB)) {
|
|
2934
2953
|
return true;
|
|
@@ -2967,19 +2986,11 @@ function shallow(objA, objB) {
|
|
|
2967
2986
|
}
|
|
2968
2987
|
return true;
|
|
2969
2988
|
}
|
|
2970
|
-
var shallow$1 = (objA, objB) => {
|
|
2971
|
-
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
|
|
2972
|
-
console.warn(
|
|
2973
|
-
"[DEPRECATED] Default export is deprecated. Instead use `import { shallow } from 'zustand/shallow'`."
|
|
2974
|
-
);
|
|
2975
|
-
}
|
|
2976
|
-
return shallow(objA, objB);
|
|
2977
|
-
};
|
|
2978
2989
|
|
|
2979
2990
|
function useWallet() {
|
|
2980
2991
|
const [providers, setProviders] = useState(null);
|
|
2981
|
-
const clients =
|
|
2982
|
-
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);
|
|
2983
2994
|
const getAccountsByProvider = (id) => {
|
|
2984
2995
|
return connectedAccounts.filter((account) => account.providerId === id);
|
|
2985
2996
|
};
|
|
@@ -3182,4 +3193,4 @@ function useInitializeProviders({ providers, nodeConfig, algosdkStatic, debug =
|
|
|
3182
3193
|
return walletProviders;
|
|
3183
3194
|
}
|
|
3184
3195
|
|
|
3185
|
-
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.
|
|
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;
|