@rhinestone/deposit-modal 0.1.24 → 0.1.25
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 -5
- package/dist/DepositModalReown-4A5HJK74.mjs +33 -0
- package/dist/DepositModalReown-QQ6WI265.cjs +33 -0
- package/dist/WithdrawModalReown-HBORIX2O.mjs +33 -0
- package/dist/WithdrawModalReown-L77OC26X.cjs +33 -0
- package/dist/{chunk-O3I5KVXA.cjs → chunk-4QDHXCPG.cjs} +97 -81
- package/dist/chunk-6VJ2ZTNQ.cjs +90 -0
- package/dist/{chunk-35DWLO33.mjs → chunk-B3HMNWR4.mjs} +61 -45
- package/dist/{chunk-ANQQMGNN.cjs → chunk-CZWAKYDR.cjs} +230 -115
- package/dist/{chunk-P7SQQAAF.mjs → chunk-GAFLOODV.mjs} +203 -88
- package/dist/{chunk-ZMVCDFXM.mjs → chunk-JAR372KJ.mjs} +48 -40
- package/dist/chunk-LBEP3A2Z.mjs +90 -0
- package/dist/{chunk-A2PDOYYE.cjs → chunk-VBNFP3JF.cjs} +89 -81
- package/dist/deposit.cjs +3 -3
- package/dist/deposit.d.cts +2 -2
- package/dist/deposit.d.ts +2 -2
- package/dist/deposit.mjs +2 -2
- package/dist/index.cjs +4 -4
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +3 -3
- package/dist/reown.cjs +6 -191
- package/dist/reown.d.cts +4 -12
- package/dist/reown.d.ts +4 -12
- package/dist/reown.mjs +8 -193
- package/dist/{types-CUww05xT.d.cts → types-BwaQ7jK5.d.cts} +3 -16
- package/dist/{types-Z6GjVWFR.d.ts → types-CgXyx46m.d.ts} +3 -16
- package/dist/withdraw.cjs +3 -3
- package/dist/withdraw.d.cts +2 -2
- package/dist/withdraw.d.ts +2 -2
- package/dist/withdraw.mjs +2 -2
- package/package.json +16 -33
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CHAIN_BY_ID,
|
|
3
3
|
NATIVE_TOKEN_ADDRESS,
|
|
4
|
+
SUPPORTED_CHAINS,
|
|
4
5
|
getChainIcon,
|
|
5
6
|
getChainName,
|
|
6
7
|
getExplorerTxUrl,
|
|
8
|
+
getSupportedTokenSymbolsForChain,
|
|
7
9
|
getTokenAddress,
|
|
8
10
|
getTokenDecimalsByAddress,
|
|
9
11
|
getTokenSymbol,
|
|
@@ -151,21 +153,6 @@ function createDepositService(baseUrl) {
|
|
|
151
153
|
return `${normalizedBaseUrl}${normalizedPath}`;
|
|
152
154
|
}
|
|
153
155
|
return {
|
|
154
|
-
async prepareAccount(params) {
|
|
155
|
-
const response = await fetch(apiUrl("/prepare-account"), {
|
|
156
|
-
method: "POST",
|
|
157
|
-
headers: { "Content-Type": "application/json" },
|
|
158
|
-
body: JSON.stringify(params, jsonReplacer)
|
|
159
|
-
});
|
|
160
|
-
if (!response.ok) {
|
|
161
|
-
const error = await response.json().catch(() => ({ error: "Unknown error" }));
|
|
162
|
-
throw new Error(
|
|
163
|
-
error.error || `Prepare account failed: ${response.status}`
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
const payload = await response.json();
|
|
167
|
-
return normalizePrepareAccountResponse(payload);
|
|
168
|
-
},
|
|
169
156
|
async registerAccount(params) {
|
|
170
157
|
const { eoaAddress, sessionOwner, ...account } = params;
|
|
171
158
|
const response = await fetch(apiUrl("/register"), {
|
|
@@ -246,58 +233,40 @@ function createDepositService(baseUrl) {
|
|
|
246
233
|
return { lastEvent: void 0 };
|
|
247
234
|
}
|
|
248
235
|
return response.json();
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
function buildSessionDetails(sessionDetailsUnsigned, signature) {
|
|
253
|
-
return {
|
|
254
|
-
hashesAndChainIds: sessionDetailsUnsigned.hashesAndChainIds,
|
|
255
|
-
signature
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
function normalizePrepareAccountResponse(payload) {
|
|
259
|
-
if (!isRecord(payload)) {
|
|
260
|
-
throw new Error("Invalid prepare-account response");
|
|
261
|
-
}
|
|
262
|
-
const smartAccount = extractString(payload, "smartAccount");
|
|
263
|
-
const accountParams = isRecord(payload.accountParams) ? payload.accountParams : null;
|
|
264
|
-
const sessionDetailsUnsigned = isRecord(payload.sessionDetailsUnsigned) ? payload.sessionDetailsUnsigned : null;
|
|
265
|
-
if (!smartAccount || !accountParams || !sessionDetailsUnsigned) {
|
|
266
|
-
throw new Error("Missing prepare-account fields");
|
|
267
|
-
}
|
|
268
|
-
const factory = extractString(accountParams, "factory");
|
|
269
|
-
const factoryData = extractString(accountParams, "factoryData");
|
|
270
|
-
if (!factory || !factoryData) {
|
|
271
|
-
throw new Error("Invalid account params from prepare-account");
|
|
272
|
-
}
|
|
273
|
-
const rawHashes = Array.isArray(sessionDetailsUnsigned.hashesAndChainIds) ? sessionDetailsUnsigned.hashesAndChainIds : null;
|
|
274
|
-
if (!rawHashes) {
|
|
275
|
-
throw new Error("Missing session hashes from prepare-account");
|
|
276
|
-
}
|
|
277
|
-
const hashesAndChainIds = rawHashes.map((value) => {
|
|
278
|
-
if (!isRecord(value)) return null;
|
|
279
|
-
const sessionDigest = extractString(value, "sessionDigest");
|
|
280
|
-
const chainId = toBigInt(value.chainId);
|
|
281
|
-
if (!sessionDigest || chainId === null) return null;
|
|
282
|
-
return {
|
|
283
|
-
chainId,
|
|
284
|
-
sessionDigest
|
|
285
|
-
};
|
|
286
|
-
}).filter(
|
|
287
|
-
(item) => item !== null
|
|
288
|
-
);
|
|
289
|
-
if (hashesAndChainIds.length === 0) {
|
|
290
|
-
throw new Error("Session hashes are empty");
|
|
291
|
-
}
|
|
292
|
-
return {
|
|
293
|
-
smartAccount,
|
|
294
|
-
accountParams: {
|
|
295
|
-
factory,
|
|
296
|
-
factoryData
|
|
297
236
|
},
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
237
|
+
async relayWithdraw(params) {
|
|
238
|
+
const { smartAccount, chainId, safeAddress, safeTransaction, signature } = params;
|
|
239
|
+
const response = await fetch(apiUrl(`/relay-withdraw`), {
|
|
240
|
+
method: "POST",
|
|
241
|
+
headers: { "Content-Type": "application/json" },
|
|
242
|
+
body: JSON.stringify(
|
|
243
|
+
{
|
|
244
|
+
chainId,
|
|
245
|
+
safeAddress,
|
|
246
|
+
safeTransaction: {
|
|
247
|
+
to: safeTransaction.to,
|
|
248
|
+
value: safeTransaction.value.toString(),
|
|
249
|
+
data: safeTransaction.data,
|
|
250
|
+
operation: safeTransaction.operation,
|
|
251
|
+
safeTxGas: safeTransaction.safeTxGas.toString(),
|
|
252
|
+
baseGas: safeTransaction.baseGas.toString(),
|
|
253
|
+
gasPrice: safeTransaction.gasPrice.toString(),
|
|
254
|
+
gasToken: safeTransaction.gasToken,
|
|
255
|
+
refundReceiver: safeTransaction.refundReceiver,
|
|
256
|
+
nonce: safeTransaction.nonce.toString()
|
|
257
|
+
},
|
|
258
|
+
signature
|
|
259
|
+
},
|
|
260
|
+
jsonReplacer
|
|
261
|
+
)
|
|
262
|
+
});
|
|
263
|
+
if (!response.ok) {
|
|
264
|
+
const error = await response.json().catch(() => ({ error: "Unknown error" }));
|
|
265
|
+
throw new Error(
|
|
266
|
+
error.error || `Relay withdraw failed: ${response.status}`
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
return response.json();
|
|
301
270
|
}
|
|
302
271
|
};
|
|
303
272
|
}
|
|
@@ -386,23 +355,6 @@ function extractTokenAddress(tokenData, chainId) {
|
|
|
386
355
|
const token = tokenData;
|
|
387
356
|
return token.tokenAddress ?? token.address ?? token.addresses?.[chainId] ?? token.token?.address ?? token.token?.addresses?.[chainId];
|
|
388
357
|
}
|
|
389
|
-
function isRecord(value) {
|
|
390
|
-
return typeof value === "object" && value !== null;
|
|
391
|
-
}
|
|
392
|
-
function toBigInt(value) {
|
|
393
|
-
if (typeof value === "bigint") return value;
|
|
394
|
-
if (typeof value === "number" && Number.isInteger(value) && value >= 0) {
|
|
395
|
-
return BigInt(value);
|
|
396
|
-
}
|
|
397
|
-
if (typeof value === "string" && /^\d+$/.test(value)) {
|
|
398
|
-
try {
|
|
399
|
-
return BigInt(value);
|
|
400
|
-
} catch {
|
|
401
|
-
return null;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
return null;
|
|
405
|
-
}
|
|
406
358
|
function extractArray(data, key) {
|
|
407
359
|
if (!data || typeof data !== "object") return null;
|
|
408
360
|
const record = data;
|
|
@@ -851,6 +803,165 @@ function ConnectStep({
|
|
|
851
803
|
}
|
|
852
804
|
ConnectStep.displayName = "ConnectStep";
|
|
853
805
|
|
|
806
|
+
// src/core/account.ts
|
|
807
|
+
import {
|
|
808
|
+
RhinestoneSDK
|
|
809
|
+
} from "@rhinestone/sdk";
|
|
810
|
+
import { zeroAddress } from "viem";
|
|
811
|
+
import { toAccount } from "viem/accounts";
|
|
812
|
+
function createViewOnlyAccount(address) {
|
|
813
|
+
if (!address || address === zeroAddress) {
|
|
814
|
+
throw new Error("Address is required");
|
|
815
|
+
}
|
|
816
|
+
return toAccount({
|
|
817
|
+
address,
|
|
818
|
+
signMessage: async () => {
|
|
819
|
+
throw new Error("Account is view-only");
|
|
820
|
+
},
|
|
821
|
+
signTransaction: async () => {
|
|
822
|
+
throw new Error("Account is view-only");
|
|
823
|
+
},
|
|
824
|
+
signTypedData: async () => {
|
|
825
|
+
throw new Error("Account is view-only");
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
function getSessionSignerAccount(signerAddress) {
|
|
830
|
+
if (!signerAddress || signerAddress === zeroAddress) {
|
|
831
|
+
throw new Error("Signer address is required");
|
|
832
|
+
}
|
|
833
|
+
return toAccount({
|
|
834
|
+
address: signerAddress,
|
|
835
|
+
signMessage: async () => {
|
|
836
|
+
throw new Error("Session signer is view-only");
|
|
837
|
+
},
|
|
838
|
+
signTransaction: async () => {
|
|
839
|
+
throw new Error("Session signer is view-only");
|
|
840
|
+
},
|
|
841
|
+
signTypedData: async () => {
|
|
842
|
+
throw new Error("Session signer is view-only");
|
|
843
|
+
}
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
function buildSession(chain, signerAddress) {
|
|
847
|
+
const sessionSignerAccount = getSessionSignerAccount(signerAddress);
|
|
848
|
+
return {
|
|
849
|
+
owners: {
|
|
850
|
+
type: "ecdsa",
|
|
851
|
+
accounts: [sessionSignerAccount]
|
|
852
|
+
},
|
|
853
|
+
chain
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
async function createSmartAccount(userSigner, sessionSigner, sdkApiKey) {
|
|
857
|
+
const rhinestone = new RhinestoneSDK({
|
|
858
|
+
apiKey: sdkApiKey ?? ""
|
|
859
|
+
});
|
|
860
|
+
const ownerAccounts = sessionSigner ? [userSigner, sessionSigner] : [userSigner];
|
|
861
|
+
const config = {
|
|
862
|
+
account: {
|
|
863
|
+
type: "nexus"
|
|
864
|
+
},
|
|
865
|
+
owners: {
|
|
866
|
+
type: "ecdsa",
|
|
867
|
+
accounts: ownerAccounts,
|
|
868
|
+
...sessionSigner ? { threshold: 1 } : {}
|
|
869
|
+
},
|
|
870
|
+
experimental_sessions: {
|
|
871
|
+
enabled: true
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
const account = await rhinestone.createAccount(config);
|
|
875
|
+
return account;
|
|
876
|
+
}
|
|
877
|
+
function getAccountAddress(account) {
|
|
878
|
+
return account.getAddress();
|
|
879
|
+
}
|
|
880
|
+
function getAccountInitData(account) {
|
|
881
|
+
const { factory, factoryData } = account.getInitData();
|
|
882
|
+
if (!factory) {
|
|
883
|
+
throw new Error("Account init data is not available");
|
|
884
|
+
}
|
|
885
|
+
return {
|
|
886
|
+
factory,
|
|
887
|
+
factoryData
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
async function signEnableSessionWithOwner(rhinestoneAccount, sessionDetails, signer) {
|
|
891
|
+
const originalOwners = rhinestoneAccount.config.owners;
|
|
892
|
+
rhinestoneAccount.config.owners = {
|
|
893
|
+
type: "ecdsa",
|
|
894
|
+
accounts: [signer],
|
|
895
|
+
threshold: 1,
|
|
896
|
+
...originalOwners?.type === "ecdsa" && originalOwners.module ? { module: originalOwners.module } : {}
|
|
897
|
+
};
|
|
898
|
+
try {
|
|
899
|
+
return await rhinestoneAccount.experimental_signEnableSession(
|
|
900
|
+
sessionDetails
|
|
901
|
+
);
|
|
902
|
+
} finally {
|
|
903
|
+
rhinestoneAccount.config.owners = originalOwners;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
async function getSessionDetails(rhinestoneAccount, targetChain, signerAddress, sessionSigner, targetToken, sessionChainIds) {
|
|
907
|
+
const isTargetTestnet = Boolean(targetChain.testnet);
|
|
908
|
+
const chainsByNetworkType = SUPPORTED_CHAINS.filter(
|
|
909
|
+
(chain) => Boolean(chain.testnet) === isTargetTestnet
|
|
910
|
+
);
|
|
911
|
+
const chainsById = new Map(
|
|
912
|
+
chainsByNetworkType.map((chain) => [chain.id, chain])
|
|
913
|
+
);
|
|
914
|
+
let selectedChains = [...chainsByNetworkType];
|
|
915
|
+
if (sessionChainIds && sessionChainIds.length > 0) {
|
|
916
|
+
const selectedByCaller = [];
|
|
917
|
+
for (const chainId of sessionChainIds) {
|
|
918
|
+
const chain = chainsById.get(chainId);
|
|
919
|
+
if (chain) {
|
|
920
|
+
selectedByCaller.push(chain);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
if (selectedByCaller.length > 0) {
|
|
924
|
+
selectedChains = selectedByCaller;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
if (targetToken) {
|
|
928
|
+
const targetSymbol = getTokenSymbol(
|
|
929
|
+
targetToken,
|
|
930
|
+
targetChain.id
|
|
931
|
+
).toUpperCase();
|
|
932
|
+
if (targetSymbol && targetSymbol !== "TOKEN") {
|
|
933
|
+
const chainsForToken = selectedChains.filter(
|
|
934
|
+
(chain) => getSupportedTokenSymbolsForChain(chain.id).includes(targetSymbol)
|
|
935
|
+
);
|
|
936
|
+
if (chainsForToken.length > 0) {
|
|
937
|
+
selectedChains = chainsForToken;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
if (!selectedChains.some((c) => c.id === targetChain.id)) {
|
|
942
|
+
selectedChains.push(targetChain);
|
|
943
|
+
}
|
|
944
|
+
const uniqueChains = Array.from(
|
|
945
|
+
new Map(selectedChains.map((chain) => [chain.id, chain])).values()
|
|
946
|
+
);
|
|
947
|
+
const sessions = uniqueChains.map(
|
|
948
|
+
(chain) => buildSession(chain, signerAddress)
|
|
949
|
+
);
|
|
950
|
+
const sessionDetails = await rhinestoneAccount.experimental_getSessionDetails(sessions);
|
|
951
|
+
const enableSignature = sessionSigner ? await signEnableSessionWithOwner(
|
|
952
|
+
rhinestoneAccount,
|
|
953
|
+
sessionDetails,
|
|
954
|
+
sessionSigner
|
|
955
|
+
) : await rhinestoneAccount.experimental_signEnableSession(sessionDetails);
|
|
956
|
+
if (!sessionDetails.hashesAndChainIds?.length) {
|
|
957
|
+
throw new Error("Session details missing chain digests");
|
|
958
|
+
}
|
|
959
|
+
return {
|
|
960
|
+
hashesAndChainIds: sessionDetails.hashesAndChainIds,
|
|
961
|
+
signature: enableSignature
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
|
|
854
965
|
// src/core/session-owner.ts
|
|
855
966
|
import { isAddress } from "viem";
|
|
856
967
|
import {
|
|
@@ -942,7 +1053,7 @@ function PoweredBy() {
|
|
|
942
1053
|
}
|
|
943
1054
|
|
|
944
1055
|
// src/core/webhook.ts
|
|
945
|
-
function
|
|
1056
|
+
function isRecord(value) {
|
|
946
1057
|
return typeof value === "object" && value !== null;
|
|
947
1058
|
}
|
|
948
1059
|
function asString(value) {
|
|
@@ -954,11 +1065,11 @@ function getEventTxHash(event) {
|
|
|
954
1065
|
return asString(event.data?.transactionHash);
|
|
955
1066
|
}
|
|
956
1067
|
if (event.type === "bridge-started" || event.type === "bridge-complete") {
|
|
957
|
-
const deposit =
|
|
1068
|
+
const deposit = isRecord(event.data?.deposit) ? event.data.deposit : void 0;
|
|
958
1069
|
return asString(deposit?.transactionHash);
|
|
959
1070
|
}
|
|
960
1071
|
if (event.type === "bridge-failed" || event.type === "error") {
|
|
961
|
-
const deposit =
|
|
1072
|
+
const deposit = isRecord(event.data?.deposit) ? event.data.deposit : void 0;
|
|
962
1073
|
return asString(deposit?.transactionHash);
|
|
963
1074
|
}
|
|
964
1075
|
return void 0;
|
|
@@ -1546,16 +1657,20 @@ export {
|
|
|
1546
1657
|
Spinner,
|
|
1547
1658
|
Button,
|
|
1548
1659
|
ConnectStep,
|
|
1660
|
+
createViewOnlyAccount,
|
|
1661
|
+
createSmartAccount,
|
|
1662
|
+
getAccountAddress,
|
|
1663
|
+
getAccountInitData,
|
|
1664
|
+
getSessionDetails,
|
|
1549
1665
|
loadSessionOwnerFromStorage,
|
|
1550
1666
|
saveSessionOwnerToStorage,
|
|
1551
1667
|
createSessionOwnerKey,
|
|
1552
1668
|
accountFromPrivateKey,
|
|
1669
|
+
PoweredBy,
|
|
1553
1670
|
createDepositService,
|
|
1554
|
-
buildSessionDetails,
|
|
1555
1671
|
getAssetId,
|
|
1556
1672
|
portfolioToAssets,
|
|
1557
1673
|
isNativeAsset,
|
|
1558
|
-
PoweredBy,
|
|
1559
1674
|
currencyFormatter,
|
|
1560
1675
|
tokenFormatter,
|
|
1561
1676
|
formatUserError,
|
|
@@ -7,21 +7,25 @@ import {
|
|
|
7
7
|
Spinner,
|
|
8
8
|
accountFromPrivateKey,
|
|
9
9
|
applyTheme,
|
|
10
|
-
buildSessionDetails,
|
|
11
10
|
createDepositService,
|
|
12
11
|
createSessionOwnerKey,
|
|
12
|
+
createSmartAccount,
|
|
13
|
+
createViewOnlyAccount,
|
|
13
14
|
currencyFormatter,
|
|
14
15
|
formatUserError,
|
|
16
|
+
getAccountAddress,
|
|
17
|
+
getAccountInitData,
|
|
15
18
|
getAssetId,
|
|
16
19
|
getEventTxHash,
|
|
17
20
|
getPublicClient,
|
|
21
|
+
getSessionDetails,
|
|
18
22
|
isDepositEvent,
|
|
19
23
|
isNativeAsset,
|
|
20
24
|
loadSessionOwnerFromStorage,
|
|
21
25
|
portfolioToAssets,
|
|
22
26
|
saveSessionOwnerToStorage,
|
|
23
27
|
tokenFormatter
|
|
24
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-GAFLOODV.mjs";
|
|
25
29
|
import {
|
|
26
30
|
CHAIN_BY_ID,
|
|
27
31
|
DEFAULT_BACKEND_URL,
|
|
@@ -45,7 +49,9 @@ import {
|
|
|
45
49
|
useEffect as useEffect7,
|
|
46
50
|
useRef as useRef5,
|
|
47
51
|
useState as useState8,
|
|
48
|
-
useCallback as useCallback4
|
|
52
|
+
useCallback as useCallback4,
|
|
53
|
+
lazy,
|
|
54
|
+
Suspense
|
|
49
55
|
} from "react";
|
|
50
56
|
|
|
51
57
|
// src/DepositFlow.tsx
|
|
@@ -53,6 +59,7 @@ import { useState as useState7, useCallback as useCallback3, useMemo as useMemo6
|
|
|
53
59
|
|
|
54
60
|
// src/components/steps/SetupStep.tsx
|
|
55
61
|
import { useState, useEffect, useRef, useCallback } from "react";
|
|
62
|
+
import { walletClientToAccount } from "@rhinestone/sdk";
|
|
56
63
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
57
64
|
async function resolveSessionOwner(eoaAddress) {
|
|
58
65
|
const localOwner = loadSessionOwnerFromStorage(eoaAddress);
|
|
@@ -73,7 +80,9 @@ function SetupStep({
|
|
|
73
80
|
walletClient,
|
|
74
81
|
address,
|
|
75
82
|
targetChain,
|
|
83
|
+
targetChainObj,
|
|
76
84
|
targetToken,
|
|
85
|
+
rhinestoneApiKey,
|
|
77
86
|
signerAddress,
|
|
78
87
|
sessionChainIds,
|
|
79
88
|
recipient,
|
|
@@ -85,18 +94,8 @@ function SetupStep({
|
|
|
85
94
|
}) {
|
|
86
95
|
const [state, setState] = useState({ type: "idle" });
|
|
87
96
|
const setupInitiatedRef = useRef(false);
|
|
88
|
-
const signSessionDetails = useCallback(
|
|
89
|
-
async (sessionOwner, typedData) => {
|
|
90
|
-
const signer = sessionOwner.account;
|
|
91
|
-
if (!signer.signTypedData) {
|
|
92
|
-
throw new Error("Session owner cannot sign typed data");
|
|
93
|
-
}
|
|
94
|
-
return await signer.signTypedData(typedData);
|
|
95
|
-
},
|
|
96
|
-
[]
|
|
97
|
-
);
|
|
98
97
|
const runSetup = useCallback(async () => {
|
|
99
|
-
if (!address) {
|
|
98
|
+
if (!address || !targetChainObj) {
|
|
100
99
|
return;
|
|
101
100
|
}
|
|
102
101
|
if (walletClient && !walletClient.account) {
|
|
@@ -104,16 +103,14 @@ function SetupStep({
|
|
|
104
103
|
}
|
|
105
104
|
try {
|
|
106
105
|
setState({ type: "creating-account" });
|
|
106
|
+
const signerAccount = walletClient ? walletClientToAccount(walletClient) : createViewOnlyAccount(address);
|
|
107
107
|
const sessionOwner = await resolveSessionOwner(address);
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
sessionChainIds
|
|
115
|
-
});
|
|
116
|
-
const smartAccount = prepared.smartAccount;
|
|
108
|
+
const account = await createSmartAccount(
|
|
109
|
+
signerAccount,
|
|
110
|
+
sessionOwner.account,
|
|
111
|
+
rhinestoneApiKey
|
|
112
|
+
);
|
|
113
|
+
const smartAccount = getAccountAddress(account);
|
|
117
114
|
setState({ type: "checking" });
|
|
118
115
|
const checkResult = await service.checkAccount(smartAccount);
|
|
119
116
|
if (checkResult.isRegistered && !forceRegister) {
|
|
@@ -126,20 +123,21 @@ function SetupStep({
|
|
|
126
123
|
}
|
|
127
124
|
}
|
|
128
125
|
setState({ type: "signing-session" });
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
126
|
+
const initData = getAccountInitData(account);
|
|
127
|
+
const sessionDetails = await getSessionDetails(
|
|
128
|
+
account,
|
|
129
|
+
targetChainObj,
|
|
130
|
+
signerAddress,
|
|
131
|
+
sessionOwner.account,
|
|
132
|
+
targetToken,
|
|
133
|
+
sessionChainIds
|
|
136
134
|
);
|
|
137
135
|
setState({ type: "registering" });
|
|
138
136
|
await service.registerAccount({
|
|
139
137
|
address: smartAccount,
|
|
140
138
|
accountParams: {
|
|
141
|
-
factory:
|
|
142
|
-
factoryData:
|
|
139
|
+
factory: initData.factory,
|
|
140
|
+
factoryData: initData.factoryData,
|
|
143
141
|
sessionDetails
|
|
144
142
|
},
|
|
145
143
|
eoaAddress: address,
|
|
@@ -161,8 +159,10 @@ function SetupStep({
|
|
|
161
159
|
}, [
|
|
162
160
|
address,
|
|
163
161
|
walletClient,
|
|
162
|
+
targetChainObj,
|
|
164
163
|
targetChain,
|
|
165
164
|
targetToken,
|
|
165
|
+
rhinestoneApiKey,
|
|
166
166
|
signerAddress,
|
|
167
167
|
sessionChainIds,
|
|
168
168
|
recipient,
|
|
@@ -170,16 +170,15 @@ function SetupStep({
|
|
|
170
170
|
service,
|
|
171
171
|
onSetupComplete,
|
|
172
172
|
onError,
|
|
173
|
-
onConnected
|
|
174
|
-
signSessionDetails
|
|
173
|
+
onConnected
|
|
175
174
|
]);
|
|
176
175
|
useEffect(() => {
|
|
177
176
|
const hasWallet = walletClient ? Boolean(walletClient.account) : true;
|
|
178
|
-
if (address && hasWallet && !setupInitiatedRef.current && state.type === "idle") {
|
|
177
|
+
if (address && hasWallet && targetChainObj && !setupInitiatedRef.current && state.type === "idle") {
|
|
179
178
|
setupInitiatedRef.current = true;
|
|
180
179
|
runSetup();
|
|
181
180
|
}
|
|
182
|
-
}, [address, walletClient, state.type, runSetup]);
|
|
181
|
+
}, [address, walletClient, targetChainObj, state.type, runSetup]);
|
|
183
182
|
const handleRetry = () => {
|
|
184
183
|
setupInitiatedRef.current = false;
|
|
185
184
|
setState({ type: "idle" });
|
|
@@ -1651,6 +1650,7 @@ function DepositFlow({
|
|
|
1651
1650
|
sourceToken: defaultSourceToken,
|
|
1652
1651
|
amount: defaultAmount,
|
|
1653
1652
|
recipient,
|
|
1653
|
+
rhinestoneApiKey,
|
|
1654
1654
|
signerAddress = DEFAULT_SIGNER_ADDRESS,
|
|
1655
1655
|
sessionChainIds,
|
|
1656
1656
|
forceRegister = false,
|
|
@@ -1973,7 +1973,9 @@ function DepositFlow({
|
|
|
1973
1973
|
{
|
|
1974
1974
|
address: sessionKeyAddress,
|
|
1975
1975
|
targetChain,
|
|
1976
|
+
targetChainObj,
|
|
1976
1977
|
targetToken,
|
|
1978
|
+
rhinestoneApiKey,
|
|
1977
1979
|
signerAddress,
|
|
1978
1980
|
sessionChainIds,
|
|
1979
1981
|
recipient,
|
|
@@ -2034,7 +2036,9 @@ function DepositFlow({
|
|
|
2034
2036
|
walletClient: signerContext.walletClient,
|
|
2035
2037
|
address: ownerAddress,
|
|
2036
2038
|
targetChain,
|
|
2039
|
+
targetChainObj,
|
|
2037
2040
|
targetToken,
|
|
2041
|
+
rhinestoneApiKey,
|
|
2038
2042
|
signerAddress,
|
|
2039
2043
|
sessionChainIds,
|
|
2040
2044
|
recipient,
|
|
@@ -2115,11 +2119,13 @@ function DepositFlow({
|
|
|
2115
2119
|
|
|
2116
2120
|
// src/DepositModal.tsx
|
|
2117
2121
|
import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
2122
|
+
var ReownDepositInner = lazy(
|
|
2123
|
+
() => import("./DepositModalReown-4A5HJK74.mjs").then((m) => ({ default: m.DepositModalReown }))
|
|
2124
|
+
);
|
|
2118
2125
|
function DepositModal(props) {
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
);
|
|
2126
|
+
const needsReown = !!props.reownAppId;
|
|
2127
|
+
if (needsReown) {
|
|
2128
|
+
return /* @__PURE__ */ jsx8(Suspense, { fallback: null, children: /* @__PURE__ */ jsx8(ReownDepositInner, { ...props }) });
|
|
2123
2129
|
}
|
|
2124
2130
|
return /* @__PURE__ */ jsx8(DepositModalInner, { ...props });
|
|
2125
2131
|
}
|
|
@@ -2138,6 +2144,7 @@ function DepositModalInner({
|
|
|
2138
2144
|
defaultAmount,
|
|
2139
2145
|
recipient,
|
|
2140
2146
|
backendUrl = DEFAULT_BACKEND_URL,
|
|
2147
|
+
rhinestoneApiKey,
|
|
2141
2148
|
signerAddress = DEFAULT_SIGNER_ADDRESS,
|
|
2142
2149
|
sessionChainIds,
|
|
2143
2150
|
forceRegister = false,
|
|
@@ -2307,6 +2314,7 @@ function DepositModalInner({
|
|
|
2307
2314
|
sourceToken,
|
|
2308
2315
|
amount: defaultAmount,
|
|
2309
2316
|
recipient,
|
|
2317
|
+
rhinestoneApiKey,
|
|
2310
2318
|
signerAddress,
|
|
2311
2319
|
sessionChainIds,
|
|
2312
2320
|
forceRegister,
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// src/core/reown.tsx
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
4
|
+
import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
|
|
5
|
+
import { WagmiProvider } from "wagmi";
|
|
6
|
+
import { createAppKit, useAppKit, useAppKitAccount } from "@reown/appkit/react";
|
|
7
|
+
import {
|
|
8
|
+
mainnet,
|
|
9
|
+
base,
|
|
10
|
+
arbitrum,
|
|
11
|
+
optimism,
|
|
12
|
+
polygon,
|
|
13
|
+
bsc
|
|
14
|
+
} from "@reown/appkit/networks";
|
|
15
|
+
import { useWalletClient, usePublicClient, useSwitchChain } from "wagmi";
|
|
16
|
+
import { jsx } from "react/jsx-runtime";
|
|
17
|
+
var NETWORKS = [
|
|
18
|
+
mainnet,
|
|
19
|
+
base,
|
|
20
|
+
arbitrum,
|
|
21
|
+
optimism,
|
|
22
|
+
polygon,
|
|
23
|
+
bsc
|
|
24
|
+
];
|
|
25
|
+
var cachedAdapter = null;
|
|
26
|
+
var cachedProjectId = null;
|
|
27
|
+
function mapTheme(theme) {
|
|
28
|
+
const themeMode = theme?.mode === "light" ? "light" : "dark";
|
|
29
|
+
const themeVariables = {};
|
|
30
|
+
if (theme?.ctaColor) {
|
|
31
|
+
themeVariables["--apkt-accent"] = theme.ctaColor;
|
|
32
|
+
}
|
|
33
|
+
return { themeMode, themeVariables };
|
|
34
|
+
}
|
|
35
|
+
function getOrCreateAdapter(projectId, theme) {
|
|
36
|
+
if (cachedAdapter && cachedProjectId === projectId) return cachedAdapter;
|
|
37
|
+
cachedAdapter = new WagmiAdapter({
|
|
38
|
+
networks: NETWORKS,
|
|
39
|
+
projectId
|
|
40
|
+
});
|
|
41
|
+
cachedProjectId = projectId;
|
|
42
|
+
const { themeMode, themeVariables } = mapTheme(theme);
|
|
43
|
+
createAppKit({
|
|
44
|
+
adapters: [cachedAdapter],
|
|
45
|
+
networks: NETWORKS,
|
|
46
|
+
projectId,
|
|
47
|
+
themeMode,
|
|
48
|
+
themeVariables,
|
|
49
|
+
features: {
|
|
50
|
+
connectMethodsOrder: ["wallet"],
|
|
51
|
+
email: false,
|
|
52
|
+
socials: false
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return cachedAdapter;
|
|
56
|
+
}
|
|
57
|
+
function ReownWalletProvider({
|
|
58
|
+
projectId,
|
|
59
|
+
theme,
|
|
60
|
+
children
|
|
61
|
+
}) {
|
|
62
|
+
const [queryClient] = useState(() => new QueryClient());
|
|
63
|
+
const adapter = getOrCreateAdapter(projectId, theme);
|
|
64
|
+
const config = adapter.wagmiConfig;
|
|
65
|
+
return /* @__PURE__ */ jsx(WagmiProvider, { config, children: /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children }) });
|
|
66
|
+
}
|
|
67
|
+
function useReownWallet() {
|
|
68
|
+
const { open } = useAppKit();
|
|
69
|
+
const { address, isConnected } = useAppKitAccount();
|
|
70
|
+
const { data: walletClient } = useWalletClient();
|
|
71
|
+
const publicClient = usePublicClient();
|
|
72
|
+
const { switchChainAsync } = useSwitchChain();
|
|
73
|
+
return {
|
|
74
|
+
walletClient: walletClient ?? void 0,
|
|
75
|
+
publicClient: publicClient ?? void 0,
|
|
76
|
+
address,
|
|
77
|
+
isConnected,
|
|
78
|
+
openConnect: () => {
|
|
79
|
+
void open({ view: isConnected ? "Account" : "Connect" });
|
|
80
|
+
},
|
|
81
|
+
switchChain: async (chainId) => {
|
|
82
|
+
await switchChainAsync({ chainId });
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export {
|
|
88
|
+
ReownWalletProvider,
|
|
89
|
+
useReownWallet
|
|
90
|
+
};
|