@d13co/use-wallet 4.5.13 → 4.5.14

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 CHANGED
@@ -8748,23 +8748,33 @@ var AlgoXEvmBaseWallet = class extends BaseWallet {
8748
8748
  const flatTxns = flattenTxnGroup(txnGroup);
8749
8749
  txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
8750
8750
  }
8751
- const firstTxn = txnsToSign[0];
8752
- const algorandAddress = firstTxn.txn.sender.toString();
8753
- let evmAddress = this.evmAddressMap.get(algorandAddress);
8754
- if (!evmAddress) {
8755
- const walletState = this.store.state.wallets[this.id];
8756
- if (walletState) {
8757
- for (const account of walletState.accounts) {
8758
- const addr = account.metadata?.evmAddress;
8759
- if (addr) {
8760
- this.evmAddressMap.set(account.address, addr);
8761
- }
8751
+ const walletState = this.store.state.wallets[this.id];
8752
+ if (walletState) {
8753
+ for (const account of walletState.accounts) {
8754
+ const addr = account.metadata?.evmAddress;
8755
+ if (addr && !this.evmAddressMap.has(account.address)) {
8756
+ this.evmAddressMap.set(account.address, addr);
8762
8757
  }
8763
- evmAddress = this.evmAddressMap.get(algorandAddress);
8764
8758
  }
8765
8759
  }
8766
- if (!evmAddress) {
8767
- throw new Error(`No EVM address found for Algorand address: ${algorandAddress}`);
8760
+ const allTxns = txnsToSign.map((t) => t.txn);
8761
+ const signIndexes = txnsToSign.reduce((acc, t, i) => {
8762
+ if (!("signers" in t)) acc.push(i);
8763
+ return acc;
8764
+ }, []);
8765
+ const evmGroups = /* @__PURE__ */ new Map();
8766
+ for (const idx of signIndexes) {
8767
+ const algorandAddress = allTxns[idx].sender.toString();
8768
+ const evmAddress = this.evmAddressMap.get(algorandAddress);
8769
+ if (!evmAddress) {
8770
+ throw new Error(`No EVM address found for Algorand address: ${algorandAddress}`);
8771
+ }
8772
+ const group = evmGroups.get(evmAddress);
8773
+ if (group) {
8774
+ group.push(idx);
8775
+ } else {
8776
+ evmGroups.set(evmAddress, [idx]);
8777
+ }
8768
8778
  }
8769
8779
  const onBeforeSign = this.options.uiHooks?.onBeforeSign ?? this.managerUIHooks?.onBeforeSign;
8770
8780
  if (onBeforeSign) {
@@ -8772,16 +8782,18 @@ var AlgoXEvmBaseWallet = class extends BaseWallet {
8772
8782
  const txnsAsUint8 = txnsToSign.map(({ txn }) => import_algosdk11.default.encodeUnsignedTransaction(txn));
8773
8783
  await onBeforeSign(txnsAsUint8, indexesToSign);
8774
8784
  }
8775
- const { signer: evmSigner } = await algoXEvmSdk.getSigner({
8776
- evmAddress,
8777
- signMessage: (typedData) => this.signWithProvider(typedData, evmAddress)
8778
- });
8779
- const allTxns = txnsToSign.map((t) => t.txn);
8780
- const signIndexes = txnsToSign.reduce((acc, t, i) => {
8781
- if (!("signers" in t)) acc.push(i);
8782
- return acc;
8783
- }, []);
8784
- const signedBlobs = await evmSigner(allTxns, signIndexes);
8785
+ const signedResult = new Array(txnsToSign.length).fill(null);
8786
+ console.log("EVM Groups for signing:", evmGroups);
8787
+ for (const [evmAddress, indexes] of evmGroups) {
8788
+ const { signer: evmSigner } = await algoXEvmSdk.getSigner({
8789
+ evmAddress,
8790
+ signMessage: (typedData) => this.signWithProvider(typedData, evmAddress)
8791
+ });
8792
+ const signedBlobs = await evmSigner(allTxns, indexes);
8793
+ for (let i = 0; i < indexes.length; i++) {
8794
+ signedResult[indexes[i]] = signedBlobs[i];
8795
+ }
8796
+ }
8785
8797
  const onAfterSign = this.options.uiHooks?.onAfterSign ?? this.managerUIHooks?.onAfterSign;
8786
8798
  if (onAfterSign) {
8787
8799
  this.logger.debug("Running onAfterSign hook");
@@ -8790,15 +8802,8 @@ var AlgoXEvmBaseWallet = class extends BaseWallet {
8790
8802
  } catch (e) {
8791
8803
  }
8792
8804
  }
8793
- let signedIdx = 0;
8794
- const result = txnsToSign.map((_2, index) => {
8795
- if (signIndexes.includes(index)) {
8796
- return signedBlobs[signedIdx++];
8797
- }
8798
- return null;
8799
- });
8800
- this.logger.debug("Transactions signed successfully", result);
8801
- return result;
8805
+ this.logger.debug("Transactions signed successfully", signedResult);
8806
+ return signedResult;
8802
8807
  } catch (error) {
8803
8808
  try {
8804
8809
  const onAfterSignCleanup = this.options.uiHooks?.onAfterSign ?? this.managerUIHooks?.onAfterSign;
@@ -8951,36 +8956,35 @@ var RainbowKitWallet = class _RainbowKitWallet extends AlgoXEvmBaseWallet {
8951
8956
  }
8952
8957
  /**
8953
8958
  * Read connected EVM accounts from wagmi state.
8954
- * If not connected, tries the getEvmAccounts callback, then falls back to
8955
- * connecting with the first available connector.
8956
- *
8957
- * When getEvmAccounts is provided, it is always called (to show the wallet
8958
- * selection UI). The callback is responsible for any disconnect/reconnect
8959
- * needed to present a fresh selection.
8959
+ * If already connected (e.g. auto-reconnect on page refresh), uses the
8960
+ * existing connection directly. Otherwise tries the getEvmAccounts
8961
+ * callback (wallet picker UI), then falls back to connecting with the
8962
+ * first available connector.
8960
8963
  */
8961
8964
  async getConnectedEvmAddresses() {
8962
8965
  const { getAccount, connect: wagmiConnect } = await import("@wagmi/core");
8966
+ const existing = getAccount(this.wagmiConfig);
8967
+ if (existing.isConnected && existing.address) {
8968
+ this.logger.info("Using existing wagmi connection");
8969
+ return {
8970
+ addresses: existing.addresses ? [...existing.addresses] : [existing.address],
8971
+ connectorInfo: _RainbowKitWallet.extractConnectorInfo(existing)
8972
+ };
8973
+ }
8963
8974
  if (this.options.getEvmAccounts) {
8964
8975
  const addresses = await this.options.getEvmAccounts();
8965
8976
  if (addresses.length > 0) {
8966
- const account2 = getAccount(this.wagmiConfig);
8967
- const connectorInfo = _RainbowKitWallet.extractConnectorInfo(account2);
8968
- if (account2.isConnected && account2.address) {
8977
+ const account = getAccount(this.wagmiConfig);
8978
+ const connectorInfo = _RainbowKitWallet.extractConnectorInfo(account);
8979
+ if (account.isConnected && account.address) {
8969
8980
  return {
8970
- addresses: account2.addresses ? [...account2.addresses] : [account2.address],
8981
+ addresses: account.addresses ? [...account.addresses] : [account.address],
8971
8982
  connectorInfo
8972
8983
  };
8973
8984
  }
8974
8985
  return { addresses, connectorInfo };
8975
8986
  }
8976
8987
  }
8977
- const account = getAccount(this.wagmiConfig);
8978
- if (account.isConnected && account.address) {
8979
- return {
8980
- addresses: account.addresses ? [...account.addresses] : [account.address],
8981
- connectorInfo: _RainbowKitWallet.extractConnectorInfo(account)
8982
- };
8983
- }
8984
8988
  const connectors = this.wagmiConfig.connectors;
8985
8989
  if (connectors.length > 0) {
8986
8990
  this.logger.info("Attempting connection with first available connector...");