@txnlab/use-wallet 3.1.4 → 3.1.6
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 +43 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +43 -36
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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;
|
|
@@ -5833,7 +5836,6 @@ var CustomWallet = class extends BaseWallet {
|
|
|
5833
5836
|
};
|
|
5834
5837
|
|
|
5835
5838
|
// src/store.ts
|
|
5836
|
-
import { Algodv2 } from "algosdk";
|
|
5837
5839
|
var defaultState = {
|
|
5838
5840
|
wallets: {},
|
|
5839
5841
|
activeWallet: null,
|
|
@@ -5843,56 +5845,61 @@ var defaultState = {
|
|
|
5843
5845
|
var LOCAL_STORAGE_KEY = "@txnlab/use-wallet:v3";
|
|
5844
5846
|
function addWallet(store, { walletId, wallet }) {
|
|
5845
5847
|
store.setState((state) => {
|
|
5846
|
-
const
|
|
5848
|
+
const updatedWallets = {
|
|
5847
5849
|
...state.wallets,
|
|
5848
|
-
[walletId]:
|
|
5850
|
+
[walletId]: {
|
|
5851
|
+
accounts: wallet.accounts.map((account) => ({ ...account })),
|
|
5852
|
+
activeAccount: wallet.activeAccount ? { ...wallet.activeAccount } : null
|
|
5853
|
+
}
|
|
5849
5854
|
};
|
|
5850
5855
|
return {
|
|
5851
5856
|
...state,
|
|
5852
|
-
wallets:
|
|
5857
|
+
wallets: updatedWallets,
|
|
5853
5858
|
activeWallet: walletId
|
|
5854
5859
|
};
|
|
5855
5860
|
});
|
|
5856
5861
|
}
|
|
5857
5862
|
function removeWallet(store, { walletId }) {
|
|
5858
5863
|
store.setState((state) => {
|
|
5859
|
-
const
|
|
5860
|
-
delete
|
|
5864
|
+
const updatedWallets = { ...state.wallets };
|
|
5865
|
+
delete updatedWallets[walletId];
|
|
5861
5866
|
return {
|
|
5862
5867
|
...state,
|
|
5863
|
-
wallets:
|
|
5868
|
+
wallets: updatedWallets,
|
|
5864
5869
|
activeWallet: state.activeWallet === walletId ? null : state.activeWallet
|
|
5865
5870
|
};
|
|
5866
5871
|
});
|
|
5867
5872
|
}
|
|
5868
5873
|
function setActiveWallet(store, { walletId }) {
|
|
5869
|
-
store.setState((state) => {
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
};
|
|
5874
|
-
});
|
|
5874
|
+
store.setState((state) => ({
|
|
5875
|
+
...state,
|
|
5876
|
+
activeWallet: walletId
|
|
5877
|
+
}));
|
|
5875
5878
|
}
|
|
5876
5879
|
function setActiveAccount(store, { walletId, address }) {
|
|
5877
5880
|
store.setState((state) => {
|
|
5878
5881
|
const wallet = state.wallets[walletId];
|
|
5879
5882
|
if (!wallet) {
|
|
5883
|
+
console.warn(`Wallet with id "${walletId}" not found`);
|
|
5880
5884
|
return state;
|
|
5881
5885
|
}
|
|
5882
|
-
const
|
|
5883
|
-
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}"`);
|
|
5884
5889
|
return state;
|
|
5885
5890
|
}
|
|
5886
|
-
const
|
|
5891
|
+
const updatedWallet = {
|
|
5892
|
+
...wallet,
|
|
5893
|
+
accounts: wallet.accounts.map((account) => ({ ...account })),
|
|
5894
|
+
activeAccount: { ...newActiveAccount }
|
|
5895
|
+
};
|
|
5896
|
+
const updatedWallets = {
|
|
5887
5897
|
...state.wallets,
|
|
5888
|
-
[walletId]:
|
|
5889
|
-
...wallet,
|
|
5890
|
-
activeAccount
|
|
5891
|
-
}
|
|
5898
|
+
[walletId]: updatedWallet
|
|
5892
5899
|
};
|
|
5893
5900
|
return {
|
|
5894
5901
|
...state,
|
|
5895
|
-
wallets:
|
|
5902
|
+
wallets: updatedWallets
|
|
5896
5903
|
};
|
|
5897
5904
|
});
|
|
5898
5905
|
}
|
|
@@ -5900,34 +5907,34 @@ function setAccounts(store, { walletId, accounts }) {
|
|
|
5900
5907
|
store.setState((state) => {
|
|
5901
5908
|
const wallet = state.wallets[walletId];
|
|
5902
5909
|
if (!wallet) {
|
|
5910
|
+
console.warn(`Wallet with id "${walletId}" not found`);
|
|
5903
5911
|
return state;
|
|
5904
5912
|
}
|
|
5905
|
-
const
|
|
5913
|
+
const newAccounts = accounts.map((account) => ({ ...account }));
|
|
5914
|
+
const isActiveAccountConnected = newAccounts.some(
|
|
5906
5915
|
(account) => account.address === wallet.activeAccount?.address
|
|
5907
5916
|
);
|
|
5908
|
-
const
|
|
5909
|
-
const
|
|
5917
|
+
const newActiveAccount = isActiveAccountConnected ? { ...wallet.activeAccount } : newAccounts[0] || null;
|
|
5918
|
+
const updatedWallet = {
|
|
5910
5919
|
...wallet,
|
|
5911
|
-
accounts,
|
|
5912
|
-
activeAccount
|
|
5920
|
+
accounts: newAccounts,
|
|
5921
|
+
activeAccount: newActiveAccount
|
|
5913
5922
|
};
|
|
5914
|
-
const
|
|
5923
|
+
const updatedWallets = {
|
|
5915
5924
|
...state.wallets,
|
|
5916
|
-
[walletId]:
|
|
5925
|
+
[walletId]: updatedWallet
|
|
5917
5926
|
};
|
|
5918
5927
|
return {
|
|
5919
5928
|
...state,
|
|
5920
|
-
wallets:
|
|
5929
|
+
wallets: updatedWallets
|
|
5921
5930
|
};
|
|
5922
5931
|
});
|
|
5923
5932
|
}
|
|
5924
5933
|
function setActiveNetwork(store, { networkId }) {
|
|
5925
|
-
store.setState((state) => {
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
};
|
|
5930
|
-
});
|
|
5934
|
+
store.setState((state) => ({
|
|
5935
|
+
...state,
|
|
5936
|
+
activeNetwork: networkId
|
|
5937
|
+
}));
|
|
5931
5938
|
}
|
|
5932
5939
|
function isValidWalletId(walletId) {
|
|
5933
5940
|
return Object.values(WalletId).includes(walletId);
|
|
@@ -5977,7 +5984,7 @@ var WalletManager = class {
|
|
|
5977
5984
|
return unsubscribe;
|
|
5978
5985
|
};
|
|
5979
5986
|
this.networkConfig = this.initNetworkConfig(network, algod);
|
|
5980
|
-
this.algodClient = this.createAlgodClient(this.networkConfig[
|
|
5987
|
+
this.algodClient = this.createAlgodClient(this.networkConfig[initialState.activeNetwork]);
|
|
5981
5988
|
this.initializeWallets(wallets);
|
|
5982
5989
|
}
|
|
5983
5990
|
// ---------- Store ------------------------------------------------- //
|