@d13co/use-wallet 4.5.13 → 4.5.15
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 +58 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -10
- package/dist/index.d.ts +8 -10
- package/dist/index.js +58 -54
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -8653,16 +8653,16 @@ var AlgoXEvmBaseWallet = class extends BaseWallet {
|
|
|
8653
8653
|
this.store = params.store;
|
|
8654
8654
|
}
|
|
8655
8655
|
/**
|
|
8656
|
-
* Default metadata for
|
|
8656
|
+
* Default metadata for xChain EVM wallets.
|
|
8657
8657
|
* Subclasses MUST override this with their own metadata including isAlgoXEvm: "EVM"
|
|
8658
8658
|
*/
|
|
8659
8659
|
static defaultMetadata;
|
|
8660
8660
|
/**
|
|
8661
|
-
* Initialize the
|
|
8661
|
+
* Initialize the xChain EVM SDK for deriving Algorand addresses
|
|
8662
8662
|
*/
|
|
8663
8663
|
async initializeEvmSdk() {
|
|
8664
8664
|
if (!this.algoXEvmSdk) {
|
|
8665
|
-
this.logger.info("Initializing
|
|
8665
|
+
this.logger.info("Initializing xChain EVM SDK...");
|
|
8666
8666
|
if (!this.algorandClient) {
|
|
8667
8667
|
const { AlgorandClient } = await import("@algorandfoundation/algokit-utils");
|
|
8668
8668
|
const algodClient = this.getAlgodClient();
|
|
@@ -8672,7 +8672,7 @@ var AlgoXEvmBaseWallet = class extends BaseWallet {
|
|
|
8672
8672
|
}
|
|
8673
8673
|
const { AlgoXEvmSdk } = await import("algo-x-evm-sdk");
|
|
8674
8674
|
this.algoXEvmSdk = new AlgoXEvmSdk({ algorand: this.algorandClient });
|
|
8675
|
-
this.logger.info("
|
|
8675
|
+
this.logger.info("xChain EVM SDK initialized");
|
|
8676
8676
|
}
|
|
8677
8677
|
return this.algoXEvmSdk;
|
|
8678
8678
|
}
|
|
@@ -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
|
|
8752
|
-
|
|
8753
|
-
|
|
8754
|
-
|
|
8755
|
-
|
|
8756
|
-
|
|
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
|
-
|
|
8767
|
-
|
|
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
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
8779
|
-
|
|
8780
|
-
|
|
8781
|
-
|
|
8782
|
-
|
|
8783
|
-
|
|
8784
|
-
|
|
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
|
-
|
|
8794
|
-
|
|
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
|
|
8955
|
-
*
|
|
8956
|
-
*
|
|
8957
|
-
*
|
|
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
|
|
8967
|
-
const connectorInfo = _RainbowKitWallet.extractConnectorInfo(
|
|
8968
|
-
if (
|
|
8977
|
+
const account = getAccount(this.wagmiConfig);
|
|
8978
|
+
const connectorInfo = _RainbowKitWallet.extractConnectorInfo(account);
|
|
8979
|
+
if (account.isConnected && account.address) {
|
|
8969
8980
|
return {
|
|
8970
|
-
addresses:
|
|
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...");
|