@txnlab/use-wallet 3.1.3 → 3.1.5
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/index.cjs +53 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +53 -36
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -345,7 +345,7 @@ interface SignClientOptions {
|
|
|
345
345
|
}
|
|
346
346
|
type WalletConnectModalOptions = Pick<WalletConnectModalConfig, 'enableExplorer' | 'explorerRecommendedWalletIds' | 'privacyPolicyUrl' | 'termsOfServiceUrl' | 'themeMode' | 'themeVariables'>;
|
|
347
347
|
type WalletConnectOptions = SignClientOptions & WalletConnectModalOptions;
|
|
348
|
-
type SignTxnsResponse = Array<Uint8Array | string | null | undefined>;
|
|
348
|
+
type SignTxnsResponse = Array<Uint8Array | number[] | string | null | undefined>;
|
|
349
349
|
declare class SessionError extends Error {
|
|
350
350
|
constructor(message: string);
|
|
351
351
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -345,7 +345,7 @@ interface SignClientOptions {
|
|
|
345
345
|
}
|
|
346
346
|
type WalletConnectModalOptions = Pick<WalletConnectModalConfig, 'enableExplorer' | 'explorerRecommendedWalletIds' | 'privacyPolicyUrl' | 'termsOfServiceUrl' | 'themeMode' | 'themeVariables'>;
|
|
347
347
|
type WalletConnectOptions = SignClientOptions & WalletConnectModalOptions;
|
|
348
|
-
type SignTxnsResponse = Array<Uint8Array | string | null | undefined>;
|
|
348
|
+
type SignTxnsResponse = Array<Uint8Array | number[] | string | null | undefined>;
|
|
349
349
|
declare class SessionError extends Error {
|
|
350
350
|
constructor(message: string);
|
|
351
351
|
}
|
package/dist/index.js
CHANGED
|
@@ -3439,6 +3439,9 @@ var StorageAdapter = class {
|
|
|
3439
3439
|
}
|
|
3440
3440
|
};
|
|
3441
3441
|
|
|
3442
|
+
// src/store.ts
|
|
3443
|
+
import { Algodv2 } from "algosdk";
|
|
3444
|
+
|
|
3442
3445
|
// src/wallets/base.ts
|
|
3443
3446
|
var BaseWallet = class {
|
|
3444
3447
|
id;
|
|
@@ -5588,7 +5591,17 @@ var WalletConnect = class extends BaseWallet {
|
|
|
5588
5591
|
});
|
|
5589
5592
|
const signedTxns = signTxnsResult.reduce((acc, value) => {
|
|
5590
5593
|
if (value) {
|
|
5591
|
-
|
|
5594
|
+
let signedTxn;
|
|
5595
|
+
if (typeof value === "string") {
|
|
5596
|
+
signedTxn = base64ToByteArray(value);
|
|
5597
|
+
} else if (value instanceof Uint8Array) {
|
|
5598
|
+
signedTxn = value;
|
|
5599
|
+
} else if (Array.isArray(value)) {
|
|
5600
|
+
signedTxn = new Uint8Array(value);
|
|
5601
|
+
} else {
|
|
5602
|
+
console.warn(`[${this.metadata.name}] Unexpected type in signTxnsResult`, value);
|
|
5603
|
+
signedTxn = new Uint8Array();
|
|
5604
|
+
}
|
|
5592
5605
|
acc.push(signedTxn);
|
|
5593
5606
|
}
|
|
5594
5607
|
return acc;
|
|
@@ -5823,7 +5836,6 @@ var CustomWallet = class extends BaseWallet {
|
|
|
5823
5836
|
};
|
|
5824
5837
|
|
|
5825
5838
|
// src/store.ts
|
|
5826
|
-
import { Algodv2 } from "algosdk";
|
|
5827
5839
|
var defaultState = {
|
|
5828
5840
|
wallets: {},
|
|
5829
5841
|
activeWallet: null,
|
|
@@ -5833,56 +5845,61 @@ var defaultState = {
|
|
|
5833
5845
|
var LOCAL_STORAGE_KEY = "@txnlab/use-wallet:v3";
|
|
5834
5846
|
function addWallet(store, { walletId, wallet }) {
|
|
5835
5847
|
store.setState((state) => {
|
|
5836
|
-
const
|
|
5848
|
+
const updatedWallets = {
|
|
5837
5849
|
...state.wallets,
|
|
5838
|
-
[walletId]:
|
|
5850
|
+
[walletId]: {
|
|
5851
|
+
accounts: wallet.accounts.map((account) => ({ ...account })),
|
|
5852
|
+
activeAccount: wallet.activeAccount ? { ...wallet.activeAccount } : null
|
|
5853
|
+
}
|
|
5839
5854
|
};
|
|
5840
5855
|
return {
|
|
5841
5856
|
...state,
|
|
5842
|
-
wallets:
|
|
5857
|
+
wallets: updatedWallets,
|
|
5843
5858
|
activeWallet: walletId
|
|
5844
5859
|
};
|
|
5845
5860
|
});
|
|
5846
5861
|
}
|
|
5847
5862
|
function removeWallet(store, { walletId }) {
|
|
5848
5863
|
store.setState((state) => {
|
|
5849
|
-
const
|
|
5850
|
-
delete
|
|
5864
|
+
const updatedWallets = { ...state.wallets };
|
|
5865
|
+
delete updatedWallets[walletId];
|
|
5851
5866
|
return {
|
|
5852
5867
|
...state,
|
|
5853
|
-
wallets:
|
|
5868
|
+
wallets: updatedWallets,
|
|
5854
5869
|
activeWallet: state.activeWallet === walletId ? null : state.activeWallet
|
|
5855
5870
|
};
|
|
5856
5871
|
});
|
|
5857
5872
|
}
|
|
5858
5873
|
function setActiveWallet(store, { walletId }) {
|
|
5859
|
-
store.setState((state) => {
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
};
|
|
5864
|
-
});
|
|
5874
|
+
store.setState((state) => ({
|
|
5875
|
+
...state,
|
|
5876
|
+
activeWallet: walletId
|
|
5877
|
+
}));
|
|
5865
5878
|
}
|
|
5866
5879
|
function setActiveAccount(store, { walletId, address }) {
|
|
5867
5880
|
store.setState((state) => {
|
|
5868
5881
|
const wallet = state.wallets[walletId];
|
|
5869
5882
|
if (!wallet) {
|
|
5883
|
+
console.warn(`Wallet with id "${walletId}" not found`);
|
|
5870
5884
|
return state;
|
|
5871
5885
|
}
|
|
5872
|
-
const
|
|
5873
|
-
if (!
|
|
5886
|
+
const newActiveAccount = wallet.accounts.find((a2) => a2.address === address);
|
|
5887
|
+
if (!newActiveAccount) {
|
|
5888
|
+
console.warn(`Account with address ${address} not found in wallet "${walletId}"`);
|
|
5874
5889
|
return state;
|
|
5875
5890
|
}
|
|
5876
|
-
const
|
|
5891
|
+
const updatedWallet = {
|
|
5892
|
+
...wallet,
|
|
5893
|
+
accounts: wallet.accounts.map((account) => ({ ...account })),
|
|
5894
|
+
activeAccount: { ...newActiveAccount }
|
|
5895
|
+
};
|
|
5896
|
+
const updatedWallets = {
|
|
5877
5897
|
...state.wallets,
|
|
5878
|
-
[walletId]:
|
|
5879
|
-
...wallet,
|
|
5880
|
-
activeAccount
|
|
5881
|
-
}
|
|
5898
|
+
[walletId]: updatedWallet
|
|
5882
5899
|
};
|
|
5883
5900
|
return {
|
|
5884
5901
|
...state,
|
|
5885
|
-
wallets:
|
|
5902
|
+
wallets: updatedWallets
|
|
5886
5903
|
};
|
|
5887
5904
|
});
|
|
5888
5905
|
}
|
|
@@ -5890,34 +5907,34 @@ function setAccounts(store, { walletId, accounts }) {
|
|
|
5890
5907
|
store.setState((state) => {
|
|
5891
5908
|
const wallet = state.wallets[walletId];
|
|
5892
5909
|
if (!wallet) {
|
|
5910
|
+
console.warn(`Wallet with id "${walletId}" not found`);
|
|
5893
5911
|
return state;
|
|
5894
5912
|
}
|
|
5895
|
-
const
|
|
5913
|
+
const newAccounts = accounts.map((account) => ({ ...account }));
|
|
5914
|
+
const isActiveAccountConnected = newAccounts.some(
|
|
5896
5915
|
(account) => account.address === wallet.activeAccount?.address
|
|
5897
5916
|
);
|
|
5898
|
-
const
|
|
5899
|
-
const
|
|
5917
|
+
const newActiveAccount = isActiveAccountConnected ? { ...wallet.activeAccount } : newAccounts[0] || null;
|
|
5918
|
+
const updatedWallet = {
|
|
5900
5919
|
...wallet,
|
|
5901
|
-
accounts,
|
|
5902
|
-
activeAccount
|
|
5920
|
+
accounts: newAccounts,
|
|
5921
|
+
activeAccount: newActiveAccount
|
|
5903
5922
|
};
|
|
5904
|
-
const
|
|
5923
|
+
const updatedWallets = {
|
|
5905
5924
|
...state.wallets,
|
|
5906
|
-
[walletId]:
|
|
5925
|
+
[walletId]: updatedWallet
|
|
5907
5926
|
};
|
|
5908
5927
|
return {
|
|
5909
5928
|
...state,
|
|
5910
|
-
wallets:
|
|
5929
|
+
wallets: updatedWallets
|
|
5911
5930
|
};
|
|
5912
5931
|
});
|
|
5913
5932
|
}
|
|
5914
5933
|
function setActiveNetwork(store, { networkId }) {
|
|
5915
|
-
store.setState((state) => {
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
};
|
|
5920
|
-
});
|
|
5934
|
+
store.setState((state) => ({
|
|
5935
|
+
...state,
|
|
5936
|
+
activeNetwork: networkId
|
|
5937
|
+
}));
|
|
5921
5938
|
}
|
|
5922
5939
|
function isValidWalletId(walletId) {
|
|
5923
5940
|
return Object.values(WalletId).includes(walletId);
|