@rhinestone/deposit-modal 0.1.0 → 0.1.2
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 +146 -51
- package/dist/index.d.cts +52 -16
- package/dist/index.d.ts +52 -16
- package/dist/index.mjs +129 -49
- package/dist/styles.d.ts +3 -0
- package/package.json +12 -9
package/dist/index.cjs
CHANGED
|
@@ -24,10 +24,25 @@ __export(index_exports, {
|
|
|
24
24
|
DEFAULT_BACKEND_URL: () => DEFAULT_BACKEND_URL,
|
|
25
25
|
DEFAULT_SIGNER_ADDRESS: () => DEFAULT_SIGNER_ADDRESS,
|
|
26
26
|
DepositModal: () => DepositModal,
|
|
27
|
+
NATIVE_TOKEN_ADDRESS: () => NATIVE_TOKEN_ADDRESS,
|
|
27
28
|
SOURCE_CHAINS: () => SOURCE_CHAINS,
|
|
28
|
-
|
|
29
|
+
SUPPORTED_CHAINS: () => SUPPORTED_CHAINS,
|
|
30
|
+
chainRegistry: () => import_shared_configs.chainRegistry,
|
|
31
|
+
findChainIdForToken: () => findChainIdForToken,
|
|
32
|
+
getChainBadge: () => getChainBadge,
|
|
33
|
+
getChainIcon: () => getChainIcon,
|
|
34
|
+
getChainId: () => getChainId,
|
|
29
35
|
getChainName: () => getChainName,
|
|
30
|
-
|
|
36
|
+
getChainObject: () => getChainObject,
|
|
37
|
+
getExplorerName: () => getExplorerName,
|
|
38
|
+
getExplorerTxUrl: () => getExplorerTxUrl,
|
|
39
|
+
getExplorerUrl: () => getExplorerUrl,
|
|
40
|
+
getTokenAddress: () => getTokenAddress,
|
|
41
|
+
getTokenDecimals: () => getTokenDecimals,
|
|
42
|
+
getTokenIcon: () => getTokenIcon,
|
|
43
|
+
getTokenSymbol: () => getTokenSymbol,
|
|
44
|
+
getUsdcAddress: () => getUsdcAddress,
|
|
45
|
+
getUsdcDecimals: () => getUsdcDecimals
|
|
31
46
|
});
|
|
32
47
|
module.exports = __toCommonJS(index_exports);
|
|
33
48
|
|
|
@@ -288,28 +303,103 @@ var import_accounts = require("viem/accounts");
|
|
|
288
303
|
|
|
289
304
|
// src/core/constants.ts
|
|
290
305
|
var import_chains = require("viem/chains");
|
|
306
|
+
var import_shared_configs = require("@rhinestone/shared-configs");
|
|
291
307
|
var DEFAULT_BACKEND_URL = "https://v1.orchestrator.rhinestone.dev/deposit-widget";
|
|
292
308
|
var DEFAULT_SIGNER_ADDRESS = "0xcc47aa2d96c35bc6aab12ffb0e2edab8042274bd";
|
|
293
|
-
var SOURCE_CHAINS = [import_chains.base, import_chains.optimism, import_chains.arbitrum];
|
|
294
309
|
var NATIVE_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
295
|
-
var
|
|
296
|
-
[import_chains.base.id]: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
297
|
-
[import_chains.optimism.id]: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
|
|
298
|
-
[import_chains.arbitrum.id]: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831"
|
|
299
|
-
};
|
|
310
|
+
var SOURCE_CHAINS = [import_chains.base, import_chains.optimism, import_chains.arbitrum];
|
|
300
311
|
var CHAIN_BY_ID = {
|
|
301
312
|
[import_chains.base.id]: import_chains.base,
|
|
302
313
|
[import_chains.optimism.id]: import_chains.optimism,
|
|
303
314
|
[import_chains.arbitrum.id]: import_chains.arbitrum
|
|
304
315
|
};
|
|
305
316
|
var SUPPORTED_CHAINS = Object.values(CHAIN_BY_ID);
|
|
317
|
+
function getChainId(chain) {
|
|
318
|
+
return typeof chain === "number" ? chain : chain.id;
|
|
319
|
+
}
|
|
320
|
+
function getChainObject(chain) {
|
|
321
|
+
if (typeof chain === "number") {
|
|
322
|
+
return CHAIN_BY_ID[chain];
|
|
323
|
+
}
|
|
324
|
+
return chain;
|
|
325
|
+
}
|
|
326
|
+
function getTokenFromRegistry(chainId, symbol) {
|
|
327
|
+
const chainEntry = import_shared_configs.chainRegistry[String(chainId)];
|
|
328
|
+
if (!chainEntry) return void 0;
|
|
329
|
+
const token = chainEntry.tokens.find(
|
|
330
|
+
(t) => t.symbol.toUpperCase() === symbol.toUpperCase()
|
|
331
|
+
);
|
|
332
|
+
if (token) {
|
|
333
|
+
return { address: token.address, decimals: token.decimals };
|
|
334
|
+
}
|
|
335
|
+
return void 0;
|
|
336
|
+
}
|
|
337
|
+
function getUsdcAddress(chainId) {
|
|
338
|
+
const token = getTokenFromRegistry(chainId, "USDC");
|
|
339
|
+
return token?.address;
|
|
340
|
+
}
|
|
341
|
+
function getUsdcDecimals(chainId) {
|
|
342
|
+
const token = getTokenFromRegistry(chainId, "USDC");
|
|
343
|
+
return token?.decimals ?? 6;
|
|
344
|
+
}
|
|
345
|
+
function getTokenAddress(symbol, chainId) {
|
|
346
|
+
if (symbol.toUpperCase() === "ETH") {
|
|
347
|
+
return NATIVE_TOKEN_ADDRESS;
|
|
348
|
+
}
|
|
349
|
+
const token = getTokenFromRegistry(chainId, symbol);
|
|
350
|
+
return token?.address;
|
|
351
|
+
}
|
|
352
|
+
function getTokenDecimals(symbol, chainId) {
|
|
353
|
+
if (symbol.toUpperCase() === "ETH") {
|
|
354
|
+
return 18;
|
|
355
|
+
}
|
|
356
|
+
const token = getTokenFromRegistry(chainId, symbol);
|
|
357
|
+
return token?.decimals ?? 18;
|
|
358
|
+
}
|
|
359
|
+
function findChainIdForToken(address) {
|
|
360
|
+
const normalized = address.toLowerCase();
|
|
361
|
+
for (const [chainIdStr, chainEntry] of Object.entries(import_shared_configs.chainRegistry)) {
|
|
362
|
+
for (const token of chainEntry.tokens) {
|
|
363
|
+
if (token.address.toLowerCase() === normalized) {
|
|
364
|
+
return Number(chainIdStr);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return void 0;
|
|
369
|
+
}
|
|
370
|
+
function getTokenSymbol(token, chainId) {
|
|
371
|
+
const normalized = token.toLowerCase();
|
|
372
|
+
if (normalized === NATIVE_TOKEN_ADDRESS) {
|
|
373
|
+
return "ETH";
|
|
374
|
+
}
|
|
375
|
+
if (chainId) {
|
|
376
|
+
const chainEntry = import_shared_configs.chainRegistry[String(chainId)];
|
|
377
|
+
if (chainEntry) {
|
|
378
|
+
const found = chainEntry.tokens.find(
|
|
379
|
+
(t) => t.address.toLowerCase() === normalized
|
|
380
|
+
);
|
|
381
|
+
if (found) return found.symbol;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
for (const chainEntry of Object.values(import_shared_configs.chainRegistry)) {
|
|
385
|
+
const found = chainEntry.tokens.find(
|
|
386
|
+
(t) => t.address.toLowerCase() === normalized
|
|
387
|
+
);
|
|
388
|
+
if (found) return found.symbol;
|
|
389
|
+
}
|
|
390
|
+
return "Token";
|
|
391
|
+
}
|
|
306
392
|
var CHAIN_BADGES = {
|
|
307
393
|
[import_chains.base.id]: { shortLabel: "Base", color: "#0052FF", bg: "#E7F0FF" },
|
|
308
394
|
[import_chains.optimism.id]: { shortLabel: "OP", color: "#FF0420", bg: "#FFE9EC" },
|
|
309
395
|
[import_chains.arbitrum.id]: { shortLabel: "Arb", color: "#28A0F0", bg: "#E6F6FF" }
|
|
310
396
|
};
|
|
311
397
|
function getChainName(chainId) {
|
|
312
|
-
|
|
398
|
+
const chain = CHAIN_BY_ID[chainId];
|
|
399
|
+
if (chain) return chain.name;
|
|
400
|
+
const chainEntry = import_shared_configs.chainRegistry[String(chainId)];
|
|
401
|
+
if (chainEntry) return chainEntry.name;
|
|
402
|
+
return `Chain ${chainId}`;
|
|
313
403
|
}
|
|
314
404
|
function getChainBadge(chainId) {
|
|
315
405
|
return CHAIN_BADGES[chainId] || {
|
|
@@ -318,41 +408,18 @@ function getChainBadge(chainId) {
|
|
|
318
408
|
bg: "#F1F5F9"
|
|
319
409
|
};
|
|
320
410
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
[`USDC:${import_chains.arbitrum.id}`]: USDC_ADDRESSES[import_chains.arbitrum.id],
|
|
325
|
-
[`ETH:${import_chains.base.id}`]: NATIVE_TOKEN_ADDRESS,
|
|
326
|
-
[`ETH:${import_chains.optimism.id}`]: NATIVE_TOKEN_ADDRESS,
|
|
327
|
-
[`ETH:${import_chains.arbitrum.id}`]: NATIVE_TOKEN_ADDRESS
|
|
328
|
-
};
|
|
329
|
-
function getTokenAddress(symbol, chainId) {
|
|
330
|
-
return TOKEN_ADDRESSES[`${symbol}:${chainId}`];
|
|
411
|
+
function getExplorerUrl(chainId) {
|
|
412
|
+
const chain = CHAIN_BY_ID[chainId];
|
|
413
|
+
return chain?.blockExplorers?.default?.url;
|
|
331
414
|
}
|
|
332
|
-
var CHAIN_EXPLORERS = {
|
|
333
|
-
[import_chains.base.id]: { name: "Basescan", url: "https://basescan.org" },
|
|
334
|
-
[import_chains.optimism.id]: {
|
|
335
|
-
name: "Optimistic Etherscan",
|
|
336
|
-
url: "https://optimistic.etherscan.io"
|
|
337
|
-
},
|
|
338
|
-
[import_chains.arbitrum.id]: { name: "Arbiscan", url: "https://arbiscan.io" }
|
|
339
|
-
};
|
|
340
415
|
function getExplorerTxUrl(chainId, txHash) {
|
|
341
|
-
const
|
|
342
|
-
if (!
|
|
343
|
-
return `${
|
|
416
|
+
const url = getExplorerUrl(chainId);
|
|
417
|
+
if (!url) return void 0;
|
|
418
|
+
return `${url}/tx/${txHash}`;
|
|
344
419
|
}
|
|
345
|
-
function
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
return "ETH";
|
|
349
|
-
}
|
|
350
|
-
for (const address of Object.values(USDC_ADDRESSES)) {
|
|
351
|
-
if (address.toLowerCase() === normalized) {
|
|
352
|
-
return "USDC";
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
return "Token";
|
|
420
|
+
function getExplorerName(chainId) {
|
|
421
|
+
const chain = CHAIN_BY_ID[chainId];
|
|
422
|
+
return chain?.blockExplorers?.default?.name ?? "Explorer";
|
|
356
423
|
}
|
|
357
424
|
var CHAIN_ICONS = {
|
|
358
425
|
[import_chains.base.id]: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 111 111'%3E%3Ccircle cx='55.5' cy='55.5' r='55.5' fill='%230052FF'/%3E%3Cpath d='M54.921 93.4c20.942 0 37.92-16.978 37.92-37.921S75.863 17.558 54.92 17.558c-19.498 0-35.57 14.725-37.655 33.647h49.82v5.548h-49.82C19.351 75.675 35.423 93.4 54.921 93.4z' fill='%23fff'/%3E%3C/svg%3E",
|
|
@@ -363,7 +430,6 @@ var TOKEN_ICONS = {
|
|
|
363
430
|
USDC: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2000 2000'%3E%3Cpath d='M1000 2000c554.17 0 1000-445.83 1000-1000S1554.17 0 1000 0 0 445.83 0 1000s445.83 1000 1000 1000z' fill='%232775ca'/%3E%3Cpath d='M1275 1158.33c0-145.83-87.5-195.83-262.5-216.66-125-16.67-150-50-150-108.34s41.67-95.83 125-95.83c75 0 116.67 25 137.5 87.5 4.17 12.5 16.67 20.83 29.17 20.83h66.66c16.67 0 29.17-12.5 29.17-29.16v-4.17c-16.67-91.67-91.67-162.5-187.5-170.83v-100c0-16.67-12.5-29.17-33.33-33.34h-62.5c-16.67 0-29.17 12.5-33.34 33.34v95.83c-125 16.67-204.16 100-204.16 204.17 0 137.5 83.33 191.66 258.33 212.5 116.67 20.83 154.17 45.83 154.17 112.5s-58.34 112.5-137.5 112.5c-108.34 0-145.84-45.84-158.34-108.34-4.16-16.66-16.66-25-29.16-25h-70.84c-16.66 0-29.16 12.5-29.16 29.17v4.17c16.66 104.16 83.33 179.16 220.83 200v100c0 16.66 12.5 29.16 33.33 33.33h62.5c16.67 0 29.17-12.5 33.34-33.33v-100c125-20.84 208.33-108.34 208.33-220.84z' fill='%23fff'/%3E%3Cpath d='M787.5 1595.83c-325-116.66-491.67-479.16-370.83-800 62.5-175 200-308.33 370.83-370.83 16.67-8.33 25-20.83 25-41.67V325c0-16.67-8.33-29.17-25-33.33-4.17 0-12.5 0-16.67 4.16-395.83 125-612.5 545.84-487.5 941.67 75 233.33 254.17 412.5 487.5 487.5 16.67 8.33 33.34 0 37.5-16.67 4.17-4.16 4.17-8.33 4.17-16.66v-58.34c0-12.5-12.5-29.16-25-37.5zm441.67-1300c-16.67-8.33-33.34 0-37.5 16.67-4.17 4.17-4.17 8.33-4.17 16.67v58.33c0 16.67 12.5 33.33 25 41.67 325 116.66 491.67 479.16 370.83 800-62.5 175-200 308.33-370.83 370.83-16.67 8.33-25 20.83-25 41.67V1700c0 16.67 8.33 29.17 25 33.33 4.17 0 12.5 0 16.67-4.16 395.83-125 612.5-545.84 487.5-941.67-75-237.5-258.34-416.67-487.5-491.67z' fill='%23fff'/%3E%3C/svg%3E",
|
|
364
431
|
ETH: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 784.37 1277.39'%3E%3Cpolygon fill='%23343434' points='392.07 0 383.5 29.11 383.5 873.74 392.07 882.29 784.13 650.54'/%3E%3Cpolygon fill='%238C8C8C' points='392.07 0 0 650.54 392.07 882.29 392.07 472.33'/%3E%3Cpolygon fill='%233C3C3B' points='392.07 956.52 387.24 962.41 387.24 1263.28 392.07 1277.38 784.37 724.89'/%3E%3Cpolygon fill='%238C8C8C' points='392.07 1277.38 392.07 956.52 0 724.89'/%3E%3Cpolygon fill='%23141414' points='392.07 882.29 784.13 650.54 392.07 472.33'/%3E%3Cpolygon fill='%23393939' points='0 650.54 392.07 882.29 392.07 472.33'/%3E%3C/svg%3E",
|
|
365
432
|
USDT: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 339.43 295.27'%3E%3Cpath fill='%2350AF95' d='M62.15 1.45l-61.89 130a2.52 2.52 0 00.54 2.94l167.15 160.17a2.55 2.55 0 003.53 0L339.62 134.4a2.52 2.52 0 00.54-2.94l-61.89-130A2.5 2.5 0 00276 0H64.45a2.5 2.5 0 00-2.3 1.45z'/%3E%3Cpath fill='%23fff' d='M191.19 144.8v-.12c-1.09.07-5.42.33-15.55.33-8.09 0-13.81-.22-15.83-.33v.13c-31.22-1.38-54.6-7.1-54.6-14s23.38-12.58 54.6-14v22.28c2.05.14 7.92.46 16 .46 9.67 0 14.31-.38 15.38-.46v-22.29c31.13 1.38 54.42 7.06 54.42 13.95s-23.29 12.58-54.42 13.96zm0-30.29v-19.85h43.17V66.35H105.49v28.31h43.17v19.84c-35.37 1.59-62 8.76-62 17.33s26.59 15.74 62 17.33v62h30.53v-62c35.29-1.58 61.84-8.74 61.84-17.32s-26.55-15.74-61.84-17.33z'/%3E%3C/svg%3E",
|
|
366
|
-
USDT0: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 339.43 295.27'%3E%3Cpath fill='%2350AF95' d='M62.15 1.45l-61.89 130a2.52 2.52 0 00.54 2.94l167.15 160.17a2.55 2.55 0 003.53 0L339.62 134.4a2.52 2.52 0 00.54-2.94l-61.89-130A2.5 2.5 0 00276 0H64.45a2.5 2.5 0 00-2.3 1.45z'/%3E%3Cpath fill='%23fff' d='M191.19 144.8v-.12c-1.09.07-5.42.33-15.55.33-8.09 0-13.81-.22-15.83-.33v.13c-31.22-1.38-54.6-7.1-54.6-14s23.38-12.58 54.6-14v22.28c2.05.14 7.92.46 16 .46 9.67 0 14.31-.38 15.38-.46v-22.29c31.13 1.38 54.42 7.06 54.42 13.95s-23.29 12.58-54.42 13.96zm0-30.29v-19.85h43.17V66.35H105.49v28.31h43.17v19.84c-35.37 1.59-62 8.76-62 17.33s26.59 15.74 62 17.33v62h30.53v-62c35.29-1.58 61.84-8.74 61.84-17.32s-26.55-15.74-61.84-17.33z'/%3E%3C/svg%3E",
|
|
367
433
|
WETH: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 784.37 1277.39'%3E%3Cpolygon fill='%23EC1A79' points='392.07 0 383.5 29.11 383.5 873.74 392.07 882.29 784.13 650.54'/%3E%3Cpolygon fill='%23EC1A79' fill-opacity='0.6' points='392.07 0 0 650.54 392.07 882.29 392.07 472.33'/%3E%3Cpolygon fill='%239E1165' points='392.07 956.52 387.24 962.41 387.24 1263.28 392.07 1277.38 784.37 724.89'/%3E%3Cpolygon fill='%23EC1A79' fill-opacity='0.6' points='392.07 1277.38 392.07 956.52 0 724.89'/%3E%3Cpolygon fill='%239E1165' points='392.07 882.29 784.13 650.54 392.07 472.33'/%3E%3Cpolygon fill='%23EC1A79' fill-opacity='0.2' points='0 650.54 392.07 882.29 392.07 472.33'/%3E%3C/svg%3E"
|
|
368
434
|
};
|
|
369
435
|
function getChainIcon(chainId) {
|
|
@@ -442,7 +508,9 @@ async function signEnableSessionWithOwner(rhinestoneAccount, sessionDetails, sig
|
|
|
442
508
|
...originalOwners?.type === "ecdsa" && originalOwners.module ? { module: originalOwners.module } : {}
|
|
443
509
|
};
|
|
444
510
|
try {
|
|
445
|
-
return await rhinestoneAccount.experimental_signEnableSession(
|
|
511
|
+
return await rhinestoneAccount.experimental_signEnableSession(
|
|
512
|
+
sessionDetails
|
|
513
|
+
);
|
|
446
514
|
} finally {
|
|
447
515
|
rhinestoneAccount.config.owners = originalOwners;
|
|
448
516
|
}
|
|
@@ -454,7 +522,11 @@ async function getSessionDetails(rhinestoneAccount, targetChain, signerAddress,
|
|
|
454
522
|
}
|
|
455
523
|
const sessions = allChains.map((chain) => buildSession(chain, signerAddress));
|
|
456
524
|
const sessionDetails = await rhinestoneAccount.experimental_getSessionDetails(sessions);
|
|
457
|
-
const enableSignature = sessionSigner ? await signEnableSessionWithOwner(
|
|
525
|
+
const enableSignature = sessionSigner ? await signEnableSessionWithOwner(
|
|
526
|
+
rhinestoneAccount,
|
|
527
|
+
sessionDetails,
|
|
528
|
+
sessionSigner
|
|
529
|
+
) : await rhinestoneAccount.experimental_signEnableSession(sessionDetails);
|
|
458
530
|
if (!sessionDetails.hashesAndChainIds?.length) {
|
|
459
531
|
throw new Error("Session details missing chain digests");
|
|
460
532
|
}
|
|
@@ -2453,15 +2525,14 @@ function DepositModal({
|
|
|
2453
2525
|
walletClient,
|
|
2454
2526
|
publicClient,
|
|
2455
2527
|
address,
|
|
2456
|
-
targetChain,
|
|
2528
|
+
targetChain: targetChainProp,
|
|
2457
2529
|
targetToken,
|
|
2458
2530
|
isOpen,
|
|
2459
2531
|
onClose,
|
|
2460
2532
|
inline,
|
|
2461
2533
|
switchChain,
|
|
2462
|
-
sourceChain,
|
|
2534
|
+
sourceChain: sourceChainProp,
|
|
2463
2535
|
sourceToken,
|
|
2464
|
-
amount,
|
|
2465
2536
|
defaultAmount,
|
|
2466
2537
|
recipient,
|
|
2467
2538
|
backendUrl = DEFAULT_BACKEND_URL,
|
|
@@ -2472,20 +2543,29 @@ function DepositModal({
|
|
|
2472
2543
|
theme,
|
|
2473
2544
|
branding,
|
|
2474
2545
|
className,
|
|
2546
|
+
onReady,
|
|
2475
2547
|
onConnected,
|
|
2476
2548
|
onDepositSubmitted,
|
|
2477
2549
|
onDepositComplete,
|
|
2478
2550
|
onDepositFailed,
|
|
2479
2551
|
onError
|
|
2480
2552
|
}) {
|
|
2481
|
-
const resolvedAmount = amount ?? defaultAmount;
|
|
2482
2553
|
const modalRef = (0, import_react9.useRef)(null);
|
|
2554
|
+
const targetChain = getChainId(targetChainProp);
|
|
2555
|
+
const sourceChain = sourceChainProp ? getChainId(sourceChainProp) : void 0;
|
|
2483
2556
|
const service = (0, import_react9.useMemo)(() => createDepositService(backendUrl), [backendUrl]);
|
|
2484
2557
|
(0, import_react9.useEffect)(() => {
|
|
2485
2558
|
if (isOpen && modalRef.current) {
|
|
2486
2559
|
applyTheme(modalRef.current, theme);
|
|
2487
2560
|
}
|
|
2488
2561
|
}, [isOpen, theme]);
|
|
2562
|
+
const hasCalledReady = (0, import_react9.useRef)(false);
|
|
2563
|
+
(0, import_react9.useEffect)(() => {
|
|
2564
|
+
if (isOpen && !hasCalledReady.current) {
|
|
2565
|
+
hasCalledReady.current = true;
|
|
2566
|
+
onReady?.();
|
|
2567
|
+
}
|
|
2568
|
+
}, [isOpen, onReady]);
|
|
2489
2569
|
const logoUrl = branding?.logoUrl ?? "https://github.com/rhinestonewtf.png";
|
|
2490
2570
|
const title = branding?.title ?? "Rhinestone";
|
|
2491
2571
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
@@ -2559,7 +2639,7 @@ function DepositModal({
|
|
|
2559
2639
|
switchChain,
|
|
2560
2640
|
sourceChain,
|
|
2561
2641
|
sourceToken,
|
|
2562
|
-
amount:
|
|
2642
|
+
amount: defaultAmount,
|
|
2563
2643
|
recipient,
|
|
2564
2644
|
signerAddress,
|
|
2565
2645
|
waitForFinalTx,
|
|
@@ -2583,8 +2663,23 @@ DepositModal.displayName = "DepositModal";
|
|
|
2583
2663
|
DEFAULT_BACKEND_URL,
|
|
2584
2664
|
DEFAULT_SIGNER_ADDRESS,
|
|
2585
2665
|
DepositModal,
|
|
2666
|
+
NATIVE_TOKEN_ADDRESS,
|
|
2586
2667
|
SOURCE_CHAINS,
|
|
2587
|
-
|
|
2668
|
+
SUPPORTED_CHAINS,
|
|
2669
|
+
chainRegistry,
|
|
2670
|
+
findChainIdForToken,
|
|
2671
|
+
getChainBadge,
|
|
2672
|
+
getChainIcon,
|
|
2673
|
+
getChainId,
|
|
2588
2674
|
getChainName,
|
|
2589
|
-
|
|
2675
|
+
getChainObject,
|
|
2676
|
+
getExplorerName,
|
|
2677
|
+
getExplorerTxUrl,
|
|
2678
|
+
getExplorerUrl,
|
|
2679
|
+
getTokenAddress,
|
|
2680
|
+
getTokenDecimals,
|
|
2681
|
+
getTokenIcon,
|
|
2682
|
+
getTokenSymbol,
|
|
2683
|
+
getUsdcAddress,
|
|
2684
|
+
getUsdcDecimals
|
|
2590
2685
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { Address, Hex, WalletClient, PublicClient } from 'viem';
|
|
3
|
-
import { Chain } from 'viem/chains';
|
|
2
|
+
import { Address, Hex, WalletClient, PublicClient, Chain } from 'viem';
|
|
3
|
+
import { Chain as Chain$1 } from 'viem/chains';
|
|
4
|
+
export { chainRegistry } from '@rhinestone/shared-configs';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Theme configuration for the deposit modal.
|
|
@@ -73,8 +74,8 @@ interface DepositModalProps {
|
|
|
73
74
|
publicClient?: PublicClient | null;
|
|
74
75
|
/** Connected wallet address */
|
|
75
76
|
address?: Address | null;
|
|
76
|
-
/** Target chain
|
|
77
|
-
targetChain: number;
|
|
77
|
+
/** Target chain for the deposit (Chain object or chain ID) */
|
|
78
|
+
targetChain: Chain | number;
|
|
78
79
|
/** Target token address on the destination chain */
|
|
79
80
|
targetToken: Address;
|
|
80
81
|
/** Whether the modal is open */
|
|
@@ -86,15 +87,16 @@ interface DepositModalProps {
|
|
|
86
87
|
/**
|
|
87
88
|
* Callback for switching chains in the parent wallet.
|
|
88
89
|
* If provided, the modal will call this when user needs to switch chains.
|
|
90
|
+
* Returns the new chain (matching wagmi's switchChain return type).
|
|
89
91
|
*/
|
|
90
|
-
switchChain?: (chainId: number) => Promise<
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
switchChain?: (chainId: number) => Promise<{
|
|
93
|
+
id: number;
|
|
94
|
+
} | void>;
|
|
95
|
+
/** Pre-selected source chain (Chain object or chain ID) */
|
|
96
|
+
sourceChain?: Chain | number;
|
|
93
97
|
/** Pre-selected source token address */
|
|
94
98
|
sourceToken?: Address;
|
|
95
99
|
/** Pre-filled deposit amount */
|
|
96
|
-
amount?: string;
|
|
97
|
-
/** Pre-filled deposit amount (alias for amount) */
|
|
98
100
|
defaultAmount?: string;
|
|
99
101
|
/** Custom recipient address (defaults to smart account) */
|
|
100
102
|
recipient?: Address;
|
|
@@ -114,6 +116,8 @@ interface DepositModalProps {
|
|
|
114
116
|
branding?: DepositModalBranding;
|
|
115
117
|
/** Additional CSS class for the modal container */
|
|
116
118
|
className?: string;
|
|
119
|
+
/** Called when modal is fully initialized and ready */
|
|
120
|
+
onReady?: () => void;
|
|
117
121
|
/** Called when smart account is created and registered */
|
|
118
122
|
onConnected?: (data: ConnectedEventData) => void;
|
|
119
123
|
/** Called when user signs the transfer transaction */
|
|
@@ -139,7 +143,7 @@ interface AssetOption {
|
|
|
139
143
|
balanceUsd?: number;
|
|
140
144
|
}
|
|
141
145
|
|
|
142
|
-
declare function DepositModal({ walletClient, publicClient, address, targetChain, targetToken, isOpen, onClose, inline, switchChain, sourceChain, sourceToken,
|
|
146
|
+
declare function DepositModal({ walletClient, publicClient, address, targetChain: targetChainProp, targetToken, isOpen, onClose, inline, switchChain, sourceChain: sourceChainProp, sourceToken, defaultAmount, recipient, backendUrl, signerAddress, waitForFinalTx, onRequestConnect, connectButtonLabel, theme, branding, className, onReady, onConnected, onDepositSubmitted, onDepositComplete, onDepositFailed, onError, }: DepositModalProps): react_jsx_runtime.JSX.Element;
|
|
143
147
|
declare namespace DepositModal {
|
|
144
148
|
var displayName: string;
|
|
145
149
|
}
|
|
@@ -148,15 +152,47 @@ declare namespace DepositModal {
|
|
|
148
152
|
declare const DEFAULT_BACKEND_URL = "https://v1.orchestrator.rhinestone.dev/deposit-widget";
|
|
149
153
|
/** Default Rhinestone session signer address */
|
|
150
154
|
declare const DEFAULT_SIGNER_ADDRESS: Address;
|
|
151
|
-
/**
|
|
152
|
-
declare const
|
|
153
|
-
/**
|
|
154
|
-
declare const
|
|
155
|
+
/** Native token placeholder address */
|
|
156
|
+
declare const NATIVE_TOKEN_ADDRESS: Address;
|
|
157
|
+
/** Supported source chains for deposits */
|
|
158
|
+
declare const SOURCE_CHAINS: Chain$1[];
|
|
155
159
|
/** Chain lookup by ID */
|
|
156
|
-
declare const CHAIN_BY_ID: Record<number, Chain>;
|
|
160
|
+
declare const CHAIN_BY_ID: Record<number, Chain$1>;
|
|
161
|
+
/** All supported chains */
|
|
162
|
+
declare const SUPPORTED_CHAINS: Chain$1[];
|
|
163
|
+
/** Get chain ID from Chain object or number */
|
|
164
|
+
declare function getChainId(chain: Chain$1 | number): number;
|
|
165
|
+
/** Get chain object from Chain or number */
|
|
166
|
+
declare function getChainObject(chain: Chain$1 | number): Chain$1 | undefined;
|
|
167
|
+
/** Get USDC address for a chain */
|
|
168
|
+
declare function getUsdcAddress(chainId: number): Address | undefined;
|
|
169
|
+
/** Get USDC decimals for a chain (defaults to 6) */
|
|
170
|
+
declare function getUsdcDecimals(chainId: number): number;
|
|
171
|
+
/** Get token address by symbol and chain */
|
|
172
|
+
declare function getTokenAddress(symbol: string, chainId: number): Address | undefined;
|
|
173
|
+
/** Get token decimals by symbol and chain */
|
|
174
|
+
declare function getTokenDecimals(symbol: string, chainId: number): number;
|
|
175
|
+
/** Find chain ID for a token address */
|
|
176
|
+
declare function findChainIdForToken(address: Address): number | undefined;
|
|
177
|
+
/** Get token symbol from address and chain */
|
|
178
|
+
declare function getTokenSymbol(token: Address, chainId?: number): string;
|
|
157
179
|
/** Get human-readable chain name */
|
|
158
180
|
declare function getChainName(chainId: number): string;
|
|
181
|
+
/** Get chain badge styling */
|
|
182
|
+
declare function getChainBadge(chainId: number): {
|
|
183
|
+
shortLabel: string;
|
|
184
|
+
color: string;
|
|
185
|
+
bg: string;
|
|
186
|
+
};
|
|
187
|
+
/** Get block explorer URL for a chain */
|
|
188
|
+
declare function getExplorerUrl(chainId: number): string | undefined;
|
|
159
189
|
/** Get block explorer transaction URL */
|
|
160
190
|
declare function getExplorerTxUrl(chainId: number, txHash: string): string | undefined;
|
|
191
|
+
/** Get block explorer name */
|
|
192
|
+
declare function getExplorerName(chainId: number): string;
|
|
193
|
+
/** Get chain icon URL */
|
|
194
|
+
declare function getChainIcon(chainId: number): string | undefined;
|
|
195
|
+
/** Get token icon URL */
|
|
196
|
+
declare function getTokenIcon(symbol: string): string | undefined;
|
|
161
197
|
|
|
162
|
-
export { type AssetOption, CHAIN_BY_ID, type ConnectedEventData, DEFAULT_BACKEND_URL, DEFAULT_SIGNER_ADDRESS, type DepositCompleteEventData, type DepositFailedEventData, DepositModal, type DepositModalBranding, type DepositModalProps, type DepositModalTheme, type DepositSubmittedEventData, type ErrorEventData, SOURCE_CHAINS,
|
|
198
|
+
export { type AssetOption, CHAIN_BY_ID, type ConnectedEventData, DEFAULT_BACKEND_URL, DEFAULT_SIGNER_ADDRESS, type DepositCompleteEventData, type DepositFailedEventData, DepositModal, type DepositModalBranding, type DepositModalProps, type DepositModalTheme, type DepositSubmittedEventData, type ErrorEventData, NATIVE_TOKEN_ADDRESS, SOURCE_CHAINS, SUPPORTED_CHAINS, findChainIdForToken, getChainBadge, getChainIcon, getChainId, getChainName, getChainObject, getExplorerName, getExplorerTxUrl, getExplorerUrl, getTokenAddress, getTokenDecimals, getTokenIcon, getTokenSymbol, getUsdcAddress, getUsdcDecimals };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { Address, Hex, WalletClient, PublicClient } from 'viem';
|
|
3
|
-
import { Chain } from 'viem/chains';
|
|
2
|
+
import { Address, Hex, WalletClient, PublicClient, Chain } from 'viem';
|
|
3
|
+
import { Chain as Chain$1 } from 'viem/chains';
|
|
4
|
+
export { chainRegistry } from '@rhinestone/shared-configs';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Theme configuration for the deposit modal.
|
|
@@ -73,8 +74,8 @@ interface DepositModalProps {
|
|
|
73
74
|
publicClient?: PublicClient | null;
|
|
74
75
|
/** Connected wallet address */
|
|
75
76
|
address?: Address | null;
|
|
76
|
-
/** Target chain
|
|
77
|
-
targetChain: number;
|
|
77
|
+
/** Target chain for the deposit (Chain object or chain ID) */
|
|
78
|
+
targetChain: Chain | number;
|
|
78
79
|
/** Target token address on the destination chain */
|
|
79
80
|
targetToken: Address;
|
|
80
81
|
/** Whether the modal is open */
|
|
@@ -86,15 +87,16 @@ interface DepositModalProps {
|
|
|
86
87
|
/**
|
|
87
88
|
* Callback for switching chains in the parent wallet.
|
|
88
89
|
* If provided, the modal will call this when user needs to switch chains.
|
|
90
|
+
* Returns the new chain (matching wagmi's switchChain return type).
|
|
89
91
|
*/
|
|
90
|
-
switchChain?: (chainId: number) => Promise<
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
switchChain?: (chainId: number) => Promise<{
|
|
93
|
+
id: number;
|
|
94
|
+
} | void>;
|
|
95
|
+
/** Pre-selected source chain (Chain object or chain ID) */
|
|
96
|
+
sourceChain?: Chain | number;
|
|
93
97
|
/** Pre-selected source token address */
|
|
94
98
|
sourceToken?: Address;
|
|
95
99
|
/** Pre-filled deposit amount */
|
|
96
|
-
amount?: string;
|
|
97
|
-
/** Pre-filled deposit amount (alias for amount) */
|
|
98
100
|
defaultAmount?: string;
|
|
99
101
|
/** Custom recipient address (defaults to smart account) */
|
|
100
102
|
recipient?: Address;
|
|
@@ -114,6 +116,8 @@ interface DepositModalProps {
|
|
|
114
116
|
branding?: DepositModalBranding;
|
|
115
117
|
/** Additional CSS class for the modal container */
|
|
116
118
|
className?: string;
|
|
119
|
+
/** Called when modal is fully initialized and ready */
|
|
120
|
+
onReady?: () => void;
|
|
117
121
|
/** Called when smart account is created and registered */
|
|
118
122
|
onConnected?: (data: ConnectedEventData) => void;
|
|
119
123
|
/** Called when user signs the transfer transaction */
|
|
@@ -139,7 +143,7 @@ interface AssetOption {
|
|
|
139
143
|
balanceUsd?: number;
|
|
140
144
|
}
|
|
141
145
|
|
|
142
|
-
declare function DepositModal({ walletClient, publicClient, address, targetChain, targetToken, isOpen, onClose, inline, switchChain, sourceChain, sourceToken,
|
|
146
|
+
declare function DepositModal({ walletClient, publicClient, address, targetChain: targetChainProp, targetToken, isOpen, onClose, inline, switchChain, sourceChain: sourceChainProp, sourceToken, defaultAmount, recipient, backendUrl, signerAddress, waitForFinalTx, onRequestConnect, connectButtonLabel, theme, branding, className, onReady, onConnected, onDepositSubmitted, onDepositComplete, onDepositFailed, onError, }: DepositModalProps): react_jsx_runtime.JSX.Element;
|
|
143
147
|
declare namespace DepositModal {
|
|
144
148
|
var displayName: string;
|
|
145
149
|
}
|
|
@@ -148,15 +152,47 @@ declare namespace DepositModal {
|
|
|
148
152
|
declare const DEFAULT_BACKEND_URL = "https://v1.orchestrator.rhinestone.dev/deposit-widget";
|
|
149
153
|
/** Default Rhinestone session signer address */
|
|
150
154
|
declare const DEFAULT_SIGNER_ADDRESS: Address;
|
|
151
|
-
/**
|
|
152
|
-
declare const
|
|
153
|
-
/**
|
|
154
|
-
declare const
|
|
155
|
+
/** Native token placeholder address */
|
|
156
|
+
declare const NATIVE_TOKEN_ADDRESS: Address;
|
|
157
|
+
/** Supported source chains for deposits */
|
|
158
|
+
declare const SOURCE_CHAINS: Chain$1[];
|
|
155
159
|
/** Chain lookup by ID */
|
|
156
|
-
declare const CHAIN_BY_ID: Record<number, Chain>;
|
|
160
|
+
declare const CHAIN_BY_ID: Record<number, Chain$1>;
|
|
161
|
+
/** All supported chains */
|
|
162
|
+
declare const SUPPORTED_CHAINS: Chain$1[];
|
|
163
|
+
/** Get chain ID from Chain object or number */
|
|
164
|
+
declare function getChainId(chain: Chain$1 | number): number;
|
|
165
|
+
/** Get chain object from Chain or number */
|
|
166
|
+
declare function getChainObject(chain: Chain$1 | number): Chain$1 | undefined;
|
|
167
|
+
/** Get USDC address for a chain */
|
|
168
|
+
declare function getUsdcAddress(chainId: number): Address | undefined;
|
|
169
|
+
/** Get USDC decimals for a chain (defaults to 6) */
|
|
170
|
+
declare function getUsdcDecimals(chainId: number): number;
|
|
171
|
+
/** Get token address by symbol and chain */
|
|
172
|
+
declare function getTokenAddress(symbol: string, chainId: number): Address | undefined;
|
|
173
|
+
/** Get token decimals by symbol and chain */
|
|
174
|
+
declare function getTokenDecimals(symbol: string, chainId: number): number;
|
|
175
|
+
/** Find chain ID for a token address */
|
|
176
|
+
declare function findChainIdForToken(address: Address): number | undefined;
|
|
177
|
+
/** Get token symbol from address and chain */
|
|
178
|
+
declare function getTokenSymbol(token: Address, chainId?: number): string;
|
|
157
179
|
/** Get human-readable chain name */
|
|
158
180
|
declare function getChainName(chainId: number): string;
|
|
181
|
+
/** Get chain badge styling */
|
|
182
|
+
declare function getChainBadge(chainId: number): {
|
|
183
|
+
shortLabel: string;
|
|
184
|
+
color: string;
|
|
185
|
+
bg: string;
|
|
186
|
+
};
|
|
187
|
+
/** Get block explorer URL for a chain */
|
|
188
|
+
declare function getExplorerUrl(chainId: number): string | undefined;
|
|
159
189
|
/** Get block explorer transaction URL */
|
|
160
190
|
declare function getExplorerTxUrl(chainId: number, txHash: string): string | undefined;
|
|
191
|
+
/** Get block explorer name */
|
|
192
|
+
declare function getExplorerName(chainId: number): string;
|
|
193
|
+
/** Get chain icon URL */
|
|
194
|
+
declare function getChainIcon(chainId: number): string | undefined;
|
|
195
|
+
/** Get token icon URL */
|
|
196
|
+
declare function getTokenIcon(symbol: string): string | undefined;
|
|
161
197
|
|
|
162
|
-
export { type AssetOption, CHAIN_BY_ID, type ConnectedEventData, DEFAULT_BACKEND_URL, DEFAULT_SIGNER_ADDRESS, type DepositCompleteEventData, type DepositFailedEventData, DepositModal, type DepositModalBranding, type DepositModalProps, type DepositModalTheme, type DepositSubmittedEventData, type ErrorEventData, SOURCE_CHAINS,
|
|
198
|
+
export { type AssetOption, CHAIN_BY_ID, type ConnectedEventData, DEFAULT_BACKEND_URL, DEFAULT_SIGNER_ADDRESS, type DepositCompleteEventData, type DepositFailedEventData, DepositModal, type DepositModalBranding, type DepositModalProps, type DepositModalTheme, type DepositSubmittedEventData, type ErrorEventData, NATIVE_TOKEN_ADDRESS, SOURCE_CHAINS, SUPPORTED_CHAINS, findChainIdForToken, getChainBadge, getChainIcon, getChainId, getChainName, getChainObject, getExplorerName, getExplorerTxUrl, getExplorerUrl, getTokenAddress, getTokenDecimals, getTokenIcon, getTokenSymbol, getUsdcAddress, getUsdcDecimals };
|
package/dist/index.mjs
CHANGED
|
@@ -261,28 +261,103 @@ import { toAccount } from "viem/accounts";
|
|
|
261
261
|
|
|
262
262
|
// src/core/constants.ts
|
|
263
263
|
import { base, optimism, arbitrum } from "viem/chains";
|
|
264
|
+
import { chainRegistry } from "@rhinestone/shared-configs";
|
|
264
265
|
var DEFAULT_BACKEND_URL = "https://v1.orchestrator.rhinestone.dev/deposit-widget";
|
|
265
266
|
var DEFAULT_SIGNER_ADDRESS = "0xcc47aa2d96c35bc6aab12ffb0e2edab8042274bd";
|
|
266
|
-
var SOURCE_CHAINS = [base, optimism, arbitrum];
|
|
267
267
|
var NATIVE_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
268
|
-
var
|
|
269
|
-
[base.id]: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
270
|
-
[optimism.id]: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
|
|
271
|
-
[arbitrum.id]: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831"
|
|
272
|
-
};
|
|
268
|
+
var SOURCE_CHAINS = [base, optimism, arbitrum];
|
|
273
269
|
var CHAIN_BY_ID = {
|
|
274
270
|
[base.id]: base,
|
|
275
271
|
[optimism.id]: optimism,
|
|
276
272
|
[arbitrum.id]: arbitrum
|
|
277
273
|
};
|
|
278
274
|
var SUPPORTED_CHAINS = Object.values(CHAIN_BY_ID);
|
|
275
|
+
function getChainId(chain) {
|
|
276
|
+
return typeof chain === "number" ? chain : chain.id;
|
|
277
|
+
}
|
|
278
|
+
function getChainObject(chain) {
|
|
279
|
+
if (typeof chain === "number") {
|
|
280
|
+
return CHAIN_BY_ID[chain];
|
|
281
|
+
}
|
|
282
|
+
return chain;
|
|
283
|
+
}
|
|
284
|
+
function getTokenFromRegistry(chainId, symbol) {
|
|
285
|
+
const chainEntry = chainRegistry[String(chainId)];
|
|
286
|
+
if (!chainEntry) return void 0;
|
|
287
|
+
const token = chainEntry.tokens.find(
|
|
288
|
+
(t) => t.symbol.toUpperCase() === symbol.toUpperCase()
|
|
289
|
+
);
|
|
290
|
+
if (token) {
|
|
291
|
+
return { address: token.address, decimals: token.decimals };
|
|
292
|
+
}
|
|
293
|
+
return void 0;
|
|
294
|
+
}
|
|
295
|
+
function getUsdcAddress(chainId) {
|
|
296
|
+
const token = getTokenFromRegistry(chainId, "USDC");
|
|
297
|
+
return token?.address;
|
|
298
|
+
}
|
|
299
|
+
function getUsdcDecimals(chainId) {
|
|
300
|
+
const token = getTokenFromRegistry(chainId, "USDC");
|
|
301
|
+
return token?.decimals ?? 6;
|
|
302
|
+
}
|
|
303
|
+
function getTokenAddress(symbol, chainId) {
|
|
304
|
+
if (symbol.toUpperCase() === "ETH") {
|
|
305
|
+
return NATIVE_TOKEN_ADDRESS;
|
|
306
|
+
}
|
|
307
|
+
const token = getTokenFromRegistry(chainId, symbol);
|
|
308
|
+
return token?.address;
|
|
309
|
+
}
|
|
310
|
+
function getTokenDecimals(symbol, chainId) {
|
|
311
|
+
if (symbol.toUpperCase() === "ETH") {
|
|
312
|
+
return 18;
|
|
313
|
+
}
|
|
314
|
+
const token = getTokenFromRegistry(chainId, symbol);
|
|
315
|
+
return token?.decimals ?? 18;
|
|
316
|
+
}
|
|
317
|
+
function findChainIdForToken(address) {
|
|
318
|
+
const normalized = address.toLowerCase();
|
|
319
|
+
for (const [chainIdStr, chainEntry] of Object.entries(chainRegistry)) {
|
|
320
|
+
for (const token of chainEntry.tokens) {
|
|
321
|
+
if (token.address.toLowerCase() === normalized) {
|
|
322
|
+
return Number(chainIdStr);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return void 0;
|
|
327
|
+
}
|
|
328
|
+
function getTokenSymbol(token, chainId) {
|
|
329
|
+
const normalized = token.toLowerCase();
|
|
330
|
+
if (normalized === NATIVE_TOKEN_ADDRESS) {
|
|
331
|
+
return "ETH";
|
|
332
|
+
}
|
|
333
|
+
if (chainId) {
|
|
334
|
+
const chainEntry = chainRegistry[String(chainId)];
|
|
335
|
+
if (chainEntry) {
|
|
336
|
+
const found = chainEntry.tokens.find(
|
|
337
|
+
(t) => t.address.toLowerCase() === normalized
|
|
338
|
+
);
|
|
339
|
+
if (found) return found.symbol;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
for (const chainEntry of Object.values(chainRegistry)) {
|
|
343
|
+
const found = chainEntry.tokens.find(
|
|
344
|
+
(t) => t.address.toLowerCase() === normalized
|
|
345
|
+
);
|
|
346
|
+
if (found) return found.symbol;
|
|
347
|
+
}
|
|
348
|
+
return "Token";
|
|
349
|
+
}
|
|
279
350
|
var CHAIN_BADGES = {
|
|
280
351
|
[base.id]: { shortLabel: "Base", color: "#0052FF", bg: "#E7F0FF" },
|
|
281
352
|
[optimism.id]: { shortLabel: "OP", color: "#FF0420", bg: "#FFE9EC" },
|
|
282
353
|
[arbitrum.id]: { shortLabel: "Arb", color: "#28A0F0", bg: "#E6F6FF" }
|
|
283
354
|
};
|
|
284
355
|
function getChainName(chainId) {
|
|
285
|
-
|
|
356
|
+
const chain = CHAIN_BY_ID[chainId];
|
|
357
|
+
if (chain) return chain.name;
|
|
358
|
+
const chainEntry = chainRegistry[String(chainId)];
|
|
359
|
+
if (chainEntry) return chainEntry.name;
|
|
360
|
+
return `Chain ${chainId}`;
|
|
286
361
|
}
|
|
287
362
|
function getChainBadge(chainId) {
|
|
288
363
|
return CHAIN_BADGES[chainId] || {
|
|
@@ -291,41 +366,18 @@ function getChainBadge(chainId) {
|
|
|
291
366
|
bg: "#F1F5F9"
|
|
292
367
|
};
|
|
293
368
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
[`USDC:${arbitrum.id}`]: USDC_ADDRESSES[arbitrum.id],
|
|
298
|
-
[`ETH:${base.id}`]: NATIVE_TOKEN_ADDRESS,
|
|
299
|
-
[`ETH:${optimism.id}`]: NATIVE_TOKEN_ADDRESS,
|
|
300
|
-
[`ETH:${arbitrum.id}`]: NATIVE_TOKEN_ADDRESS
|
|
301
|
-
};
|
|
302
|
-
function getTokenAddress(symbol, chainId) {
|
|
303
|
-
return TOKEN_ADDRESSES[`${symbol}:${chainId}`];
|
|
369
|
+
function getExplorerUrl(chainId) {
|
|
370
|
+
const chain = CHAIN_BY_ID[chainId];
|
|
371
|
+
return chain?.blockExplorers?.default?.url;
|
|
304
372
|
}
|
|
305
|
-
var CHAIN_EXPLORERS = {
|
|
306
|
-
[base.id]: { name: "Basescan", url: "https://basescan.org" },
|
|
307
|
-
[optimism.id]: {
|
|
308
|
-
name: "Optimistic Etherscan",
|
|
309
|
-
url: "https://optimistic.etherscan.io"
|
|
310
|
-
},
|
|
311
|
-
[arbitrum.id]: { name: "Arbiscan", url: "https://arbiscan.io" }
|
|
312
|
-
};
|
|
313
373
|
function getExplorerTxUrl(chainId, txHash) {
|
|
314
|
-
const
|
|
315
|
-
if (!
|
|
316
|
-
return `${
|
|
374
|
+
const url = getExplorerUrl(chainId);
|
|
375
|
+
if (!url) return void 0;
|
|
376
|
+
return `${url}/tx/${txHash}`;
|
|
317
377
|
}
|
|
318
|
-
function
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
return "ETH";
|
|
322
|
-
}
|
|
323
|
-
for (const address of Object.values(USDC_ADDRESSES)) {
|
|
324
|
-
if (address.toLowerCase() === normalized) {
|
|
325
|
-
return "USDC";
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
return "Token";
|
|
378
|
+
function getExplorerName(chainId) {
|
|
379
|
+
const chain = CHAIN_BY_ID[chainId];
|
|
380
|
+
return chain?.blockExplorers?.default?.name ?? "Explorer";
|
|
329
381
|
}
|
|
330
382
|
var CHAIN_ICONS = {
|
|
331
383
|
[base.id]: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 111 111'%3E%3Ccircle cx='55.5' cy='55.5' r='55.5' fill='%230052FF'/%3E%3Cpath d='M54.921 93.4c20.942 0 37.92-16.978 37.92-37.921S75.863 17.558 54.92 17.558c-19.498 0-35.57 14.725-37.655 33.647h49.82v5.548h-49.82C19.351 75.675 35.423 93.4 54.921 93.4z' fill='%23fff'/%3E%3C/svg%3E",
|
|
@@ -336,7 +388,6 @@ var TOKEN_ICONS = {
|
|
|
336
388
|
USDC: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2000 2000'%3E%3Cpath d='M1000 2000c554.17 0 1000-445.83 1000-1000S1554.17 0 1000 0 0 445.83 0 1000s445.83 1000 1000 1000z' fill='%232775ca'/%3E%3Cpath d='M1275 1158.33c0-145.83-87.5-195.83-262.5-216.66-125-16.67-150-50-150-108.34s41.67-95.83 125-95.83c75 0 116.67 25 137.5 87.5 4.17 12.5 16.67 20.83 29.17 20.83h66.66c16.67 0 29.17-12.5 29.17-29.16v-4.17c-16.67-91.67-91.67-162.5-187.5-170.83v-100c0-16.67-12.5-29.17-33.33-33.34h-62.5c-16.67 0-29.17 12.5-33.34 33.34v95.83c-125 16.67-204.16 100-204.16 204.17 0 137.5 83.33 191.66 258.33 212.5 116.67 20.83 154.17 45.83 154.17 112.5s-58.34 112.5-137.5 112.5c-108.34 0-145.84-45.84-158.34-108.34-4.16-16.66-16.66-25-29.16-25h-70.84c-16.66 0-29.16 12.5-29.16 29.17v4.17c16.66 104.16 83.33 179.16 220.83 200v100c0 16.66 12.5 29.16 33.33 33.33h62.5c16.67 0 29.17-12.5 33.34-33.33v-100c125-20.84 208.33-108.34 208.33-220.84z' fill='%23fff'/%3E%3Cpath d='M787.5 1595.83c-325-116.66-491.67-479.16-370.83-800 62.5-175 200-308.33 370.83-370.83 16.67-8.33 25-20.83 25-41.67V325c0-16.67-8.33-29.17-25-33.33-4.17 0-12.5 0-16.67 4.16-395.83 125-612.5 545.84-487.5 941.67 75 233.33 254.17 412.5 487.5 487.5 16.67 8.33 33.34 0 37.5-16.67 4.17-4.16 4.17-8.33 4.17-16.66v-58.34c0-12.5-12.5-29.16-25-37.5zm441.67-1300c-16.67-8.33-33.34 0-37.5 16.67-4.17 4.17-4.17 8.33-4.17 16.67v58.33c0 16.67 12.5 33.33 25 41.67 325 116.66 491.67 479.16 370.83 800-62.5 175-200 308.33-370.83 370.83-16.67 8.33-25 20.83-25 41.67V1700c0 16.67 8.33 29.17 25 33.33 4.17 0 12.5 0 16.67-4.16 395.83-125 612.5-545.84 487.5-941.67-75-237.5-258.34-416.67-487.5-491.67z' fill='%23fff'/%3E%3C/svg%3E",
|
|
337
389
|
ETH: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 784.37 1277.39'%3E%3Cpolygon fill='%23343434' points='392.07 0 383.5 29.11 383.5 873.74 392.07 882.29 784.13 650.54'/%3E%3Cpolygon fill='%238C8C8C' points='392.07 0 0 650.54 392.07 882.29 392.07 472.33'/%3E%3Cpolygon fill='%233C3C3B' points='392.07 956.52 387.24 962.41 387.24 1263.28 392.07 1277.38 784.37 724.89'/%3E%3Cpolygon fill='%238C8C8C' points='392.07 1277.38 392.07 956.52 0 724.89'/%3E%3Cpolygon fill='%23141414' points='392.07 882.29 784.13 650.54 392.07 472.33'/%3E%3Cpolygon fill='%23393939' points='0 650.54 392.07 882.29 392.07 472.33'/%3E%3C/svg%3E",
|
|
338
390
|
USDT: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 339.43 295.27'%3E%3Cpath fill='%2350AF95' d='M62.15 1.45l-61.89 130a2.52 2.52 0 00.54 2.94l167.15 160.17a2.55 2.55 0 003.53 0L339.62 134.4a2.52 2.52 0 00.54-2.94l-61.89-130A2.5 2.5 0 00276 0H64.45a2.5 2.5 0 00-2.3 1.45z'/%3E%3Cpath fill='%23fff' d='M191.19 144.8v-.12c-1.09.07-5.42.33-15.55.33-8.09 0-13.81-.22-15.83-.33v.13c-31.22-1.38-54.6-7.1-54.6-14s23.38-12.58 54.6-14v22.28c2.05.14 7.92.46 16 .46 9.67 0 14.31-.38 15.38-.46v-22.29c31.13 1.38 54.42 7.06 54.42 13.95s-23.29 12.58-54.42 13.96zm0-30.29v-19.85h43.17V66.35H105.49v28.31h43.17v19.84c-35.37 1.59-62 8.76-62 17.33s26.59 15.74 62 17.33v62h30.53v-62c35.29-1.58 61.84-8.74 61.84-17.32s-26.55-15.74-61.84-17.33z'/%3E%3C/svg%3E",
|
|
339
|
-
USDT0: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 339.43 295.27'%3E%3Cpath fill='%2350AF95' d='M62.15 1.45l-61.89 130a2.52 2.52 0 00.54 2.94l167.15 160.17a2.55 2.55 0 003.53 0L339.62 134.4a2.52 2.52 0 00.54-2.94l-61.89-130A2.5 2.5 0 00276 0H64.45a2.5 2.5 0 00-2.3 1.45z'/%3E%3Cpath fill='%23fff' d='M191.19 144.8v-.12c-1.09.07-5.42.33-15.55.33-8.09 0-13.81-.22-15.83-.33v.13c-31.22-1.38-54.6-7.1-54.6-14s23.38-12.58 54.6-14v22.28c2.05.14 7.92.46 16 .46 9.67 0 14.31-.38 15.38-.46v-22.29c31.13 1.38 54.42 7.06 54.42 13.95s-23.29 12.58-54.42 13.96zm0-30.29v-19.85h43.17V66.35H105.49v28.31h43.17v19.84c-35.37 1.59-62 8.76-62 17.33s26.59 15.74 62 17.33v62h30.53v-62c35.29-1.58 61.84-8.74 61.84-17.32s-26.55-15.74-61.84-17.33z'/%3E%3C/svg%3E",
|
|
340
391
|
WETH: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 784.37 1277.39'%3E%3Cpolygon fill='%23EC1A79' points='392.07 0 383.5 29.11 383.5 873.74 392.07 882.29 784.13 650.54'/%3E%3Cpolygon fill='%23EC1A79' fill-opacity='0.6' points='392.07 0 0 650.54 392.07 882.29 392.07 472.33'/%3E%3Cpolygon fill='%239E1165' points='392.07 956.52 387.24 962.41 387.24 1263.28 392.07 1277.38 784.37 724.89'/%3E%3Cpolygon fill='%23EC1A79' fill-opacity='0.6' points='392.07 1277.38 392.07 956.52 0 724.89'/%3E%3Cpolygon fill='%239E1165' points='392.07 882.29 784.13 650.54 392.07 472.33'/%3E%3Cpolygon fill='%23EC1A79' fill-opacity='0.2' points='0 650.54 392.07 882.29 392.07 472.33'/%3E%3C/svg%3E"
|
|
341
392
|
};
|
|
342
393
|
function getChainIcon(chainId) {
|
|
@@ -415,7 +466,9 @@ async function signEnableSessionWithOwner(rhinestoneAccount, sessionDetails, sig
|
|
|
415
466
|
...originalOwners?.type === "ecdsa" && originalOwners.module ? { module: originalOwners.module } : {}
|
|
416
467
|
};
|
|
417
468
|
try {
|
|
418
|
-
return await rhinestoneAccount.experimental_signEnableSession(
|
|
469
|
+
return await rhinestoneAccount.experimental_signEnableSession(
|
|
470
|
+
sessionDetails
|
|
471
|
+
);
|
|
419
472
|
} finally {
|
|
420
473
|
rhinestoneAccount.config.owners = originalOwners;
|
|
421
474
|
}
|
|
@@ -427,7 +480,11 @@ async function getSessionDetails(rhinestoneAccount, targetChain, signerAddress,
|
|
|
427
480
|
}
|
|
428
481
|
const sessions = allChains.map((chain) => buildSession(chain, signerAddress));
|
|
429
482
|
const sessionDetails = await rhinestoneAccount.experimental_getSessionDetails(sessions);
|
|
430
|
-
const enableSignature = sessionSigner ? await signEnableSessionWithOwner(
|
|
483
|
+
const enableSignature = sessionSigner ? await signEnableSessionWithOwner(
|
|
484
|
+
rhinestoneAccount,
|
|
485
|
+
sessionDetails,
|
|
486
|
+
sessionSigner
|
|
487
|
+
) : await rhinestoneAccount.experimental_signEnableSession(sessionDetails);
|
|
431
488
|
if (!sessionDetails.hashesAndChainIds?.length) {
|
|
432
489
|
throw new Error("Session details missing chain digests");
|
|
433
490
|
}
|
|
@@ -2429,15 +2486,14 @@ function DepositModal({
|
|
|
2429
2486
|
walletClient,
|
|
2430
2487
|
publicClient,
|
|
2431
2488
|
address,
|
|
2432
|
-
targetChain,
|
|
2489
|
+
targetChain: targetChainProp,
|
|
2433
2490
|
targetToken,
|
|
2434
2491
|
isOpen,
|
|
2435
2492
|
onClose,
|
|
2436
2493
|
inline,
|
|
2437
2494
|
switchChain,
|
|
2438
|
-
sourceChain,
|
|
2495
|
+
sourceChain: sourceChainProp,
|
|
2439
2496
|
sourceToken,
|
|
2440
|
-
amount,
|
|
2441
2497
|
defaultAmount,
|
|
2442
2498
|
recipient,
|
|
2443
2499
|
backendUrl = DEFAULT_BACKEND_URL,
|
|
@@ -2448,20 +2504,29 @@ function DepositModal({
|
|
|
2448
2504
|
theme,
|
|
2449
2505
|
branding,
|
|
2450
2506
|
className,
|
|
2507
|
+
onReady,
|
|
2451
2508
|
onConnected,
|
|
2452
2509
|
onDepositSubmitted,
|
|
2453
2510
|
onDepositComplete,
|
|
2454
2511
|
onDepositFailed,
|
|
2455
2512
|
onError
|
|
2456
2513
|
}) {
|
|
2457
|
-
const resolvedAmount = amount ?? defaultAmount;
|
|
2458
2514
|
const modalRef = useRef5(null);
|
|
2515
|
+
const targetChain = getChainId(targetChainProp);
|
|
2516
|
+
const sourceChain = sourceChainProp ? getChainId(sourceChainProp) : void 0;
|
|
2459
2517
|
const service = useMemo5(() => createDepositService(backendUrl), [backendUrl]);
|
|
2460
2518
|
useEffect7(() => {
|
|
2461
2519
|
if (isOpen && modalRef.current) {
|
|
2462
2520
|
applyTheme(modalRef.current, theme);
|
|
2463
2521
|
}
|
|
2464
2522
|
}, [isOpen, theme]);
|
|
2523
|
+
const hasCalledReady = useRef5(false);
|
|
2524
|
+
useEffect7(() => {
|
|
2525
|
+
if (isOpen && !hasCalledReady.current) {
|
|
2526
|
+
hasCalledReady.current = true;
|
|
2527
|
+
onReady?.();
|
|
2528
|
+
}
|
|
2529
|
+
}, [isOpen, onReady]);
|
|
2465
2530
|
const logoUrl = branding?.logoUrl ?? "https://github.com/rhinestonewtf.png";
|
|
2466
2531
|
const title = branding?.title ?? "Rhinestone";
|
|
2467
2532
|
return /* @__PURE__ */ jsx12(
|
|
@@ -2535,7 +2600,7 @@ function DepositModal({
|
|
|
2535
2600
|
switchChain,
|
|
2536
2601
|
sourceChain,
|
|
2537
2602
|
sourceToken,
|
|
2538
|
-
amount:
|
|
2603
|
+
amount: defaultAmount,
|
|
2539
2604
|
recipient,
|
|
2540
2605
|
signerAddress,
|
|
2541
2606
|
waitForFinalTx,
|
|
@@ -2558,8 +2623,23 @@ export {
|
|
|
2558
2623
|
DEFAULT_BACKEND_URL,
|
|
2559
2624
|
DEFAULT_SIGNER_ADDRESS,
|
|
2560
2625
|
DepositModal,
|
|
2626
|
+
NATIVE_TOKEN_ADDRESS,
|
|
2561
2627
|
SOURCE_CHAINS,
|
|
2562
|
-
|
|
2628
|
+
SUPPORTED_CHAINS,
|
|
2629
|
+
chainRegistry,
|
|
2630
|
+
findChainIdForToken,
|
|
2631
|
+
getChainBadge,
|
|
2632
|
+
getChainIcon,
|
|
2633
|
+
getChainId,
|
|
2563
2634
|
getChainName,
|
|
2564
|
-
|
|
2635
|
+
getChainObject,
|
|
2636
|
+
getExplorerName,
|
|
2637
|
+
getExplorerTxUrl,
|
|
2638
|
+
getExplorerUrl,
|
|
2639
|
+
getTokenAddress,
|
|
2640
|
+
getTokenDecimals,
|
|
2641
|
+
getTokenIcon,
|
|
2642
|
+
getTokenSymbol,
|
|
2643
|
+
getUsdcAddress,
|
|
2644
|
+
getUsdcDecimals
|
|
2565
2645
|
};
|
package/dist/styles.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhinestone/deposit-modal",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "React modal component for Rhinestone cross-chain deposits",
|
|
5
|
-
"author": "Rhinestone <
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"homepage": "https://github.com/rhinestonewtf/deposit/tree/main/deposit-modal#readme",
|
|
5
|
+
"author": "Rhinestone <dev@rhinestone.wtf>",
|
|
8
6
|
"bugs": {
|
|
9
|
-
"url": "https://github.com/rhinestonewtf/deposit/issues"
|
|
7
|
+
"url": "https://github.com/rhinestonewtf/deposit-modal/issues"
|
|
10
8
|
},
|
|
11
9
|
"type": "module",
|
|
12
10
|
"main": "./dist/index.cjs",
|
|
@@ -18,7 +16,10 @@
|
|
|
18
16
|
"import": "./dist/index.mjs",
|
|
19
17
|
"require": "./dist/index.cjs"
|
|
20
18
|
},
|
|
21
|
-
"./styles.css":
|
|
19
|
+
"./styles.css": {
|
|
20
|
+
"types": "./dist/styles.d.ts",
|
|
21
|
+
"default": "./dist/styles.css"
|
|
22
|
+
}
|
|
22
23
|
},
|
|
23
24
|
"files": [
|
|
24
25
|
"dist",
|
|
@@ -28,7 +29,7 @@
|
|
|
28
29
|
"*.css"
|
|
29
30
|
],
|
|
30
31
|
"scripts": {
|
|
31
|
-
"build": "tsup",
|
|
32
|
+
"build": "tsup && bun run scripts/postbuild.ts",
|
|
32
33
|
"clean": "rm -rf dist",
|
|
33
34
|
"typecheck": "tsc --noEmit",
|
|
34
35
|
"prepublishOnly": "bun run clean && bun run build && bun run typecheck"
|
|
@@ -39,11 +40,13 @@
|
|
|
39
40
|
"viem": ">=2.0.0"
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
42
|
-
"@rhinestone/sdk": "^1.2.9"
|
|
43
|
+
"@rhinestone/sdk": "^1.2.9",
|
|
44
|
+
"@rhinestone/shared-configs": "^1.4.91"
|
|
43
45
|
},
|
|
44
46
|
"devDependencies": {
|
|
45
47
|
"@types/react": "^19.0.0",
|
|
46
48
|
"@types/react-dom": "^19.0.0",
|
|
49
|
+
"bun-types": "^1.3.8",
|
|
47
50
|
"react": "^19.0.0",
|
|
48
51
|
"react-dom": "^19.0.0",
|
|
49
52
|
"tsup": "^8.0.0",
|
|
@@ -61,6 +64,6 @@
|
|
|
61
64
|
],
|
|
62
65
|
"repository": {
|
|
63
66
|
"type": "git",
|
|
64
|
-
"url": "https://github.com/rhinestonewtf/deposit"
|
|
67
|
+
"url": "https://github.com/rhinestonewtf/deposit-modal"
|
|
65
68
|
}
|
|
66
69
|
}
|