@openzeppelin/ui-builder-adapter-evm 0.13.0 → 0.14.0
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 +2000 -1819
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +2902 -2721
- package/dist/index.js.map +1 -1
- package/dist/vite-config.cjs +53 -0
- package/dist/vite-config.cjs.map +1 -0
- package/dist/vite-config.d.cts +46 -0
- package/dist/vite-config.d.ts +46 -0
- package/dist/vite-config.js +28 -0
- package/dist/vite-config.js.map +1 -0
- package/package.json +10 -5
- package/src/__tests__/provenanceLinks.test.ts +1 -1
- package/src/__tests__/providerSelection.test.ts +20 -16
- package/src/abi/loader.ts +8 -14
- package/src/abi/sourcify.ts +2 -3
- package/src/adapter.ts +33 -0
- package/src/configuration/explorer.ts +10 -15
- package/src/configuration/index.ts +1 -0
- package/src/configuration/network-services.ts +264 -0
- package/src/configuration/rpc.ts +23 -12
- package/src/query/handler.ts +4 -6
- package/src/vite-config.ts +68 -0
- package/src/wallet/implementation/wagmi-implementation.ts +23 -13
- package/src/wallet/rainbowkit/config-service.ts +3 -79
package/dist/index.cjs
CHANGED
|
@@ -39,25 +39,25 @@ __export(rainbowkitAssetManager_exports, {
|
|
|
39
39
|
});
|
|
40
40
|
async function ensureRainbowKitAssetsLoaded() {
|
|
41
41
|
if (loadedAssets) {
|
|
42
|
-
|
|
42
|
+
import_ui_builder_utils17.logger.debug("RainbowKitAssetManager", "Assets already loaded, returning cached.");
|
|
43
43
|
return loadedAssets;
|
|
44
44
|
}
|
|
45
45
|
if (!providerPromise) {
|
|
46
46
|
providerPromise = import("@rainbow-me/rainbowkit").then((module2) => {
|
|
47
47
|
const component = module2.RainbowKitProvider;
|
|
48
|
-
|
|
48
|
+
import_ui_builder_utils17.logger.info("RainbowKitAssetManager", "RainbowKitProvider module loaded.");
|
|
49
49
|
return component;
|
|
50
50
|
}).catch((err) => {
|
|
51
|
-
|
|
51
|
+
import_ui_builder_utils17.logger.error("RainbowKitAssetManager", "Failed to load RainbowKitProvider module:", err);
|
|
52
52
|
return null;
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
if (!cssPromise) {
|
|
56
56
|
cssPromise = import("@rainbow-me/rainbowkit/styles.css").then(() => {
|
|
57
|
-
|
|
57
|
+
import_ui_builder_utils17.logger.info("RainbowKitAssetManager", "RainbowKit CSS loaded successfully.");
|
|
58
58
|
return true;
|
|
59
59
|
}).catch((err) => {
|
|
60
|
-
|
|
60
|
+
import_ui_builder_utils17.logger.error("RainbowKitAssetManager", "Failed to load RainbowKit CSS:", err);
|
|
61
61
|
return false;
|
|
62
62
|
});
|
|
63
63
|
}
|
|
@@ -65,7 +65,7 @@ async function ensureRainbowKitAssetsLoaded() {
|
|
|
65
65
|
const [ProviderComponent, cssLoadedSuccess] = await Promise.all([providerPromise, cssPromise]);
|
|
66
66
|
loadedAssets = { ProviderComponent, cssLoaded: cssLoadedSuccess };
|
|
67
67
|
if (!ProviderComponent || !cssLoadedSuccess) {
|
|
68
|
-
|
|
68
|
+
import_ui_builder_utils17.logger.warn(
|
|
69
69
|
"RainbowKitAssetManager",
|
|
70
70
|
"One or more RainbowKit assets failed to load.",
|
|
71
71
|
loadedAssets
|
|
@@ -73,16 +73,16 @@ async function ensureRainbowKitAssetsLoaded() {
|
|
|
73
73
|
}
|
|
74
74
|
return loadedAssets;
|
|
75
75
|
} catch (error) {
|
|
76
|
-
|
|
76
|
+
import_ui_builder_utils17.logger.error("RainbowKitAssetManager", "Error in Promise.all for asset loading:", error);
|
|
77
77
|
loadedAssets = { ProviderComponent: null, cssLoaded: false };
|
|
78
78
|
return loadedAssets;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
var
|
|
81
|
+
var import_ui_builder_utils17, loadedAssets, providerPromise, cssPromise;
|
|
82
82
|
var init_rainbowkitAssetManager = __esm({
|
|
83
83
|
"src/wallet/rainbowkit/rainbowkitAssetManager.ts"() {
|
|
84
84
|
"use strict";
|
|
85
|
-
|
|
85
|
+
import_ui_builder_utils17 = require("@openzeppelin/ui-builder-utils");
|
|
86
86
|
loadedAssets = null;
|
|
87
87
|
providerPromise = null;
|
|
88
88
|
cssPromise = null;
|
|
@@ -127,7 +127,7 @@ __export(index_exports, {
|
|
|
127
127
|
module.exports = __toCommonJS(index_exports);
|
|
128
128
|
|
|
129
129
|
// src/adapter.ts
|
|
130
|
-
var
|
|
130
|
+
var import_ui_builder_utils40 = require("@openzeppelin/ui-builder-utils");
|
|
131
131
|
|
|
132
132
|
// src/abi/comparison.ts
|
|
133
133
|
var import_ui_builder_utils = require("@openzeppelin/ui-builder-utils");
|
|
@@ -452,6 +452,9 @@ var AbiComparisonService = class {
|
|
|
452
452
|
};
|
|
453
453
|
var abiComparisonService = new AbiComparisonService();
|
|
454
454
|
|
|
455
|
+
// src/configuration/network-services.ts
|
|
456
|
+
var import_ui_builder_utils6 = require("@openzeppelin/ui-builder-utils");
|
|
457
|
+
|
|
455
458
|
// src/types/providers.ts
|
|
456
459
|
var EvmProviderKeys = {
|
|
457
460
|
Etherscan: "etherscan",
|
|
@@ -465,211 +468,1035 @@ function isEvmProviderKey(value) {
|
|
|
465
468
|
return value === EvmProviderKeys.Etherscan || value === EvmProviderKeys.Sourcify;
|
|
466
469
|
}
|
|
467
470
|
|
|
468
|
-
// src/
|
|
469
|
-
var
|
|
470
|
-
var import_core3 = require("@wagmi/core");
|
|
471
|
-
var import_chains3 = require("viem/chains");
|
|
472
|
-
var import_wagmi = require("wagmi");
|
|
473
|
-
var import_react9 = require("react");
|
|
474
|
-
var import_ui_builder_utils14 = require("@openzeppelin/ui-builder-utils");
|
|
471
|
+
// src/configuration/explorer.ts
|
|
472
|
+
var import_ui_builder_utils4 = require("@openzeppelin/ui-builder-utils");
|
|
475
473
|
|
|
476
|
-
// src/
|
|
477
|
-
var
|
|
478
|
-
var WagmiProviderInitializedContext = (0, import_react.createContext)(false);
|
|
474
|
+
// src/abi/etherscan-v2.ts
|
|
475
|
+
var import_ui_builder_utils3 = require("@openzeppelin/ui-builder-utils");
|
|
479
476
|
|
|
480
|
-
// src/
|
|
481
|
-
var
|
|
477
|
+
// src/abi/transformer.ts
|
|
478
|
+
var import_ui_builder_utils2 = require("@openzeppelin/ui-builder-utils");
|
|
482
479
|
|
|
483
|
-
// src/
|
|
484
|
-
|
|
480
|
+
// src/types/artifacts.ts
|
|
481
|
+
function isEvmContractArtifacts(obj) {
|
|
482
|
+
return typeof obj === "object" && obj !== null && typeof obj.contractAddress === "string";
|
|
483
|
+
}
|
|
485
484
|
|
|
486
|
-
// src/
|
|
487
|
-
|
|
488
|
-
|
|
485
|
+
// src/utils/artifacts.ts
|
|
486
|
+
function validateAndConvertEvmArtifacts(source) {
|
|
487
|
+
if (typeof source === "string") {
|
|
488
|
+
return { contractAddress: source };
|
|
489
|
+
}
|
|
490
|
+
if (!isEvmContractArtifacts(source)) {
|
|
491
|
+
throw new Error(
|
|
492
|
+
"Invalid contract artifacts provided. Expected an object with contractAddress property."
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
return source;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// src/utils/json.ts
|
|
499
|
+
function stringifyWithBigInt(value, space) {
|
|
500
|
+
const replacer = (_key, val) => {
|
|
501
|
+
if (typeof val === "bigint") {
|
|
502
|
+
return val.toString();
|
|
503
|
+
}
|
|
504
|
+
return val;
|
|
505
|
+
};
|
|
506
|
+
return JSON.stringify(value, replacer, space);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// src/utils/formatting.ts
|
|
510
|
+
function formatMethodName(name) {
|
|
511
|
+
if (!name) return "";
|
|
512
|
+
return name.replace(/([A-Z])/g, " $1").replace(/^./, (str) => str.toUpperCase()).trim();
|
|
513
|
+
}
|
|
514
|
+
function formatInputName(name, type) {
|
|
515
|
+
if (!name || name === "") {
|
|
516
|
+
return `Parameter (${type})`;
|
|
517
|
+
}
|
|
518
|
+
return name.replace(/([A-Z])/g, " $1").replace(/_/g, " ").replace(/^./, (str) => str.toUpperCase()).trim();
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// src/utils/validation.ts
|
|
489
522
|
var import_viem = require("viem");
|
|
490
|
-
|
|
523
|
+
function isValidEvmAddress(address) {
|
|
524
|
+
return (0, import_viem.isAddress)(address);
|
|
525
|
+
}
|
|
491
526
|
|
|
492
|
-
// src/
|
|
493
|
-
var
|
|
494
|
-
var
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
exportConstName: "ethereumMainnet",
|
|
498
|
-
name: "Ethereum",
|
|
499
|
-
ecosystem: "evm",
|
|
500
|
-
network: "ethereum",
|
|
501
|
-
type: "mainnet",
|
|
502
|
-
isTestnet: false,
|
|
503
|
-
chainId: 1,
|
|
504
|
-
rpcUrl: import_chains.mainnet.rpcUrls.default.http[0],
|
|
505
|
-
explorerUrl: "https://etherscan.io",
|
|
506
|
-
apiUrl: "https://api.etherscan.io/v2/api",
|
|
507
|
-
primaryExplorerApiIdentifier: "etherscan-v2",
|
|
508
|
-
supportsEtherscanV2: true,
|
|
509
|
-
iconComponent: import_react2.NetworkEthereum,
|
|
510
|
-
nativeCurrency: {
|
|
511
|
-
name: "Ether",
|
|
512
|
-
symbol: "ETH",
|
|
513
|
-
decimals: 18
|
|
514
|
-
},
|
|
515
|
-
viemChain: import_chains.mainnet
|
|
516
|
-
};
|
|
517
|
-
var arbitrumMainnet = {
|
|
518
|
-
id: "arbitrum-mainnet",
|
|
519
|
-
exportConstName: "arbitrumMainnet",
|
|
520
|
-
name: "Arbitrum One",
|
|
521
|
-
ecosystem: "evm",
|
|
522
|
-
network: "arbitrum",
|
|
523
|
-
type: "mainnet",
|
|
524
|
-
isTestnet: false,
|
|
525
|
-
chainId: 42161,
|
|
526
|
-
rpcUrl: import_chains.arbitrum.rpcUrls.default.http[0],
|
|
527
|
-
explorerUrl: "https://arbiscan.io",
|
|
528
|
-
apiUrl: "https://api.etherscan.io/v2/api",
|
|
529
|
-
primaryExplorerApiIdentifier: "etherscan-v2",
|
|
530
|
-
supportsEtherscanV2: true,
|
|
531
|
-
iconComponent: import_react2.NetworkArbitrumOne,
|
|
532
|
-
nativeCurrency: {
|
|
533
|
-
name: "Ether",
|
|
534
|
-
symbol: "ETH",
|
|
535
|
-
decimals: 18
|
|
536
|
-
},
|
|
537
|
-
viemChain: import_chains.arbitrum
|
|
538
|
-
};
|
|
539
|
-
var polygonMainnet = {
|
|
540
|
-
id: "polygon-mainnet",
|
|
541
|
-
exportConstName: "polygonMainnet",
|
|
542
|
-
name: "Polygon",
|
|
543
|
-
ecosystem: "evm",
|
|
544
|
-
network: "polygon",
|
|
545
|
-
type: "mainnet",
|
|
546
|
-
isTestnet: false,
|
|
547
|
-
chainId: 137,
|
|
548
|
-
rpcUrl: import_chains.polygon.rpcUrls.default.http[0],
|
|
549
|
-
explorerUrl: "https://polygonscan.com",
|
|
550
|
-
apiUrl: "https://api.etherscan.io/v2/api",
|
|
551
|
-
primaryExplorerApiIdentifier: "etherscan-v2",
|
|
552
|
-
supportsEtherscanV2: true,
|
|
553
|
-
iconComponent: import_react2.NetworkPolygon,
|
|
554
|
-
nativeCurrency: {
|
|
555
|
-
name: "MATIC",
|
|
556
|
-
symbol: "MATIC",
|
|
557
|
-
decimals: 18
|
|
558
|
-
},
|
|
559
|
-
viemChain: import_chains.polygon
|
|
560
|
-
};
|
|
561
|
-
var polygonZkEvmMainnet = {
|
|
562
|
-
id: "polygon-zkevm-mainnet",
|
|
563
|
-
exportConstName: "polygonZkEvmMainnet",
|
|
564
|
-
name: "Polygon zkEVM",
|
|
565
|
-
ecosystem: "evm",
|
|
566
|
-
network: "polygon-zkevm",
|
|
567
|
-
type: "mainnet",
|
|
568
|
-
isTestnet: false,
|
|
569
|
-
chainId: 1101,
|
|
570
|
-
rpcUrl: import_chains.polygonZkEvm.rpcUrls.default.http[0],
|
|
571
|
-
explorerUrl: "https://zkevm.polygonscan.com",
|
|
572
|
-
apiUrl: "https://api.etherscan.io/v2/api",
|
|
573
|
-
primaryExplorerApiIdentifier: "etherscan-v2",
|
|
574
|
-
supportsEtherscanV2: true,
|
|
575
|
-
iconComponent: import_react2.NetworkPolygon,
|
|
576
|
-
nativeCurrency: {
|
|
577
|
-
name: "Ether",
|
|
578
|
-
symbol: "ETH",
|
|
579
|
-
decimals: 18
|
|
580
|
-
},
|
|
581
|
-
viemChain: import_chains.polygonZkEvm
|
|
582
|
-
};
|
|
583
|
-
var baseMainnet = {
|
|
584
|
-
id: "base-mainnet",
|
|
585
|
-
exportConstName: "baseMainnet",
|
|
586
|
-
name: "Base",
|
|
587
|
-
ecosystem: "evm",
|
|
588
|
-
network: "base",
|
|
589
|
-
type: "mainnet",
|
|
590
|
-
isTestnet: false,
|
|
591
|
-
chainId: 8453,
|
|
592
|
-
rpcUrl: import_chains.base.rpcUrls.default.http[0],
|
|
593
|
-
explorerUrl: "https://basescan.org",
|
|
594
|
-
apiUrl: "https://api.etherscan.io/v2/api",
|
|
595
|
-
primaryExplorerApiIdentifier: "etherscan-v2",
|
|
596
|
-
supportsEtherscanV2: true,
|
|
597
|
-
iconComponent: import_react2.NetworkBase,
|
|
598
|
-
nativeCurrency: {
|
|
599
|
-
name: "Ether",
|
|
600
|
-
symbol: "ETH",
|
|
601
|
-
decimals: 18
|
|
602
|
-
},
|
|
603
|
-
viemChain: import_chains.base
|
|
604
|
-
};
|
|
605
|
-
var bscMainnet = {
|
|
606
|
-
id: "bsc-mainnet",
|
|
607
|
-
exportConstName: "bscMainnet",
|
|
608
|
-
name: "BNB Smart Chain",
|
|
609
|
-
ecosystem: "evm",
|
|
610
|
-
network: "bsc",
|
|
611
|
-
type: "mainnet",
|
|
612
|
-
isTestnet: false,
|
|
613
|
-
chainId: 56,
|
|
614
|
-
rpcUrl: import_chains.bsc.rpcUrls.default.http[0],
|
|
615
|
-
explorerUrl: "https://bscscan.com",
|
|
616
|
-
apiUrl: "https://api.etherscan.io/v2/api",
|
|
617
|
-
primaryExplorerApiIdentifier: "etherscan-v2",
|
|
618
|
-
supportsEtherscanV2: true,
|
|
619
|
-
iconComponent: import_react2.NetworkBinanceSmartChain,
|
|
620
|
-
nativeCurrency: {
|
|
621
|
-
name: "BNB",
|
|
622
|
-
symbol: "BNB",
|
|
623
|
-
decimals: 18
|
|
624
|
-
},
|
|
625
|
-
viemChain: import_chains.bsc
|
|
626
|
-
};
|
|
627
|
-
var optimismMainnet = {
|
|
628
|
-
id: "optimism-mainnet",
|
|
629
|
-
exportConstName: "optimismMainnet",
|
|
630
|
-
name: "OP Mainnet",
|
|
631
|
-
ecosystem: "evm",
|
|
632
|
-
network: "optimism",
|
|
633
|
-
type: "mainnet",
|
|
634
|
-
isTestnet: false,
|
|
635
|
-
chainId: 10,
|
|
636
|
-
rpcUrl: import_chains.optimism.rpcUrls.default.http[0],
|
|
637
|
-
explorerUrl: "https://optimistic.etherscan.io",
|
|
638
|
-
apiUrl: "https://api.etherscan.io/v2/api",
|
|
639
|
-
primaryExplorerApiIdentifier: "etherscan-v2",
|
|
640
|
-
supportsEtherscanV2: true,
|
|
641
|
-
iconComponent: import_react2.NetworkOptimism,
|
|
642
|
-
nativeCurrency: {
|
|
643
|
-
name: "Ether",
|
|
644
|
-
symbol: "ETH",
|
|
645
|
-
decimals: 18
|
|
646
|
-
},
|
|
647
|
-
viemChain: import_chains.optimism
|
|
527
|
+
// src/utils/gas.ts
|
|
528
|
+
var import_viem2 = require("viem");
|
|
529
|
+
var weiToGwei = (wei) => {
|
|
530
|
+
if (!wei) return void 0;
|
|
531
|
+
return parseFloat((0, import_viem2.formatGwei)(BigInt(wei)));
|
|
648
532
|
};
|
|
649
|
-
var
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
name: "Avalanche C-Chain",
|
|
653
|
-
ecosystem: "evm",
|
|
654
|
-
network: "avalanche",
|
|
655
|
-
type: "mainnet",
|
|
656
|
-
isTestnet: false,
|
|
657
|
-
chainId: 43114,
|
|
658
|
-
rpcUrl: import_chains.avalanche.rpcUrls.default.http[0],
|
|
659
|
-
explorerUrl: "https://snowscan.xyz",
|
|
660
|
-
apiUrl: "https://api.etherscan.io/v2/api",
|
|
661
|
-
primaryExplorerApiIdentifier: "etherscan-v2",
|
|
662
|
-
supportsEtherscanV2: true,
|
|
663
|
-
iconComponent: import_react2.NetworkAvalanche,
|
|
664
|
-
nativeCurrency: {
|
|
665
|
-
name: "Avalanche",
|
|
666
|
-
symbol: "AVAX",
|
|
667
|
-
decimals: 18
|
|
668
|
-
},
|
|
669
|
-
viemChain: import_chains.avalanche
|
|
533
|
+
var gweiToWei = (gwei) => {
|
|
534
|
+
if (!gwei) return void 0;
|
|
535
|
+
return Number((0, import_viem2.parseGwei)(gwei.toString()));
|
|
670
536
|
};
|
|
671
|
-
|
|
672
|
-
|
|
537
|
+
|
|
538
|
+
// src/abi/transformer.ts
|
|
539
|
+
function transformAbiToSchema(abi, contractName, address) {
|
|
540
|
+
import_ui_builder_utils2.logger.info("transformAbiToSchema", `Transforming ABI to ContractSchema for: ${contractName}`);
|
|
541
|
+
const functions = [];
|
|
542
|
+
for (const item of abi) {
|
|
543
|
+
if (item.type === "function") {
|
|
544
|
+
const abiFunctionItem = item;
|
|
545
|
+
functions.push({
|
|
546
|
+
// Generate a unique ID for the function within the schema.
|
|
547
|
+
// This often combines name and input types to handle overloads.
|
|
548
|
+
id: `${abiFunctionItem.name}_${abiFunctionItem.inputs?.map((i) => i.type).join("_") || ""}`,
|
|
549
|
+
name: abiFunctionItem.name || "",
|
|
550
|
+
// Fallback for unnamed functions (though rare).
|
|
551
|
+
displayName: formatMethodName(abiFunctionItem.name || ""),
|
|
552
|
+
// Create a more readable name for UI.
|
|
553
|
+
// Recursively map ABI inputs and outputs to our FunctionParameter structure.
|
|
554
|
+
// This ensures that any non-standard properties (like 'internalType') are stripped.
|
|
555
|
+
inputs: mapAbiParametersToSchemaParameters(abiFunctionItem.inputs),
|
|
556
|
+
outputs: mapAbiParametersToSchemaParameters(abiFunctionItem.outputs),
|
|
557
|
+
type: "function",
|
|
558
|
+
// Explicitly set, as we filtered for this type.
|
|
559
|
+
stateMutability: abiFunctionItem.stateMutability,
|
|
560
|
+
// Preserve EVM-specific state mutability.
|
|
561
|
+
// Determine if the function modifies blockchain state based on its `stateMutability`.
|
|
562
|
+
// This is a crucial piece of information for the UI (e.g., to differentiate read vs. write calls).
|
|
563
|
+
modifiesState: !abiFunctionItem.stateMutability || // If undefined, assume it modifies state (safer default)
|
|
564
|
+
!["view", "pure"].includes(abiFunctionItem.stateMutability)
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
const contractSchema = {
|
|
569
|
+
ecosystem: "evm",
|
|
570
|
+
// This transformer is specific to EVM.
|
|
571
|
+
name: contractName,
|
|
572
|
+
address,
|
|
573
|
+
functions
|
|
574
|
+
};
|
|
575
|
+
import_ui_builder_utils2.logger.info(
|
|
576
|
+
"transformAbiToSchema",
|
|
577
|
+
`Transformation complete. Found ${contractSchema.functions.length} functions.`
|
|
578
|
+
);
|
|
579
|
+
return contractSchema;
|
|
580
|
+
}
|
|
581
|
+
function mapAbiParametersToSchemaParameters(abiParams) {
|
|
582
|
+
if (!abiParams) {
|
|
583
|
+
return [];
|
|
584
|
+
}
|
|
585
|
+
return abiParams.map((param) => {
|
|
586
|
+
const schemaParam = {
|
|
587
|
+
name: param.name || "",
|
|
588
|
+
// Ensure name is a string, fallback if undefined in ABI.
|
|
589
|
+
type: param.type,
|
|
590
|
+
// The raw type string from the ABI (e.g., 'uint256', 'address', 'tuple').
|
|
591
|
+
displayName: formatInputName(param.name || "", param.type)
|
|
592
|
+
// Generate a user-friendly name.
|
|
593
|
+
// `description` is not a standard part of an ABI parameter, so it's not mapped here.
|
|
594
|
+
// It can be added later by the user in the builder app UI.
|
|
595
|
+
};
|
|
596
|
+
if (param.type.startsWith("tuple") && "components" in param && // Type guard for discriminated union (AbiParameter)
|
|
597
|
+
param.components && param.components.length > 0) {
|
|
598
|
+
schemaParam.components = mapAbiParametersToSchemaParameters(
|
|
599
|
+
param.components
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
return schemaParam;
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
function mapSchemaParameterToAbiParameter(param) {
|
|
606
|
+
if (param.type.startsWith("tuple") && param.components && param.components.length > 0) {
|
|
607
|
+
return {
|
|
608
|
+
name: param.name || void 0,
|
|
609
|
+
// ABI parameter names can be undefined (e.g., for return values).
|
|
610
|
+
type: param.type,
|
|
611
|
+
// Cast to satisfy viem's specific tuple type string.
|
|
612
|
+
// Recursively map nested components back to AbiParameter format.
|
|
613
|
+
components: param.components.map(mapSchemaParameterToAbiParameter)
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
return {
|
|
617
|
+
name: param.name || void 0,
|
|
618
|
+
type: param.type
|
|
619
|
+
// `internalType` is not part of our `FunctionParameter` model, so it's not added back here.
|
|
620
|
+
// Other ABI-specific fields like `indexed` (for events) are also not relevant here as
|
|
621
|
+
// this function is focused on function parameters for `AbiFunction`.
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
function createAbiFunctionItem(functionDetails) {
|
|
625
|
+
return {
|
|
626
|
+
name: functionDetails.name,
|
|
627
|
+
type: "function",
|
|
628
|
+
inputs: functionDetails.inputs.map(mapSchemaParameterToAbiParameter),
|
|
629
|
+
outputs: functionDetails.outputs?.map(mapSchemaParameterToAbiParameter) || [],
|
|
630
|
+
stateMutability: functionDetails.stateMutability ?? "view"
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// src/abi/etherscan-v2.ts
|
|
635
|
+
var ETHERSCAN_V2_BASE_URL = "https://api.etherscan.io/v2/api";
|
|
636
|
+
function buildV2ApiUrl(chainId, module2, action, params, apiKey) {
|
|
637
|
+
const url = new URL(ETHERSCAN_V2_BASE_URL);
|
|
638
|
+
url.searchParams.append("chainid", chainId.toString());
|
|
639
|
+
url.searchParams.append("module", module2);
|
|
640
|
+
url.searchParams.append("action", action);
|
|
641
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
642
|
+
url.searchParams.append(key, value);
|
|
643
|
+
});
|
|
644
|
+
if (apiKey) {
|
|
645
|
+
url.searchParams.append("apikey", apiKey);
|
|
646
|
+
}
|
|
647
|
+
return url.toString();
|
|
648
|
+
}
|
|
649
|
+
function shouldUseV2Api(networkConfig) {
|
|
650
|
+
if (!networkConfig.supportsEtherscanV2) {
|
|
651
|
+
return false;
|
|
652
|
+
}
|
|
653
|
+
return true;
|
|
654
|
+
}
|
|
655
|
+
async function loadAbiFromEtherscanV2(address, networkConfig) {
|
|
656
|
+
const explorerConfig = resolveExplorerConfig(networkConfig);
|
|
657
|
+
const url = buildV2ApiUrl(
|
|
658
|
+
networkConfig.chainId,
|
|
659
|
+
"contract",
|
|
660
|
+
"getabi",
|
|
661
|
+
{ address },
|
|
662
|
+
explorerConfig.apiKey
|
|
663
|
+
);
|
|
664
|
+
let response;
|
|
665
|
+
try {
|
|
666
|
+
import_ui_builder_utils3.logger.info(
|
|
667
|
+
"loadAbiFromEtherscanV2",
|
|
668
|
+
`Fetching ABI from Etherscan V2 API for address: ${address} on chain ${networkConfig.chainId}`
|
|
669
|
+
);
|
|
670
|
+
response = await fetch(url);
|
|
671
|
+
} catch (networkError) {
|
|
672
|
+
import_ui_builder_utils3.logger.error(
|
|
673
|
+
"loadAbiFromEtherscanV2",
|
|
674
|
+
`Network error fetching ABI from Explorer V2 API: ${networkError}`
|
|
675
|
+
);
|
|
676
|
+
throw new Error(`Network error fetching ABI: ${networkError.message}`);
|
|
677
|
+
}
|
|
678
|
+
if (!response.ok) {
|
|
679
|
+
import_ui_builder_utils3.logger.error(
|
|
680
|
+
"loadAbiFromEtherscanV2",
|
|
681
|
+
`Explorer V2 API request failed with status: ${response.status}`
|
|
682
|
+
);
|
|
683
|
+
throw new Error(`Explorer V2 API request failed: ${response.status} ${response.statusText}`);
|
|
684
|
+
}
|
|
685
|
+
let apiResult;
|
|
686
|
+
try {
|
|
687
|
+
apiResult = await response.json();
|
|
688
|
+
} catch (jsonError) {
|
|
689
|
+
import_ui_builder_utils3.logger.error(
|
|
690
|
+
"loadAbiFromEtherscanV2",
|
|
691
|
+
`Failed to parse Explorer V2 API response as JSON: ${jsonError}`
|
|
692
|
+
);
|
|
693
|
+
throw new Error("Invalid JSON response received from Explorer V2 API.");
|
|
694
|
+
}
|
|
695
|
+
if (apiResult.status !== "1") {
|
|
696
|
+
import_ui_builder_utils3.logger.warn(
|
|
697
|
+
"loadAbiFromEtherscanV2",
|
|
698
|
+
`Explorer V2 API error: Status ${apiResult.status}, Message: ${apiResult.message}, Result: ${apiResult.result}`
|
|
699
|
+
);
|
|
700
|
+
if (apiResult.message?.includes("NOTOK")) {
|
|
701
|
+
if (apiResult.result?.includes("Invalid API Key")) {
|
|
702
|
+
throw new Error(
|
|
703
|
+
`Invalid API key for Etherscan V2. Please check your API key configuration.`
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
if (apiResult.result?.includes("Contract source code not verified")) {
|
|
707
|
+
throw new Error(
|
|
708
|
+
`Contract not verified on ${networkConfig.name} explorer (address: ${address}). ABI not available. You can provide the contract's ABI manually.`
|
|
709
|
+
);
|
|
710
|
+
}
|
|
711
|
+
if (apiResult.result?.includes("Invalid chain")) {
|
|
712
|
+
throw new Error(
|
|
713
|
+
`Chain ID ${networkConfig.chainId} is not supported by Etherscan V2 API. Please check if this chain is available.`
|
|
714
|
+
);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
throw new Error(`Explorer V2 API Error: ${apiResult.result || apiResult.message}`);
|
|
718
|
+
}
|
|
719
|
+
const originalAbiString = apiResult.result;
|
|
720
|
+
let abi;
|
|
721
|
+
try {
|
|
722
|
+
abi = JSON.parse(originalAbiString);
|
|
723
|
+
if (!Array.isArray(abi)) {
|
|
724
|
+
throw new Error("Parsed ABI from Explorer V2 API is not an array.");
|
|
725
|
+
}
|
|
726
|
+
} catch (error) {
|
|
727
|
+
import_ui_builder_utils3.logger.error(
|
|
728
|
+
"loadAbiFromEtherscanV2",
|
|
729
|
+
`Failed to parse ABI JSON string from Explorer V2 API result: ${error}`
|
|
730
|
+
);
|
|
731
|
+
throw new Error(`Invalid ABI JSON received from Explorer V2 API: ${error.message}`);
|
|
732
|
+
}
|
|
733
|
+
import_ui_builder_utils3.logger.info(
|
|
734
|
+
"loadAbiFromEtherscanV2",
|
|
735
|
+
`Successfully parsed ABI for ${networkConfig.name} with ${abi.length} items using V2 API.`
|
|
736
|
+
);
|
|
737
|
+
const contractName = `Contract_${address.substring(0, 6)}`;
|
|
738
|
+
const schema = transformAbiToSchema(abi, contractName, address);
|
|
739
|
+
return {
|
|
740
|
+
schema,
|
|
741
|
+
originalAbi: originalAbiString
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
async function testEtherscanV2Connection(networkConfig, apiKey) {
|
|
745
|
+
const startTime = Date.now();
|
|
746
|
+
const requiresApiKey = networkConfig.requiresExplorerApiKey ?? true;
|
|
747
|
+
if (requiresApiKey && !apiKey) {
|
|
748
|
+
return {
|
|
749
|
+
success: false,
|
|
750
|
+
error: "API key is required for testing connection to this explorer"
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
try {
|
|
754
|
+
const url = buildV2ApiUrl(networkConfig.chainId, "proxy", "eth_blockNumber", {}, apiKey);
|
|
755
|
+
const response = await fetch(url);
|
|
756
|
+
const latency = Date.now() - startTime;
|
|
757
|
+
if (!response.ok) {
|
|
758
|
+
return {
|
|
759
|
+
success: false,
|
|
760
|
+
error: `HTTP ${response.status}: ${response.statusText}`,
|
|
761
|
+
latency
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
const data = await response.json();
|
|
765
|
+
if (data.status === "0" && data.message) {
|
|
766
|
+
if (data.result?.includes("Invalid API Key")) {
|
|
767
|
+
return {
|
|
768
|
+
success: false,
|
|
769
|
+
error: "Invalid API key. Please check your Etherscan API key.",
|
|
770
|
+
latency
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
if (data.result?.includes("Invalid chain")) {
|
|
774
|
+
return {
|
|
775
|
+
success: false,
|
|
776
|
+
error: `Chain ID ${networkConfig.chainId} is not supported by Etherscan V2 API.`,
|
|
777
|
+
latency
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
return {
|
|
781
|
+
success: false,
|
|
782
|
+
error: data.result || data.message,
|
|
783
|
+
latency
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
return {
|
|
787
|
+
success: true,
|
|
788
|
+
latency
|
|
789
|
+
};
|
|
790
|
+
} catch (error) {
|
|
791
|
+
return {
|
|
792
|
+
success: false,
|
|
793
|
+
error: error instanceof Error ? error.message : "Connection test failed",
|
|
794
|
+
latency: Date.now() - startTime
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// src/configuration/explorer.ts
|
|
800
|
+
function resolveExplorerConfig(networkConfig) {
|
|
801
|
+
const isV2 = networkConfig.supportsEtherscanV2 && networkConfig.primaryExplorerApiIdentifier === "etherscan-v2";
|
|
802
|
+
const globalV2ApiKey = isV2 ? import_ui_builder_utils4.appConfigService.getGlobalServiceConfig("etherscanv2")?.apiKey : void 0;
|
|
803
|
+
const appApiKey = networkConfig.primaryExplorerApiIdentifier ? import_ui_builder_utils4.appConfigService.getExplorerApiKey(networkConfig.primaryExplorerApiIdentifier) : void 0;
|
|
804
|
+
const rawCfg = import_ui_builder_utils4.userNetworkServiceConfigService.get(networkConfig.id, "explorer");
|
|
805
|
+
if (rawCfg && typeof rawCfg === "object") {
|
|
806
|
+
const userCfg = rawCfg;
|
|
807
|
+
import_ui_builder_utils4.logger.info("ExplorerConfig", `Using user-configured explorer for ${networkConfig.name}`);
|
|
808
|
+
return {
|
|
809
|
+
explorerUrl: userCfg.explorerUrl ?? networkConfig.explorerUrl,
|
|
810
|
+
apiUrl: userCfg.apiUrl ?? networkConfig.apiUrl,
|
|
811
|
+
apiKey: userCfg.apiKey ?? globalV2ApiKey ?? appApiKey,
|
|
812
|
+
name: `${networkConfig.name} Explorer`,
|
|
813
|
+
isCustom: true
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
if (isV2 && globalV2ApiKey) {
|
|
817
|
+
import_ui_builder_utils4.logger.info("ExplorerConfig", `Using global Etherscan V2 API key for ${networkConfig.name}`);
|
|
818
|
+
return {
|
|
819
|
+
explorerUrl: networkConfig.explorerUrl,
|
|
820
|
+
apiUrl: networkConfig.apiUrl,
|
|
821
|
+
apiKey: globalV2ApiKey,
|
|
822
|
+
name: `${networkConfig.name} Explorer (V2 API)`,
|
|
823
|
+
isCustom: false
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
if (appApiKey) {
|
|
827
|
+
import_ui_builder_utils4.logger.info("ExplorerConfig", `Using app-configured API key for ${networkConfig.name}`);
|
|
828
|
+
return {
|
|
829
|
+
explorerUrl: networkConfig.explorerUrl,
|
|
830
|
+
apiUrl: networkConfig.apiUrl,
|
|
831
|
+
apiKey: appApiKey,
|
|
832
|
+
name: `${networkConfig.name} Explorer`,
|
|
833
|
+
isCustom: false
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
import_ui_builder_utils4.logger.info(
|
|
837
|
+
"ExplorerConfig",
|
|
838
|
+
`Using default explorer for ${networkConfig.name} (no API key configured)`
|
|
839
|
+
);
|
|
840
|
+
return {
|
|
841
|
+
explorerUrl: networkConfig.explorerUrl,
|
|
842
|
+
apiUrl: networkConfig.apiUrl,
|
|
843
|
+
name: `${networkConfig.name} Explorer`,
|
|
844
|
+
isCustom: false
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
function getEvmExplorerAddressUrl(address, networkConfig) {
|
|
848
|
+
if (!isValidEvmAddress(address)) {
|
|
849
|
+
return null;
|
|
850
|
+
}
|
|
851
|
+
const explorerConfig = resolveExplorerConfig(networkConfig);
|
|
852
|
+
if (!explorerConfig.explorerUrl) {
|
|
853
|
+
return null;
|
|
854
|
+
}
|
|
855
|
+
const baseUrl = explorerConfig.explorerUrl.replace(/\/+$/, "");
|
|
856
|
+
return `${baseUrl}/address/${address}`;
|
|
857
|
+
}
|
|
858
|
+
function getEvmExplorerTxUrl(txHash, networkConfig) {
|
|
859
|
+
if (!txHash) {
|
|
860
|
+
return null;
|
|
861
|
+
}
|
|
862
|
+
const explorerConfig = resolveExplorerConfig(networkConfig);
|
|
863
|
+
if (!explorerConfig.explorerUrl) {
|
|
864
|
+
return null;
|
|
865
|
+
}
|
|
866
|
+
const baseUrl = explorerConfig.explorerUrl.replace(/\/+$/, "");
|
|
867
|
+
return `${baseUrl}/tx/${txHash}`;
|
|
868
|
+
}
|
|
869
|
+
function validateEvmExplorerConfig(explorerConfig) {
|
|
870
|
+
if (explorerConfig.explorerUrl) {
|
|
871
|
+
try {
|
|
872
|
+
new URL(explorerConfig.explorerUrl);
|
|
873
|
+
} catch {
|
|
874
|
+
return false;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
if (explorerConfig.apiUrl) {
|
|
878
|
+
try {
|
|
879
|
+
new URL(explorerConfig.apiUrl);
|
|
880
|
+
} catch {
|
|
881
|
+
return false;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
if (explorerConfig.apiKey !== void 0 && explorerConfig.apiKey.trim().length === 0) {
|
|
885
|
+
return false;
|
|
886
|
+
}
|
|
887
|
+
return true;
|
|
888
|
+
}
|
|
889
|
+
async function testEvmExplorerConnection(explorerConfig, networkConfig) {
|
|
890
|
+
const requiresApiKey = networkConfig && "requiresExplorerApiKey" in networkConfig ? networkConfig.requiresExplorerApiKey !== false : true;
|
|
891
|
+
if (requiresApiKey && !explorerConfig.apiKey) {
|
|
892
|
+
return {
|
|
893
|
+
success: false,
|
|
894
|
+
error: "API key is required for testing connection to this explorer"
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
if (networkConfig && shouldUseV2Api(networkConfig)) {
|
|
898
|
+
return testEtherscanV2Connection(networkConfig, explorerConfig.apiKey);
|
|
899
|
+
}
|
|
900
|
+
let apiUrl = explorerConfig.apiUrl;
|
|
901
|
+
if (!apiUrl && networkConfig?.apiUrl) {
|
|
902
|
+
apiUrl = networkConfig.apiUrl;
|
|
903
|
+
}
|
|
904
|
+
if (!apiUrl) {
|
|
905
|
+
return {
|
|
906
|
+
success: false,
|
|
907
|
+
error: "API URL is required for testing connection. Please provide an API URL or ensure the network has a default API URL configured."
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
const startTime = Date.now();
|
|
911
|
+
try {
|
|
912
|
+
const url = new URL(apiUrl);
|
|
913
|
+
url.searchParams.append("module", "proxy");
|
|
914
|
+
url.searchParams.append("action", "eth_blockNumber");
|
|
915
|
+
if (explorerConfig.apiKey) {
|
|
916
|
+
url.searchParams.append("apikey", explorerConfig.apiKey);
|
|
917
|
+
}
|
|
918
|
+
const response = await fetch(url.toString());
|
|
919
|
+
const latency = Date.now() - startTime;
|
|
920
|
+
if (!response.ok) {
|
|
921
|
+
return {
|
|
922
|
+
success: false,
|
|
923
|
+
error: `HTTP ${response.status}: ${response.statusText}`,
|
|
924
|
+
latency
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
const data = await response.json();
|
|
928
|
+
if (data.status === "0" && data.message) {
|
|
929
|
+
return {
|
|
930
|
+
success: false,
|
|
931
|
+
error: data.message,
|
|
932
|
+
latency
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
return {
|
|
936
|
+
success: true,
|
|
937
|
+
latency
|
|
938
|
+
};
|
|
939
|
+
} catch (error) {
|
|
940
|
+
return {
|
|
941
|
+
success: false,
|
|
942
|
+
error: error instanceof Error ? error.message : "Connection test failed",
|
|
943
|
+
latency: Date.now() - startTime
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// src/configuration/rpc.ts
|
|
949
|
+
var import_ui_builder_utils5 = require("@openzeppelin/ui-builder-utils");
|
|
950
|
+
function buildRpcUrl(config) {
|
|
951
|
+
return config.url;
|
|
952
|
+
}
|
|
953
|
+
function getUserRpcUrl(networkId) {
|
|
954
|
+
const svcCfg = import_ui_builder_utils5.userNetworkServiceConfigService.get(networkId, "rpc");
|
|
955
|
+
if (svcCfg && typeof svcCfg === "object" && "rpcUrl" in svcCfg) {
|
|
956
|
+
return svcCfg.rpcUrl;
|
|
957
|
+
}
|
|
958
|
+
return void 0;
|
|
959
|
+
}
|
|
960
|
+
function resolveRpcUrl(networkConfig) {
|
|
961
|
+
const logSystem = "RpcResolver";
|
|
962
|
+
const networkId = networkConfig.id;
|
|
963
|
+
const userRpcUrl = getUserRpcUrl(networkId);
|
|
964
|
+
if (userRpcUrl) {
|
|
965
|
+
const userRpcUrlString = String(userRpcUrl);
|
|
966
|
+
if ((0, import_ui_builder_utils5.isValidUrl)(userRpcUrlString)) {
|
|
967
|
+
import_ui_builder_utils5.logger.info(logSystem, `Using user-configured RPC URL for network ${networkId}`);
|
|
968
|
+
return userRpcUrlString;
|
|
969
|
+
} else {
|
|
970
|
+
import_ui_builder_utils5.logger.warn(
|
|
971
|
+
logSystem,
|
|
972
|
+
`User-configured RPC URL for ${networkId} is invalid: ${userRpcUrlString}. Falling back.`
|
|
973
|
+
);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
const rpcOverrideSetting = import_ui_builder_utils5.appConfigService.getRpcEndpointOverride(networkId);
|
|
977
|
+
let rpcUrlFromOverride;
|
|
978
|
+
if (typeof rpcOverrideSetting === "string") {
|
|
979
|
+
rpcUrlFromOverride = rpcOverrideSetting;
|
|
980
|
+
} else if (typeof rpcOverrideSetting === "object" && rpcOverrideSetting) {
|
|
981
|
+
if ("url" in rpcOverrideSetting && "isCustom" in rpcOverrideSetting) {
|
|
982
|
+
const userConfig = rpcOverrideSetting;
|
|
983
|
+
rpcUrlFromOverride = buildRpcUrl(userConfig);
|
|
984
|
+
} else if ("http" in rpcOverrideSetting) {
|
|
985
|
+
rpcUrlFromOverride = rpcOverrideSetting.http;
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
if (rpcUrlFromOverride) {
|
|
989
|
+
import_ui_builder_utils5.logger.info(
|
|
990
|
+
logSystem,
|
|
991
|
+
`Using overridden RPC URL for network ${networkId}: ${rpcUrlFromOverride}`
|
|
992
|
+
);
|
|
993
|
+
if ((0, import_ui_builder_utils5.isValidUrl)(rpcUrlFromOverride)) {
|
|
994
|
+
return rpcUrlFromOverride;
|
|
995
|
+
} else {
|
|
996
|
+
import_ui_builder_utils5.logger.warn(
|
|
997
|
+
logSystem,
|
|
998
|
+
`Overridden RPC URL for ${networkId} is invalid: ${rpcUrlFromOverride}. Falling back.`
|
|
999
|
+
);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
if (networkConfig.rpcUrl && (0, import_ui_builder_utils5.isValidUrl)(networkConfig.rpcUrl)) {
|
|
1003
|
+
import_ui_builder_utils5.logger.debug(
|
|
1004
|
+
logSystem,
|
|
1005
|
+
`Using default RPC URL for network ${networkId}: ${networkConfig.rpcUrl}`
|
|
1006
|
+
);
|
|
1007
|
+
return networkConfig.rpcUrl;
|
|
1008
|
+
}
|
|
1009
|
+
import_ui_builder_utils5.logger.error(
|
|
1010
|
+
logSystem,
|
|
1011
|
+
`No valid RPC URL could be resolved for network ${networkId}. Checked user config, override, and networkConfig.rpcUrl.`
|
|
1012
|
+
);
|
|
1013
|
+
throw new Error(
|
|
1014
|
+
`No valid RPC URL configured for network ${networkConfig.name} (ID: ${networkId}).`
|
|
1015
|
+
);
|
|
1016
|
+
}
|
|
1017
|
+
function validateEvmRpcEndpoint(rpcConfig) {
|
|
1018
|
+
try {
|
|
1019
|
+
if (!(0, import_ui_builder_utils5.isValidUrl)(rpcConfig.url)) {
|
|
1020
|
+
import_ui_builder_utils5.logger.error("validateEvmRpcEndpoint", `Invalid RPC URL format: ${rpcConfig.url}`);
|
|
1021
|
+
return false;
|
|
1022
|
+
}
|
|
1023
|
+
return true;
|
|
1024
|
+
} catch (error) {
|
|
1025
|
+
import_ui_builder_utils5.logger.error("validateEvmRpcEndpoint", "Error validating RPC endpoint:", error);
|
|
1026
|
+
return false;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
async function testEvmRpcConnection(rpcConfig, timeoutMs = 5e3) {
|
|
1030
|
+
if (!rpcConfig.url) {
|
|
1031
|
+
return { success: false, error: "RPC URL is required" };
|
|
1032
|
+
}
|
|
1033
|
+
const controller = new AbortController();
|
|
1034
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
1035
|
+
try {
|
|
1036
|
+
const startTime = Date.now();
|
|
1037
|
+
const response = await fetch(rpcConfig.url, {
|
|
1038
|
+
method: "POST",
|
|
1039
|
+
headers: {
|
|
1040
|
+
"Content-Type": "application/json"
|
|
1041
|
+
},
|
|
1042
|
+
body: JSON.stringify({
|
|
1043
|
+
jsonrpc: "2.0",
|
|
1044
|
+
method: "eth_blockNumber",
|
|
1045
|
+
params: [],
|
|
1046
|
+
id: 1
|
|
1047
|
+
}),
|
|
1048
|
+
signal: controller.signal
|
|
1049
|
+
});
|
|
1050
|
+
if (!response.ok) {
|
|
1051
|
+
return { success: false, error: `HTTP error: ${response.status}` };
|
|
1052
|
+
}
|
|
1053
|
+
const data = await response.json();
|
|
1054
|
+
const latency = Date.now() - startTime;
|
|
1055
|
+
if (data.error) {
|
|
1056
|
+
return { success: false, error: data.error.message || "RPC error" };
|
|
1057
|
+
}
|
|
1058
|
+
return { success: true, latency };
|
|
1059
|
+
} catch (error) {
|
|
1060
|
+
import_ui_builder_utils5.logger.error("testEvmRpcConnection", "Connection test failed:", error);
|
|
1061
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
1062
|
+
return {
|
|
1063
|
+
success: false,
|
|
1064
|
+
error: `Connection timeout after ${timeoutMs}ms`
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
return {
|
|
1068
|
+
success: false,
|
|
1069
|
+
error: error instanceof Error ? error.message : "Connection failed"
|
|
1070
|
+
};
|
|
1071
|
+
} finally {
|
|
1072
|
+
clearTimeout(timeoutId);
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
// src/configuration/network-services.ts
|
|
1077
|
+
function getEvmNetworkServiceForms(networkConfig) {
|
|
1078
|
+
const globalV2ApiKey = import_ui_builder_utils6.appConfigService.getGlobalServiceConfig("etherscanv2")?.apiKey;
|
|
1079
|
+
const v2DefaultEnabled = Boolean(globalV2ApiKey);
|
|
1080
|
+
const savedContractDefCfg = import_ui_builder_utils6.userNetworkServiceConfigService.get(
|
|
1081
|
+
networkConfig.id,
|
|
1082
|
+
"contract-definitions"
|
|
1083
|
+
);
|
|
1084
|
+
const savedDefaultProvider = savedContractDefCfg && typeof savedContractDefCfg.defaultProvider === "string" ? savedContractDefCfg.defaultProvider : void 0;
|
|
1085
|
+
return [
|
|
1086
|
+
{
|
|
1087
|
+
id: "rpc",
|
|
1088
|
+
label: "RPC Provider",
|
|
1089
|
+
description: "Setting your own RPC endpoint ensures better reliability, faster response times, and higher rate limits. Public endpoints may be rate-limited or experience congestion during high traffic periods.",
|
|
1090
|
+
fields: [
|
|
1091
|
+
{
|
|
1092
|
+
id: "evm-rpc-url",
|
|
1093
|
+
name: "rpcUrl",
|
|
1094
|
+
type: "text",
|
|
1095
|
+
label: "RPC URL",
|
|
1096
|
+
placeholder: "https://mainnet.infura.io/v3/your-key",
|
|
1097
|
+
validation: { required: true, pattern: "^https?://.+" },
|
|
1098
|
+
width: "full"
|
|
1099
|
+
}
|
|
1100
|
+
]
|
|
1101
|
+
},
|
|
1102
|
+
{
|
|
1103
|
+
id: "explorer",
|
|
1104
|
+
label: "Block Explorer",
|
|
1105
|
+
description: "Public API keys are rate-limited and may be exhausted quickly. Using your own key ensures reliable access to explorer services.",
|
|
1106
|
+
fields: [
|
|
1107
|
+
// Adapter-led informational notes (rendered generically by the panel)
|
|
1108
|
+
{
|
|
1109
|
+
id: "evm-explorer-note-etherscan",
|
|
1110
|
+
name: "_note_etherscan",
|
|
1111
|
+
type: "hidden",
|
|
1112
|
+
label: "",
|
|
1113
|
+
validation: {},
|
|
1114
|
+
isHidden: true,
|
|
1115
|
+
metadata: {
|
|
1116
|
+
note: {
|
|
1117
|
+
variant: "warning",
|
|
1118
|
+
title: "Etherscan API Support",
|
|
1119
|
+
html: true,
|
|
1120
|
+
lines: [
|
|
1121
|
+
"<strong>V2 API (Recommended):</strong> Supports all Etherscan-compatible explorers across multiple chains with a single API key.",
|
|
1122
|
+
"<strong>V1 API (Legacy):</strong> Requires chain-specific API endpoints. Some explorers may not be supported.",
|
|
1123
|
+
"<strong>Note:</strong> Non-Etherscan explorers (Blockscout, Routescan, etc.) are not supported."
|
|
1124
|
+
]
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
},
|
|
1128
|
+
{
|
|
1129
|
+
id: "evm-explorer-api-key",
|
|
1130
|
+
name: "apiKey",
|
|
1131
|
+
type: "password",
|
|
1132
|
+
label: "API Key",
|
|
1133
|
+
placeholder: "Your explorer API key",
|
|
1134
|
+
helperText: "Required for fetching contract ABIs and other API operations",
|
|
1135
|
+
validation: {},
|
|
1136
|
+
width: "full"
|
|
1137
|
+
},
|
|
1138
|
+
{
|
|
1139
|
+
id: "evm-explorer-use-v2",
|
|
1140
|
+
name: "useV2Api",
|
|
1141
|
+
type: "checkbox",
|
|
1142
|
+
label: "Use Etherscan V2 API",
|
|
1143
|
+
helperText: "Enable the new V2 API for all Etherscan-compatible networks. V2 provides unified access across all chains.",
|
|
1144
|
+
validation: {},
|
|
1145
|
+
defaultValue: v2DefaultEnabled,
|
|
1146
|
+
metadata: {
|
|
1147
|
+
section: "api-config",
|
|
1148
|
+
sectionLabel: "API Configuration",
|
|
1149
|
+
sectionHelp: "Configure API version and network application settings."
|
|
1150
|
+
}
|
|
1151
|
+
},
|
|
1152
|
+
{
|
|
1153
|
+
id: "evm-explorer-apply-all",
|
|
1154
|
+
name: "applyToAllNetworks",
|
|
1155
|
+
type: "checkbox",
|
|
1156
|
+
label: "Apply to all compatible networks",
|
|
1157
|
+
helperText: "Apply these settings to all Etherscan-compatible networks in your project.",
|
|
1158
|
+
validation: {},
|
|
1159
|
+
defaultValue: v2DefaultEnabled,
|
|
1160
|
+
// UI hinting for generic renderer to indent under and disable when V2 is off
|
|
1161
|
+
metadata: {
|
|
1162
|
+
section: "api-config",
|
|
1163
|
+
nestUnder: "useV2Api",
|
|
1164
|
+
disabledWhen: { field: "useV2Api", equals: false }
|
|
1165
|
+
}
|
|
1166
|
+
},
|
|
1167
|
+
{
|
|
1168
|
+
id: "evm-explorer-url",
|
|
1169
|
+
name: "explorerUrl",
|
|
1170
|
+
type: "text",
|
|
1171
|
+
label: "Explorer Base URL (optional)",
|
|
1172
|
+
placeholder: "https://etherscan.io",
|
|
1173
|
+
validation: {},
|
|
1174
|
+
helperText: "Base URL for viewing transactions and addresses. If not provided, defaults from the network will be used.",
|
|
1175
|
+
width: "full",
|
|
1176
|
+
metadata: {
|
|
1177
|
+
section: "custom-endpoints",
|
|
1178
|
+
sectionLabel: "Custom Endpoints",
|
|
1179
|
+
sectionHelp: "Override default URLs for explorer and API endpoints."
|
|
1180
|
+
}
|
|
1181
|
+
},
|
|
1182
|
+
{
|
|
1183
|
+
id: "evm-explorer-api-url",
|
|
1184
|
+
name: "apiUrl",
|
|
1185
|
+
type: "text",
|
|
1186
|
+
label: "Explorer API URL (legacy / V1)",
|
|
1187
|
+
placeholder: "https://api.etherscan.io/api",
|
|
1188
|
+
validation: {},
|
|
1189
|
+
helperText: "API endpoint for fetching contract data. If not provided, defaults from the network will be used.",
|
|
1190
|
+
width: "full",
|
|
1191
|
+
metadata: { section: "custom-endpoints" }
|
|
1192
|
+
}
|
|
1193
|
+
]
|
|
1194
|
+
},
|
|
1195
|
+
{
|
|
1196
|
+
id: "contract-definitions",
|
|
1197
|
+
label: "Contract Definitions",
|
|
1198
|
+
description: void 0,
|
|
1199
|
+
supportsConnectionTest: false,
|
|
1200
|
+
fields: [
|
|
1201
|
+
// Informational note
|
|
1202
|
+
{
|
|
1203
|
+
id: "evm-contract-def-note",
|
|
1204
|
+
name: "_note_contract_def",
|
|
1205
|
+
type: "hidden",
|
|
1206
|
+
label: "",
|
|
1207
|
+
validation: {},
|
|
1208
|
+
isHidden: true,
|
|
1209
|
+
metadata: {
|
|
1210
|
+
hideTestConnection: true,
|
|
1211
|
+
note: {
|
|
1212
|
+
variant: "info",
|
|
1213
|
+
title: "Contract Definition Provider",
|
|
1214
|
+
lines: [
|
|
1215
|
+
"Select which provider the builder should try first when loading verified contract definitions. Deep links can override this preference temporarily."
|
|
1216
|
+
]
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
},
|
|
1220
|
+
// Default provider select
|
|
1221
|
+
{
|
|
1222
|
+
id: "evm-contract-def-provider",
|
|
1223
|
+
name: "defaultProvider",
|
|
1224
|
+
type: "select",
|
|
1225
|
+
label: "Default Contract Definition Provider",
|
|
1226
|
+
placeholder: "Select a provider",
|
|
1227
|
+
helperText: "Used as the first provider to query for contract definitions.",
|
|
1228
|
+
validation: {},
|
|
1229
|
+
options: [
|
|
1230
|
+
{ label: "Etherscan", value: EvmProviderKeys.Etherscan },
|
|
1231
|
+
{ label: "Sourcify", value: EvmProviderKeys.Sourcify }
|
|
1232
|
+
],
|
|
1233
|
+
// Seed from saved user config or app-config default if present; otherwise empty
|
|
1234
|
+
defaultValue: savedDefaultProvider || import_ui_builder_utils6.appConfigService.getGlobalServiceParam("contractdefinition", "defaultProvider") || "",
|
|
1235
|
+
width: "full"
|
|
1236
|
+
},
|
|
1237
|
+
// Apply to all networks
|
|
1238
|
+
{
|
|
1239
|
+
id: "evm-contract-def-apply-all",
|
|
1240
|
+
name: "applyToAllNetworks",
|
|
1241
|
+
type: "checkbox",
|
|
1242
|
+
label: "Apply to all compatible networks",
|
|
1243
|
+
helperText: "Apply this default provider setting to all compatible networks in your project.",
|
|
1244
|
+
validation: {},
|
|
1245
|
+
defaultValue: false,
|
|
1246
|
+
metadata: {
|
|
1247
|
+
nestUnder: "defaultProvider",
|
|
1248
|
+
disabledWhen: { field: "defaultProvider", equals: "" }
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
]
|
|
1252
|
+
}
|
|
1253
|
+
];
|
|
1254
|
+
}
|
|
1255
|
+
async function validateEvmNetworkServiceConfig(serviceId, values) {
|
|
1256
|
+
if (serviceId === "rpc") {
|
|
1257
|
+
const cfg = { url: String(values.rpcUrl || ""), isCustom: true };
|
|
1258
|
+
return validateEvmRpcEndpoint(cfg);
|
|
1259
|
+
}
|
|
1260
|
+
if (serviceId === "explorer") {
|
|
1261
|
+
const cfg = {
|
|
1262
|
+
explorerUrl: values.explorerUrl ? String(values.explorerUrl) : void 0,
|
|
1263
|
+
apiUrl: values.apiUrl ? String(values.apiUrl) : void 0,
|
|
1264
|
+
apiKey: values.apiKey ? String(values.apiKey) : void 0,
|
|
1265
|
+
isCustom: true,
|
|
1266
|
+
applyToAllNetworks: Boolean(values.applyToAllNetworks)
|
|
1267
|
+
};
|
|
1268
|
+
return validateEvmExplorerConfig(cfg);
|
|
1269
|
+
}
|
|
1270
|
+
if (serviceId === "contract-definitions") {
|
|
1271
|
+
const raw = values.defaultProvider;
|
|
1272
|
+
if (raw === void 0 || raw === null || raw === "") return true;
|
|
1273
|
+
return isEvmProviderKey(raw);
|
|
1274
|
+
}
|
|
1275
|
+
return true;
|
|
1276
|
+
}
|
|
1277
|
+
async function testEvmNetworkServiceConnection(serviceId, values, networkConfig) {
|
|
1278
|
+
if (serviceId === "rpc") {
|
|
1279
|
+
const cfg = { url: String(values.rpcUrl || ""), isCustom: true };
|
|
1280
|
+
return testEvmRpcConnection(cfg);
|
|
1281
|
+
}
|
|
1282
|
+
if (serviceId === "explorer") {
|
|
1283
|
+
const cfg = {
|
|
1284
|
+
explorerUrl: values.explorerUrl ? String(values.explorerUrl) : void 0,
|
|
1285
|
+
apiUrl: values.apiUrl ? String(values.apiUrl) : void 0,
|
|
1286
|
+
apiKey: values.apiKey ? String(values.apiKey) : void 0,
|
|
1287
|
+
isCustom: true,
|
|
1288
|
+
applyToAllNetworks: Boolean(values.applyToAllNetworks)
|
|
1289
|
+
};
|
|
1290
|
+
return testEvmExplorerConnection(cfg, networkConfig);
|
|
1291
|
+
}
|
|
1292
|
+
return { success: true };
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
// src/wallet/components/EvmWalletUiRoot.tsx
|
|
1296
|
+
var import_react_query = require("@tanstack/react-query");
|
|
1297
|
+
var import_core3 = require("@wagmi/core");
|
|
1298
|
+
var import_chains3 = require("viem/chains");
|
|
1299
|
+
var import_wagmi = require("wagmi");
|
|
1300
|
+
var import_react9 = require("react");
|
|
1301
|
+
var import_ui_builder_utils19 = require("@openzeppelin/ui-builder-utils");
|
|
1302
|
+
|
|
1303
|
+
// src/wallet/context/wagmi-context.tsx
|
|
1304
|
+
var import_react = require("react");
|
|
1305
|
+
var WagmiProviderInitializedContext = (0, import_react.createContext)(false);
|
|
1306
|
+
|
|
1307
|
+
// src/wallet/evmUiKitManager.ts
|
|
1308
|
+
var import_ui_builder_utils18 = require("@openzeppelin/ui-builder-utils");
|
|
1309
|
+
|
|
1310
|
+
// src/wallet/utils/walletImplementationManager.ts
|
|
1311
|
+
var import_ui_builder_utils16 = require("@openzeppelin/ui-builder-utils");
|
|
1312
|
+
|
|
1313
|
+
// src/wallet/implementation/wagmi-implementation.ts
|
|
1314
|
+
var import_connectors = require("@wagmi/connectors");
|
|
1315
|
+
var import_core2 = require("@wagmi/core");
|
|
1316
|
+
var import_viem3 = require("viem");
|
|
1317
|
+
var import_ui_builder_utils15 = require("@openzeppelin/ui-builder-utils");
|
|
1318
|
+
|
|
1319
|
+
// src/networks/mainnet.ts
|
|
1320
|
+
var import_react2 = require("@web3icons/react");
|
|
1321
|
+
var import_chains = require("viem/chains");
|
|
1322
|
+
var ethereumMainnet = {
|
|
1323
|
+
id: "ethereum-mainnet",
|
|
1324
|
+
exportConstName: "ethereumMainnet",
|
|
1325
|
+
name: "Ethereum",
|
|
1326
|
+
ecosystem: "evm",
|
|
1327
|
+
network: "ethereum",
|
|
1328
|
+
type: "mainnet",
|
|
1329
|
+
isTestnet: false,
|
|
1330
|
+
chainId: 1,
|
|
1331
|
+
rpcUrl: import_chains.mainnet.rpcUrls.default.http[0],
|
|
1332
|
+
explorerUrl: "https://etherscan.io",
|
|
1333
|
+
apiUrl: "https://api.etherscan.io/v2/api",
|
|
1334
|
+
primaryExplorerApiIdentifier: "etherscan-v2",
|
|
1335
|
+
supportsEtherscanV2: true,
|
|
1336
|
+
iconComponent: import_react2.NetworkEthereum,
|
|
1337
|
+
nativeCurrency: {
|
|
1338
|
+
name: "Ether",
|
|
1339
|
+
symbol: "ETH",
|
|
1340
|
+
decimals: 18
|
|
1341
|
+
},
|
|
1342
|
+
viemChain: import_chains.mainnet
|
|
1343
|
+
};
|
|
1344
|
+
var arbitrumMainnet = {
|
|
1345
|
+
id: "arbitrum-mainnet",
|
|
1346
|
+
exportConstName: "arbitrumMainnet",
|
|
1347
|
+
name: "Arbitrum One",
|
|
1348
|
+
ecosystem: "evm",
|
|
1349
|
+
network: "arbitrum",
|
|
1350
|
+
type: "mainnet",
|
|
1351
|
+
isTestnet: false,
|
|
1352
|
+
chainId: 42161,
|
|
1353
|
+
rpcUrl: import_chains.arbitrum.rpcUrls.default.http[0],
|
|
1354
|
+
explorerUrl: "https://arbiscan.io",
|
|
1355
|
+
apiUrl: "https://api.etherscan.io/v2/api",
|
|
1356
|
+
primaryExplorerApiIdentifier: "etherscan-v2",
|
|
1357
|
+
supportsEtherscanV2: true,
|
|
1358
|
+
iconComponent: import_react2.NetworkArbitrumOne,
|
|
1359
|
+
nativeCurrency: {
|
|
1360
|
+
name: "Ether",
|
|
1361
|
+
symbol: "ETH",
|
|
1362
|
+
decimals: 18
|
|
1363
|
+
},
|
|
1364
|
+
viemChain: import_chains.arbitrum
|
|
1365
|
+
};
|
|
1366
|
+
var polygonMainnet = {
|
|
1367
|
+
id: "polygon-mainnet",
|
|
1368
|
+
exportConstName: "polygonMainnet",
|
|
1369
|
+
name: "Polygon",
|
|
1370
|
+
ecosystem: "evm",
|
|
1371
|
+
network: "polygon",
|
|
1372
|
+
type: "mainnet",
|
|
1373
|
+
isTestnet: false,
|
|
1374
|
+
chainId: 137,
|
|
1375
|
+
rpcUrl: import_chains.polygon.rpcUrls.default.http[0],
|
|
1376
|
+
explorerUrl: "https://polygonscan.com",
|
|
1377
|
+
apiUrl: "https://api.etherscan.io/v2/api",
|
|
1378
|
+
primaryExplorerApiIdentifier: "etherscan-v2",
|
|
1379
|
+
supportsEtherscanV2: true,
|
|
1380
|
+
iconComponent: import_react2.NetworkPolygon,
|
|
1381
|
+
nativeCurrency: {
|
|
1382
|
+
name: "MATIC",
|
|
1383
|
+
symbol: "MATIC",
|
|
1384
|
+
decimals: 18
|
|
1385
|
+
},
|
|
1386
|
+
viemChain: import_chains.polygon
|
|
1387
|
+
};
|
|
1388
|
+
var polygonZkEvmMainnet = {
|
|
1389
|
+
id: "polygon-zkevm-mainnet",
|
|
1390
|
+
exportConstName: "polygonZkEvmMainnet",
|
|
1391
|
+
name: "Polygon zkEVM",
|
|
1392
|
+
ecosystem: "evm",
|
|
1393
|
+
network: "polygon-zkevm",
|
|
1394
|
+
type: "mainnet",
|
|
1395
|
+
isTestnet: false,
|
|
1396
|
+
chainId: 1101,
|
|
1397
|
+
rpcUrl: import_chains.polygonZkEvm.rpcUrls.default.http[0],
|
|
1398
|
+
explorerUrl: "https://zkevm.polygonscan.com",
|
|
1399
|
+
apiUrl: "https://api.etherscan.io/v2/api",
|
|
1400
|
+
primaryExplorerApiIdentifier: "etherscan-v2",
|
|
1401
|
+
supportsEtherscanV2: true,
|
|
1402
|
+
iconComponent: import_react2.NetworkPolygon,
|
|
1403
|
+
nativeCurrency: {
|
|
1404
|
+
name: "Ether",
|
|
1405
|
+
symbol: "ETH",
|
|
1406
|
+
decimals: 18
|
|
1407
|
+
},
|
|
1408
|
+
viemChain: import_chains.polygonZkEvm
|
|
1409
|
+
};
|
|
1410
|
+
var baseMainnet = {
|
|
1411
|
+
id: "base-mainnet",
|
|
1412
|
+
exportConstName: "baseMainnet",
|
|
1413
|
+
name: "Base",
|
|
1414
|
+
ecosystem: "evm",
|
|
1415
|
+
network: "base",
|
|
1416
|
+
type: "mainnet",
|
|
1417
|
+
isTestnet: false,
|
|
1418
|
+
chainId: 8453,
|
|
1419
|
+
rpcUrl: import_chains.base.rpcUrls.default.http[0],
|
|
1420
|
+
explorerUrl: "https://basescan.org",
|
|
1421
|
+
apiUrl: "https://api.etherscan.io/v2/api",
|
|
1422
|
+
primaryExplorerApiIdentifier: "etherscan-v2",
|
|
1423
|
+
supportsEtherscanV2: true,
|
|
1424
|
+
iconComponent: import_react2.NetworkBase,
|
|
1425
|
+
nativeCurrency: {
|
|
1426
|
+
name: "Ether",
|
|
1427
|
+
symbol: "ETH",
|
|
1428
|
+
decimals: 18
|
|
1429
|
+
},
|
|
1430
|
+
viemChain: import_chains.base
|
|
1431
|
+
};
|
|
1432
|
+
var bscMainnet = {
|
|
1433
|
+
id: "bsc-mainnet",
|
|
1434
|
+
exportConstName: "bscMainnet",
|
|
1435
|
+
name: "BNB Smart Chain",
|
|
1436
|
+
ecosystem: "evm",
|
|
1437
|
+
network: "bsc",
|
|
1438
|
+
type: "mainnet",
|
|
1439
|
+
isTestnet: false,
|
|
1440
|
+
chainId: 56,
|
|
1441
|
+
rpcUrl: import_chains.bsc.rpcUrls.default.http[0],
|
|
1442
|
+
explorerUrl: "https://bscscan.com",
|
|
1443
|
+
apiUrl: "https://api.etherscan.io/v2/api",
|
|
1444
|
+
primaryExplorerApiIdentifier: "etherscan-v2",
|
|
1445
|
+
supportsEtherscanV2: true,
|
|
1446
|
+
iconComponent: import_react2.NetworkBinanceSmartChain,
|
|
1447
|
+
nativeCurrency: {
|
|
1448
|
+
name: "BNB",
|
|
1449
|
+
symbol: "BNB",
|
|
1450
|
+
decimals: 18
|
|
1451
|
+
},
|
|
1452
|
+
viemChain: import_chains.bsc
|
|
1453
|
+
};
|
|
1454
|
+
var optimismMainnet = {
|
|
1455
|
+
id: "optimism-mainnet",
|
|
1456
|
+
exportConstName: "optimismMainnet",
|
|
1457
|
+
name: "OP Mainnet",
|
|
1458
|
+
ecosystem: "evm",
|
|
1459
|
+
network: "optimism",
|
|
1460
|
+
type: "mainnet",
|
|
1461
|
+
isTestnet: false,
|
|
1462
|
+
chainId: 10,
|
|
1463
|
+
rpcUrl: import_chains.optimism.rpcUrls.default.http[0],
|
|
1464
|
+
explorerUrl: "https://optimistic.etherscan.io",
|
|
1465
|
+
apiUrl: "https://api.etherscan.io/v2/api",
|
|
1466
|
+
primaryExplorerApiIdentifier: "etherscan-v2",
|
|
1467
|
+
supportsEtherscanV2: true,
|
|
1468
|
+
iconComponent: import_react2.NetworkOptimism,
|
|
1469
|
+
nativeCurrency: {
|
|
1470
|
+
name: "Ether",
|
|
1471
|
+
symbol: "ETH",
|
|
1472
|
+
decimals: 18
|
|
1473
|
+
},
|
|
1474
|
+
viemChain: import_chains.optimism
|
|
1475
|
+
};
|
|
1476
|
+
var avalancheMainnet = {
|
|
1477
|
+
id: "avalanche-mainnet",
|
|
1478
|
+
exportConstName: "avalancheMainnet",
|
|
1479
|
+
name: "Avalanche C-Chain",
|
|
1480
|
+
ecosystem: "evm",
|
|
1481
|
+
network: "avalanche",
|
|
1482
|
+
type: "mainnet",
|
|
1483
|
+
isTestnet: false,
|
|
1484
|
+
chainId: 43114,
|
|
1485
|
+
rpcUrl: import_chains.avalanche.rpcUrls.default.http[0],
|
|
1486
|
+
explorerUrl: "https://snowscan.xyz",
|
|
1487
|
+
apiUrl: "https://api.etherscan.io/v2/api",
|
|
1488
|
+
primaryExplorerApiIdentifier: "etherscan-v2",
|
|
1489
|
+
supportsEtherscanV2: true,
|
|
1490
|
+
iconComponent: import_react2.NetworkAvalanche,
|
|
1491
|
+
nativeCurrency: {
|
|
1492
|
+
name: "Avalanche",
|
|
1493
|
+
symbol: "AVAX",
|
|
1494
|
+
decimals: 18
|
|
1495
|
+
},
|
|
1496
|
+
viemChain: import_chains.avalanche
|
|
1497
|
+
};
|
|
1498
|
+
var zkSyncEraMainnet = {
|
|
1499
|
+
id: "zksync-era-mainnet",
|
|
673
1500
|
exportConstName: "zkSyncEraMainnet",
|
|
674
1501
|
name: "ZkSync Era",
|
|
675
1502
|
ecosystem: "evm",
|
|
@@ -1042,18 +1869,18 @@ var evmNetworks = [...evmMainnetNetworks, ...evmTestnetNetworks];
|
|
|
1042
1869
|
var import_lucide_react4 = require("lucide-react");
|
|
1043
1870
|
var import_react8 = require("react");
|
|
1044
1871
|
var import_ui_builder_ui5 = require("@openzeppelin/ui-builder-ui");
|
|
1045
|
-
var
|
|
1872
|
+
var import_ui_builder_utils12 = require("@openzeppelin/ui-builder-utils");
|
|
1046
1873
|
|
|
1047
1874
|
// src/wallet/components/connect/ConnectButton.tsx
|
|
1048
1875
|
var import_lucide_react = require("lucide-react");
|
|
1049
1876
|
var import_react7 = require("react");
|
|
1050
1877
|
var import_ui_builder_react_core2 = require("@openzeppelin/ui-builder-react-core");
|
|
1051
1878
|
var import_ui_builder_ui2 = require("@openzeppelin/ui-builder-ui");
|
|
1052
|
-
var
|
|
1879
|
+
var import_ui_builder_utils9 = require("@openzeppelin/ui-builder-utils");
|
|
1053
1880
|
|
|
1054
1881
|
// src/wallet/utils/SafeWagmiComponent.tsx
|
|
1055
1882
|
var import_react5 = require("react");
|
|
1056
|
-
var
|
|
1883
|
+
var import_ui_builder_utils7 = require("@openzeppelin/ui-builder-utils");
|
|
1057
1884
|
|
|
1058
1885
|
// src/wallet/hooks/useIsWagmiProviderInitialized.ts
|
|
1059
1886
|
var import_react4 = require("react");
|
|
@@ -1077,7 +1904,7 @@ var SafeWagmiComponent = ({
|
|
|
1077
1904
|
(0, import_react5.useEffect)(() => {
|
|
1078
1905
|
const handleError = (event) => {
|
|
1079
1906
|
if (event.error?.message?.includes("useConfig") || event.error?.message?.includes("WagmiProvider")) {
|
|
1080
|
-
|
|
1907
|
+
import_ui_builder_utils7.logger.debug(
|
|
1081
1908
|
"SafeWagmiComponent",
|
|
1082
1909
|
"Caught wagmi error via window error event:",
|
|
1083
1910
|
event.error
|
|
@@ -1098,7 +1925,7 @@ var SafeWagmiComponent = ({
|
|
|
1098
1925
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
|
|
1099
1926
|
} catch (error) {
|
|
1100
1927
|
if (error instanceof Error && (error.message.includes("useConfig") || error.message.includes("WagmiProvider"))) {
|
|
1101
|
-
|
|
1928
|
+
import_ui_builder_utils7.logger.debug("SafeWagmiComponent", "Caught wagmi error:", error);
|
|
1102
1929
|
setHasError(true);
|
|
1103
1930
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: fallback });
|
|
1104
1931
|
}
|
|
@@ -1112,7 +1939,7 @@ var import_ui_builder_react_core = require("@openzeppelin/ui-builder-react-core"
|
|
|
1112
1939
|
var import_ui_builder_ui = require("@openzeppelin/ui-builder-ui");
|
|
1113
1940
|
|
|
1114
1941
|
// src/wallet/hooks/useUiKitConfig.ts
|
|
1115
|
-
var
|
|
1942
|
+
var import_ui_builder_utils8 = require("@openzeppelin/ui-builder-utils");
|
|
1116
1943
|
var defaultConfig = {
|
|
1117
1944
|
kitName: "custom",
|
|
1118
1945
|
// Default to using our custom implementation for EVM
|
|
@@ -1123,10 +1950,10 @@ var defaultConfig = {
|
|
|
1123
1950
|
};
|
|
1124
1951
|
var uiKitConfig = { ...defaultConfig };
|
|
1125
1952
|
function loadInitialConfigFromAppService() {
|
|
1126
|
-
|
|
1127
|
-
const configObj =
|
|
1953
|
+
import_ui_builder_utils8.logger.debug("useUiKitConfig", "Attempting to load initial config from AppConfigService...");
|
|
1954
|
+
const configObj = import_ui_builder_utils8.appConfigService.getWalletUIConfig("evm");
|
|
1128
1955
|
if (configObj && configObj.kitName) {
|
|
1129
|
-
|
|
1956
|
+
import_ui_builder_utils8.logger.info(
|
|
1130
1957
|
"useUiKitConfig",
|
|
1131
1958
|
`Loaded initial config from AppConfigService: kitName=${configObj.kitName}`,
|
|
1132
1959
|
configObj.kitConfig
|
|
@@ -1136,7 +1963,7 @@ function loadInitialConfigFromAppService() {
|
|
|
1136
1963
|
kitConfig: { ...defaultConfig.kitConfig, ...configObj.kitConfig || {} }
|
|
1137
1964
|
};
|
|
1138
1965
|
}
|
|
1139
|
-
|
|
1966
|
+
import_ui_builder_utils8.logger.debug(
|
|
1140
1967
|
"useUiKitConfig",
|
|
1141
1968
|
"No initial config found in AppConfigService, using module default."
|
|
1142
1969
|
);
|
|
@@ -1222,7 +2049,7 @@ var CustomConnectButton = ({
|
|
|
1222
2049
|
hideWhenConnected = true
|
|
1223
2050
|
}) => {
|
|
1224
2051
|
const [dialogOpen, setDialogOpen] = (0, import_react7.useState)(false);
|
|
1225
|
-
const unavailableButton = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: (0,
|
|
2052
|
+
const unavailableButton = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: (0, import_ui_builder_utils9.cn)("flex items-center", className), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_ui_builder_ui2.Button, { disabled: true, variant: "outline", size: "sm", className: "h-8 px-2 text-xs", children: [
|
|
1226
2053
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_lucide_react.Wallet, { className: "size-3.5 mr-1" }),
|
|
1227
2054
|
"Wallet Unavailable"
|
|
1228
2055
|
] }) });
|
|
@@ -1266,7 +2093,7 @@ var ConnectButtonContent = ({ className, dialogOpen, setDialogOpen, hideWhenConn
|
|
|
1266
2093
|
return null;
|
|
1267
2094
|
}
|
|
1268
2095
|
const showButtonLoading = isHookConnecting || isManuallyInitiated;
|
|
1269
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: (0,
|
|
2096
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: (0, import_ui_builder_utils9.cn)("flex items-center", className), children: [
|
|
1270
2097
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1271
2098
|
import_ui_builder_ui2.Button,
|
|
1272
2099
|
{
|
|
@@ -1301,7 +2128,7 @@ var ConnectButtonContent = ({ className, dialogOpen, setDialogOpen, hideWhenConn
|
|
|
1301
2128
|
var import_lucide_react2 = require("lucide-react");
|
|
1302
2129
|
var import_ui_builder_react_core3 = require("@openzeppelin/ui-builder-react-core");
|
|
1303
2130
|
var import_ui_builder_ui3 = require("@openzeppelin/ui-builder-ui");
|
|
1304
|
-
var
|
|
2131
|
+
var import_ui_builder_utils10 = require("@openzeppelin/ui-builder-utils");
|
|
1305
2132
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1306
2133
|
var CustomAccountDisplay = ({ className }) => {
|
|
1307
2134
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SafeWagmiComponent, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AccountDisplayContent, { className }) });
|
|
@@ -1312,9 +2139,9 @@ var AccountDisplayContent = ({ className }) => {
|
|
|
1312
2139
|
if (!isConnected || !address || !disconnect2) {
|
|
1313
2140
|
return null;
|
|
1314
2141
|
}
|
|
1315
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: (0,
|
|
2142
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: (0, import_ui_builder_utils10.cn)("flex items-center gap-2", className), children: [
|
|
1316
2143
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex flex-col", children: [
|
|
1317
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "text-xs font-medium", children: (0,
|
|
2144
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "text-xs font-medium", children: (0, import_ui_builder_utils10.truncateMiddle)(address, 4, 4) }),
|
|
1318
2145
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "text-[9px] text-muted-foreground -mt-0.5", children: chainId ? `Chain ID: ${chainId}` : "Chain ID: N/A" })
|
|
1319
2146
|
] }),
|
|
1320
2147
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
@@ -1335,7 +2162,7 @@ var AccountDisplayContent = ({ className }) => {
|
|
|
1335
2162
|
var import_lucide_react3 = require("lucide-react");
|
|
1336
2163
|
var import_ui_builder_react_core4 = require("@openzeppelin/ui-builder-react-core");
|
|
1337
2164
|
var import_ui_builder_ui4 = require("@openzeppelin/ui-builder-ui");
|
|
1338
|
-
var
|
|
2165
|
+
var import_ui_builder_utils11 = require("@openzeppelin/ui-builder-utils");
|
|
1339
2166
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1340
2167
|
var CustomNetworkSwitcher = ({ className }) => {
|
|
1341
2168
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SafeWagmiComponent, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(NetworkSwitcherContent, { className }) });
|
|
@@ -1355,7 +2182,7 @@ var NetworkSwitcherContent = ({ className }) => {
|
|
|
1355
2182
|
};
|
|
1356
2183
|
const currentChain = typedAvailableChains.find((chain) => chain.id === currentChainId);
|
|
1357
2184
|
const currentChainName = currentChain?.name || "Network";
|
|
1358
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: (0,
|
|
2185
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: (0, import_ui_builder_utils11.cn)("flex items-center", className), children: [
|
|
1359
2186
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
1360
2187
|
import_ui_builder_ui4.Select,
|
|
1361
2188
|
{
|
|
@@ -1435,7 +2262,7 @@ var RainbowKitConnectButton = (props) => {
|
|
|
1435
2262
|
if (isMounted) {
|
|
1436
2263
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
1437
2264
|
setIsLoadingComponent(false);
|
|
1438
|
-
|
|
2265
|
+
import_ui_builder_utils12.logger.error("RainbowKitConnectButton", "Failed to load RainbowKit ConnectButton:", err);
|
|
1439
2266
|
}
|
|
1440
2267
|
}
|
|
1441
2268
|
};
|
|
@@ -1453,7 +2280,7 @@ var RainbowKitConnectButton = (props) => {
|
|
|
1453
2280
|
disabled: true,
|
|
1454
2281
|
variant: "outline",
|
|
1455
2282
|
size: "sm",
|
|
1456
|
-
className: (0,
|
|
2283
|
+
className: (0, import_ui_builder_utils12.cn)("h-8 px-2 text-xs", props.className),
|
|
1457
2284
|
children: [
|
|
1458
2285
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.Loader2, { className: "h-3.5 w-3.5 animate-spin mr-1.5" }),
|
|
1459
2286
|
message
|
|
@@ -1461,7 +2288,7 @@ var RainbowKitConnectButton = (props) => {
|
|
|
1461
2288
|
}
|
|
1462
2289
|
);
|
|
1463
2290
|
if (error) {
|
|
1464
|
-
|
|
2291
|
+
import_ui_builder_utils12.logger.warn(
|
|
1465
2292
|
"RainbowKitConnectButton",
|
|
1466
2293
|
"Error loading RainbowKit ConnectButton. Displaying fallback CustomConnectButton."
|
|
1467
2294
|
);
|
|
@@ -1474,7 +2301,7 @@ var RainbowKitConnectButton = (props) => {
|
|
|
1474
2301
|
return renderLoadingPlaceholder("Initializing Provider...");
|
|
1475
2302
|
}
|
|
1476
2303
|
if (!Component) {
|
|
1477
|
-
|
|
2304
|
+
import_ui_builder_utils12.logger.warn("RainbowKitConnectButton", "Component is null after loading phase, falling back.");
|
|
1478
2305
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CustomConnectButton, { ...props });
|
|
1479
2306
|
}
|
|
1480
2307
|
const kitConfig = managerState.currentFullUiKitConfig?.kitConfig;
|
|
@@ -1486,7 +2313,7 @@ var RainbowKitConnectButton = (props) => {
|
|
|
1486
2313
|
...props
|
|
1487
2314
|
// Allow props to override configuration
|
|
1488
2315
|
};
|
|
1489
|
-
|
|
2316
|
+
import_ui_builder_utils12.logger.debug("RainbowKitConnectButton", "Rendering with configuration:", {
|
|
1490
2317
|
configFromFile: connectButtonConfig,
|
|
1491
2318
|
finalProps
|
|
1492
2319
|
});
|
|
@@ -1494,20 +2321,20 @@ var RainbowKitConnectButton = (props) => {
|
|
|
1494
2321
|
};
|
|
1495
2322
|
|
|
1496
2323
|
// src/wallet/rainbowkit/utils.ts
|
|
1497
|
-
var
|
|
2324
|
+
var import_ui_builder_utils13 = require("@openzeppelin/ui-builder-utils");
|
|
1498
2325
|
function validateRainbowKitConfig(kitConfig) {
|
|
1499
|
-
|
|
2326
|
+
import_ui_builder_utils13.logger.debug(
|
|
1500
2327
|
"validateRainbowKitConfig",
|
|
1501
2328
|
"Received kitConfig for validation:",
|
|
1502
2329
|
JSON.stringify(kitConfig)
|
|
1503
2330
|
);
|
|
1504
2331
|
if (!kitConfig) {
|
|
1505
|
-
|
|
2332
|
+
import_ui_builder_utils13.logger.warn("validateRainbowKitConfig", "Validation failed: No kitConfig provided.");
|
|
1506
2333
|
return { isValid: false, error: "No kitConfig provided for RainbowKit" };
|
|
1507
2334
|
}
|
|
1508
2335
|
const wagmiParamsFromKitConfig = kitConfig.wagmiParams;
|
|
1509
2336
|
if (!wagmiParamsFromKitConfig || typeof wagmiParamsFromKitConfig !== "object" || wagmiParamsFromKitConfig === null) {
|
|
1510
|
-
|
|
2337
|
+
import_ui_builder_utils13.logger.warn(
|
|
1511
2338
|
"validateRainbowKitConfig",
|
|
1512
2339
|
"Validation failed: kitConfig.wagmiParams is missing or invalid.",
|
|
1513
2340
|
{ wagmiParamsFromKitConfig }
|
|
@@ -1523,14 +2350,14 @@ function validateRainbowKitConfig(kitConfig) {
|
|
|
1523
2350
|
}
|
|
1524
2351
|
if (missingFields.length > 0) {
|
|
1525
2352
|
const errorMsg = `Missing or invalid required fields in wagmiParams: ${missingFields.join(", ")}`;
|
|
1526
|
-
|
|
2353
|
+
import_ui_builder_utils13.logger.warn("validateRainbowKitConfig", "Validation failed:", errorMsg, { missingFields });
|
|
1527
2354
|
return {
|
|
1528
2355
|
isValid: false,
|
|
1529
2356
|
missingFields,
|
|
1530
2357
|
error: errorMsg
|
|
1531
2358
|
};
|
|
1532
2359
|
}
|
|
1533
|
-
|
|
2360
|
+
import_ui_builder_utils13.logger.debug("validateRainbowKitConfig", "Validation successful.");
|
|
1534
2361
|
return { isValid: true };
|
|
1535
2362
|
}
|
|
1536
2363
|
|
|
@@ -1545,63 +2372,12 @@ function createRainbowKitComponents() {
|
|
|
1545
2372
|
|
|
1546
2373
|
// src/wallet/rainbowkit/config-service.ts
|
|
1547
2374
|
var import_core = require("@wagmi/core");
|
|
1548
|
-
var
|
|
1549
|
-
var cacheInstanceId = Math.random().toString(36).substring(7);
|
|
1550
|
-
var configCache = /* @__PURE__ */ new Map();
|
|
1551
|
-
import_ui_builder_utils9.logger.debug("rainbowkit/config-service", "NEW configCache INSTANCE CREATED", cacheInstanceId);
|
|
1552
|
-
function createConfigCacheKey(userFullNativeConfig, chains) {
|
|
1553
|
-
const wagmiParamsContent = userFullNativeConfig?.wagmiParams;
|
|
1554
|
-
const chainIds = chains.map((c) => c.id).sort();
|
|
1555
|
-
const keyObject = {
|
|
1556
|
-
wagmiParams: wagmiParamsContent,
|
|
1557
|
-
chainIds
|
|
1558
|
-
};
|
|
1559
|
-
const configHash = JSON.stringify(keyObject);
|
|
1560
|
-
import_ui_builder_utils9.logger.debug(
|
|
1561
|
-
"rainbowkit/config-service:createConfigCacheKey",
|
|
1562
|
-
"Key generation input - userFullNativeConfig.wagmiParams:",
|
|
1563
|
-
wagmiParamsContent,
|
|
1564
|
-
"Key generation input - chainIds:",
|
|
1565
|
-
chainIds,
|
|
1566
|
-
"Generated Key Object for stringify:",
|
|
1567
|
-
keyObject,
|
|
1568
|
-
"Generated Hash:",
|
|
1569
|
-
configHash
|
|
1570
|
-
);
|
|
1571
|
-
return configHash;
|
|
1572
|
-
}
|
|
2375
|
+
var import_ui_builder_utils14 = require("@openzeppelin/ui-builder-utils");
|
|
1573
2376
|
async function createRainbowKitWagmiConfig(userFullNativeConfig, chains, chainIdToNetworkIdMap, getRpcEndpointOverride) {
|
|
1574
2377
|
try {
|
|
1575
|
-
const cacheKey = createConfigCacheKey(userFullNativeConfig, chains);
|
|
1576
|
-
import_ui_builder_utils9.logger.info(
|
|
1577
|
-
"rainbowkit/config-service:createRainbowKitWagmiConfig",
|
|
1578
|
-
"Attempting to get/create config. Cache Key:",
|
|
1579
|
-
cacheKey,
|
|
1580
|
-
"Using cache instance ID:",
|
|
1581
|
-
cacheInstanceId
|
|
1582
|
-
);
|
|
1583
|
-
const cachedConfig = configCache.get(cacheKey);
|
|
1584
|
-
if (cachedConfig) {
|
|
1585
|
-
import_ui_builder_utils9.logger.info(
|
|
1586
|
-
"rainbowkit/config-service:createRainbowKitWagmiConfig",
|
|
1587
|
-
"CACHE HIT. Returning cached RainbowKit Wagmi config.",
|
|
1588
|
-
{
|
|
1589
|
-
cacheKey,
|
|
1590
|
-
cacheInstanceId,
|
|
1591
|
-
cachedConfigObjectId: typeof cachedConfig?.storage === "object" && cachedConfig.storage !== null ? "WagmiStorageObject" : String(cachedConfig?.storage)
|
|
1592
|
-
}
|
|
1593
|
-
);
|
|
1594
|
-
return cachedConfig;
|
|
1595
|
-
} else {
|
|
1596
|
-
import_ui_builder_utils9.logger.warn(
|
|
1597
|
-
"rainbowkit/config-service:createRainbowKitWagmiConfig",
|
|
1598
|
-
"CACHE MISS. Proceeding to create new RainbowKit Wagmi config.",
|
|
1599
|
-
{ cacheKey, cacheSize: configCache.size, cacheInstanceId }
|
|
1600
|
-
);
|
|
1601
|
-
}
|
|
1602
2378
|
const { getDefaultConfig } = await import("@rainbow-me/rainbowkit");
|
|
1603
2379
|
if (!getDefaultConfig) {
|
|
1604
|
-
|
|
2380
|
+
import_ui_builder_utils14.logger.error(
|
|
1605
2381
|
"rainbowkit/config-service",
|
|
1606
2382
|
"Failed to import getDefaultConfig from RainbowKit"
|
|
1607
2383
|
);
|
|
@@ -1609,21 +2385,21 @@ async function createRainbowKitWagmiConfig(userFullNativeConfig, chains, chainId
|
|
|
1609
2385
|
}
|
|
1610
2386
|
const wagmiParams = userFullNativeConfig?.wagmiParams;
|
|
1611
2387
|
if (!wagmiParams) {
|
|
1612
|
-
|
|
2388
|
+
import_ui_builder_utils14.logger.warn(
|
|
1613
2389
|
"rainbowkit/config-service",
|
|
1614
2390
|
"Resolved kitConfig does not contain a `wagmiParams` object. Cannot create RainbowKit Wagmi config."
|
|
1615
2391
|
);
|
|
1616
2392
|
return null;
|
|
1617
2393
|
}
|
|
1618
2394
|
if (typeof wagmiParams.appName !== "string" || !wagmiParams.appName) {
|
|
1619
|
-
|
|
2395
|
+
import_ui_builder_utils14.logger.warn(
|
|
1620
2396
|
"rainbowkit/config-service",
|
|
1621
2397
|
"kitConfig.wagmiParams is missing or has invalid `appName`."
|
|
1622
2398
|
);
|
|
1623
2399
|
return null;
|
|
1624
2400
|
}
|
|
1625
2401
|
if (typeof wagmiParams.projectId !== "string" || !wagmiParams.projectId) {
|
|
1626
|
-
|
|
2402
|
+
import_ui_builder_utils14.logger.warn(
|
|
1627
2403
|
"rainbowkit/config-service",
|
|
1628
2404
|
"kitConfig.wagmiParams is missing or has invalid `projectId`."
|
|
1629
2405
|
);
|
|
@@ -1638,15 +2414,15 @@ async function createRainbowKitWagmiConfig(userFullNativeConfig, chains, chainId
|
|
|
1638
2414
|
let httpRpcOverride;
|
|
1639
2415
|
if (typeof rpcOverrideSetting === "string") {
|
|
1640
2416
|
httpRpcOverride = rpcOverrideSetting;
|
|
1641
|
-
} else if (typeof rpcOverrideSetting === "object") {
|
|
1642
|
-
if (rpcOverrideSetting
|
|
2417
|
+
} else if (typeof rpcOverrideSetting === "object" && rpcOverrideSetting) {
|
|
2418
|
+
if ("http" in rpcOverrideSetting && rpcOverrideSetting.http) {
|
|
1643
2419
|
httpRpcOverride = rpcOverrideSetting.http;
|
|
1644
2420
|
} else if ("url" in rpcOverrideSetting && rpcOverrideSetting.url) {
|
|
1645
2421
|
httpRpcOverride = rpcOverrideSetting.url;
|
|
1646
2422
|
}
|
|
1647
2423
|
}
|
|
1648
2424
|
if (httpRpcOverride) {
|
|
1649
|
-
|
|
2425
|
+
import_ui_builder_utils14.logger.info(
|
|
1650
2426
|
"rainbowkit/config-service",
|
|
1651
2427
|
`Using overridden RPC for chain ${chainDefinition.name}: ${httpRpcOverride}`
|
|
1652
2428
|
);
|
|
@@ -1667,30 +2443,20 @@ async function createRainbowKitWagmiConfig(userFullNativeConfig, chains, chainId
|
|
|
1667
2443
|
// Adapter controls this
|
|
1668
2444
|
};
|
|
1669
2445
|
const config = getDefaultConfig(finalConfigOptions);
|
|
1670
|
-
|
|
1671
|
-
import_ui_builder_utils9.logger.info(
|
|
1672
|
-
"rainbowkit/config-service:createRainbowKitWagmiConfig",
|
|
1673
|
-
"New config created and cached. Cache Size now:",
|
|
1674
|
-
configCache.size,
|
|
1675
|
-
{
|
|
1676
|
-
cacheKey,
|
|
1677
|
-
cacheInstanceId
|
|
1678
|
-
}
|
|
1679
|
-
);
|
|
1680
|
-
import_ui_builder_utils9.logger.info(
|
|
2446
|
+
import_ui_builder_utils14.logger.info(
|
|
1681
2447
|
"rainbowkit/config-service",
|
|
1682
2448
|
"Successfully created RainbowKit Wagmi config object.",
|
|
1683
2449
|
config
|
|
1684
2450
|
);
|
|
1685
2451
|
return config;
|
|
1686
2452
|
} catch (error) {
|
|
1687
|
-
|
|
2453
|
+
import_ui_builder_utils14.logger.error("rainbowkit/config-service", "Error creating RainbowKit Wagmi config:", error);
|
|
1688
2454
|
return null;
|
|
1689
2455
|
}
|
|
1690
2456
|
}
|
|
1691
2457
|
async function getWagmiConfigForRainbowKit(uiKitConfiguration, chains, chainIdToNetworkIdMap, getRpcEndpointOverride) {
|
|
1692
2458
|
if (!uiKitConfiguration || uiKitConfiguration.kitName !== "rainbowkit" || !uiKitConfiguration.kitConfig) {
|
|
1693
|
-
|
|
2459
|
+
import_ui_builder_utils14.logger.debug(
|
|
1694
2460
|
"rainbowkit/config-service",
|
|
1695
2461
|
"Not configured for RainbowKit or kitConfig (resolved native + programmatic) is missing."
|
|
1696
2462
|
);
|
|
@@ -1710,7 +2476,7 @@ async function getWagmiConfigForRainbowKit(uiKitConfiguration, chains, chainIdTo
|
|
|
1710
2476
|
var LOG_SYSTEM = "WagmiWalletImplementation";
|
|
1711
2477
|
var getSupportedChainsFromNetworks = () => {
|
|
1712
2478
|
const chains = evmNetworks.filter((network) => network.viemChain).map((network) => network.viemChain).filter((chain, index, self) => self.findIndex((c) => c.id === chain.id) === index);
|
|
1713
|
-
|
|
2479
|
+
import_ui_builder_utils15.logger.info(
|
|
1714
2480
|
LOG_SYSTEM,
|
|
1715
2481
|
`Generated supported chains from network configurations: ${chains.length} chains`,
|
|
1716
2482
|
chains.map((c) => ({ id: c.id, name: c.name }))
|
|
@@ -1725,7 +2491,7 @@ var getChainIdToNetworkIdMapping = () => {
|
|
|
1725
2491
|
},
|
|
1726
2492
|
{}
|
|
1727
2493
|
);
|
|
1728
|
-
|
|
2494
|
+
import_ui_builder_utils15.logger.info(
|
|
1729
2495
|
LOG_SYSTEM,
|
|
1730
2496
|
"Generated chain ID to network ID mapping from network configurations:",
|
|
1731
2497
|
mapping
|
|
@@ -1747,1375 +2513,897 @@ var WagmiWalletImplementation = class {
|
|
|
1747
2513
|
// To be set by EvmUiKitManager
|
|
1748
2514
|
__publicField(this, "unsubscribe");
|
|
1749
2515
|
__publicField(this, "initialized", false);
|
|
1750
|
-
__publicField(this, "walletConnectProjectId");
|
|
1751
|
-
this.walletConnectProjectId = walletConnectProjectIdFromAppConfig;
|
|
1752
|
-
|
|
1753
|
-
LOG_SYSTEM,
|
|
1754
|
-
"Constructor called. Initial anticipated kitName:",
|
|
1755
|
-
initialUiKitConfig?.kitName
|
|
1756
|
-
);
|
|
1757
|
-
this.initialized = true;
|
|
1758
|
-
import_ui_builder_utils10.logger.info(
|
|
1759
|
-
LOG_SYSTEM,
|
|
1760
|
-
"WagmiWalletImplementation instance initialized (Wagmi config creation deferred)."
|
|
1761
|
-
);
|
|
1762
|
-
}
|
|
1763
|
-
/**
|
|
1764
|
-
* Sets the externally determined, currently active WagmiConfig instance.
|
|
1765
|
-
* This is typically called by EvmUiKitManager after it has resolved the appropriate
|
|
1766
|
-
* config for the selected UI kit (e.g., RainbowKit's config or a default custom config).
|
|
1767
|
-
* @param config - The Wagmi Config object to set as active, or null to clear it.
|
|
1768
|
-
*/
|
|
1769
|
-
setActiveWagmiConfig(config) {
|
|
1770
|
-
import_ui_builder_utils10.logger.info(
|
|
1771
|
-
LOG_SYSTEM,
|
|
1772
|
-
"setActiveWagmiConfig called with config:",
|
|
1773
|
-
config ? "Valid Config" : "Null"
|
|
1774
|
-
);
|
|
1775
|
-
this.activeWagmiConfig = config;
|
|
1776
|
-
if (this.unsubscribe) {
|
|
1777
|
-
import_ui_builder_utils10.logger.warn(
|
|
1778
|
-
LOG_SYSTEM,
|
|
1779
|
-
"setActiveWagmiConfig: Active WagmiConfig instance has changed. Existing direct watchAccount subscription (via onWalletConnectionChange) may be stale and operating on an old config instance."
|
|
1780
|
-
);
|
|
1781
|
-
}
|
|
1782
|
-
}
|
|
1783
|
-
/**
|
|
1784
|
-
* Creates a default WagmiConfig instance on demand.
|
|
1785
|
-
* This configuration includes standard connectors (injected, MetaMask, Safe)
|
|
1786
|
-
* and WalletConnect if a project ID is available.
|
|
1787
|
-
* Used as a fallback or for 'custom' UI kit mode.
|
|
1788
|
-
* @returns A Wagmi Config object.
|
|
1789
|
-
*/
|
|
1790
|
-
createDefaultConfig() {
|
|
1791
|
-
const baseConnectors = [(0, import_connectors.injected)(), (0, import_connectors.metaMask)(), (0, import_connectors.safe)()];
|
|
1792
|
-
if (this.walletConnectProjectId?.trim()) {
|
|
1793
|
-
baseConnectors.push((0, import_connectors.walletConnect)({ projectId: this.walletConnectProjectId }));
|
|
1794
|
-
import_ui_builder_utils10.logger.info(LOG_SYSTEM, "WalletConnect connector added to DEFAULT config.");
|
|
1795
|
-
} else {
|
|
1796
|
-
import_ui_builder_utils10.logger.warn(
|
|
1797
|
-
LOG_SYSTEM,
|
|
1798
|
-
"WalletConnect Project ID not provided; WC connector unavailable for DEFAULT config."
|
|
1799
|
-
);
|
|
1800
|
-
}
|
|
1801
|
-
const transportsConfig = defaultSupportedChains.reduce(
|
|
1802
|
-
(acc, chainDefinition) => {
|
|
1803
|
-
let rpcUrlToUse = chainDefinition.rpcUrls.default?.http?.[0];
|
|
1804
|
-
const appNetworkIdString = viemChainIdToAppNetworkId[chainDefinition.id];
|
|
1805
|
-
if (appNetworkIdString) {
|
|
1806
|
-
const rpcOverrideSetting = import_ui_builder_utils10.appConfigService.getRpcEndpointOverride(appNetworkIdString);
|
|
1807
|
-
let httpRpcOverride;
|
|
1808
|
-
if (typeof rpcOverrideSetting === "string") {
|
|
1809
|
-
httpRpcOverride = rpcOverrideSetting;
|
|
1810
|
-
} else if (typeof rpcOverrideSetting === "object") {
|
|
1811
|
-
if ("http" in rpcOverrideSetting && rpcOverrideSetting.http) {
|
|
1812
|
-
httpRpcOverride = rpcOverrideSetting.http;
|
|
1813
|
-
} else if ("url" in rpcOverrideSetting && rpcOverrideSetting.url) {
|
|
1814
|
-
httpRpcOverride = rpcOverrideSetting.url;
|
|
1815
|
-
}
|
|
1816
|
-
}
|
|
1817
|
-
if (httpRpcOverride) {
|
|
1818
|
-
import_ui_builder_utils10.logger.info(
|
|
1819
|
-
LOG_SYSTEM,
|
|
1820
|
-
`Using overridden RPC for chain ${chainDefinition.name} (default config): ${httpRpcOverride}`
|
|
1821
|
-
);
|
|
1822
|
-
rpcUrlToUse = httpRpcOverride;
|
|
1823
|
-
}
|
|
1824
|
-
}
|
|
1825
|
-
acc[chainDefinition.id] = (0, import_viem.http)(rpcUrlToUse);
|
|
1826
|
-
return acc;
|
|
1827
|
-
},
|
|
1828
|
-
{}
|
|
1829
|
-
);
|
|
1830
|
-
try {
|
|
1831
|
-
const defaultConfig2 = (0, import_core2.createConfig)({
|
|
1832
|
-
chains: defaultSupportedChains,
|
|
1833
|
-
connectors: baseConnectors,
|
|
1834
|
-
transports: transportsConfig
|
|
1835
|
-
});
|
|
1836
|
-
import_ui_builder_utils10.logger.info(LOG_SYSTEM, "Default Wagmi config created successfully on demand.");
|
|
1837
|
-
return defaultConfig2;
|
|
1838
|
-
} catch (error) {
|
|
1839
|
-
import_ui_builder_utils10.logger.error(LOG_SYSTEM, "Error creating default Wagmi config on demand:", error);
|
|
1840
|
-
return (0, import_core2.createConfig)({
|
|
1841
|
-
chains: [defaultSupportedChains[0]],
|
|
1842
|
-
connectors: [(0, import_connectors.injected)()],
|
|
1843
|
-
transports: { [defaultSupportedChains[0].id]: (0, import_viem.http)() }
|
|
1844
|
-
});
|
|
1845
|
-
}
|
|
1846
|
-
}
|
|
1847
|
-
/**
|
|
1848
|
-
* Wrapper function to convert AppConfigService RPC overrides to the format expected by RainbowKit.
|
|
1849
|
-
* @param networkId - The network ID to get RPC override for
|
|
1850
|
-
* @returns RPC configuration in the format expected by RainbowKit
|
|
1851
|
-
*/
|
|
1852
|
-
getRpcOverrideForRainbowKit(networkId) {
|
|
1853
|
-
const rpcOverrideSetting = import_ui_builder_utils10.appConfigService.getRpcEndpointOverride(networkId);
|
|
1854
|
-
if (typeof rpcOverrideSetting === "string") {
|
|
1855
|
-
return rpcOverrideSetting;
|
|
1856
|
-
} else if (typeof rpcOverrideSetting === "object" && rpcOverrideSetting !== null) {
|
|
1857
|
-
if ("url" in rpcOverrideSetting && typeof rpcOverrideSetting.url === "string") {
|
|
1858
|
-
return {
|
|
1859
|
-
http: rpcOverrideSetting.url
|
|
1860
|
-
};
|
|
1861
|
-
} else if ("http" in rpcOverrideSetting || "ws" in rpcOverrideSetting) {
|
|
1862
|
-
const config = rpcOverrideSetting;
|
|
1863
|
-
return {
|
|
1864
|
-
http: config.http,
|
|
1865
|
-
ws: config.ws
|
|
1866
|
-
};
|
|
1867
|
-
}
|
|
1868
|
-
}
|
|
1869
|
-
return void 0;
|
|
1870
|
-
}
|
|
1871
|
-
/**
|
|
1872
|
-
* Retrieves or creates the WagmiConfig specifically for RainbowKit.
|
|
1873
|
-
* This delegates to `getWagmiConfigForRainbowKit` service which handles caching
|
|
1874
|
-
* and uses RainbowKit's `getDefaultConfig`.
|
|
1875
|
-
* @param currentAdapterUiKitConfig - The fully resolved UI kit configuration for the adapter.
|
|
1876
|
-
* @returns A Promise resolving to the RainbowKit-specific Wagmi Config object, or null if creation fails or not RainbowKit.
|
|
1877
|
-
*/
|
|
1878
|
-
async getConfigForRainbowKit(currentAdapterUiKitConfig) {
|
|
1879
|
-
if (!this.initialized) {
|
|
1880
|
-
import_ui_builder_utils10.logger.error(
|
|
1881
|
-
LOG_SYSTEM,
|
|
1882
|
-
"getConfigForRainbowKit called before implementation initialization."
|
|
1883
|
-
);
|
|
1884
|
-
return null;
|
|
1885
|
-
}
|
|
1886
|
-
if (currentAdapterUiKitConfig?.kitName !== "rainbowkit") {
|
|
1887
|
-
import_ui_builder_utils10.logger.warn(
|
|
1888
|
-
LOG_SYSTEM,
|
|
1889
|
-
"getConfigForRainbowKit called, but kitName is not rainbowkit. Returning null."
|
|
1890
|
-
);
|
|
1891
|
-
return null;
|
|
1892
|
-
}
|
|
1893
|
-
import_ui_builder_utils10.logger.info(
|
|
1894
|
-
LOG_SYSTEM,
|
|
1895
|
-
"getConfigForRainbowKit: Kit is RainbowKit. Proceeding to create/get config. CurrentAdapterUiKitConfig:",
|
|
1896
|
-
currentAdapterUiKitConfig
|
|
1897
|
-
);
|
|
1898
|
-
const rainbowKitWagmiConfig = await getWagmiConfigForRainbowKit(
|
|
1899
|
-
currentAdapterUiKitConfig,
|
|
1900
|
-
defaultSupportedChains,
|
|
1901
|
-
viemChainIdToAppNetworkId,
|
|
1902
|
-
this.getRpcOverrideForRainbowKit.bind(this)
|
|
1903
|
-
);
|
|
1904
|
-
if (rainbowKitWagmiConfig) {
|
|
1905
|
-
import_ui_builder_utils10.logger.info(LOG_SYSTEM, "Returning RainbowKit-specific Wagmi config for provider.");
|
|
1906
|
-
return rainbowKitWagmiConfig;
|
|
1907
|
-
}
|
|
1908
|
-
import_ui_builder_utils10.logger.warn(LOG_SYSTEM, "RainbowKit specific Wagmi config creation failed.");
|
|
1909
|
-
return null;
|
|
1910
|
-
}
|
|
1911
|
-
/**
|
|
1912
|
-
* Determines and returns the WagmiConfig to be used by EvmUiKitManager during its configuration process.
|
|
1913
|
-
* If RainbowKit is specified in the passed uiKitConfig, it attempts to get its specific config.
|
|
1914
|
-
* Otherwise, it falls back to creating/returning a default instance config.
|
|
1915
|
-
* @param uiKitConfig - The fully resolved UiKitConfiguration that the manager is currently processing.
|
|
1916
|
-
* @returns A Promise resolving to the determined Wagmi Config object.
|
|
1917
|
-
*/
|
|
1918
|
-
async getActiveConfigForManager(uiKitConfig2) {
|
|
1919
|
-
if (!this.initialized) {
|
|
1920
|
-
import_ui_builder_utils10.logger.error(
|
|
1921
|
-
LOG_SYSTEM,
|
|
1922
|
-
"getActiveConfigForManager called before initialization! Creating fallback."
|
|
1923
|
-
);
|
|
1924
|
-
return (0, import_core2.createConfig)({
|
|
1925
|
-
chains: [defaultSupportedChains[0]],
|
|
1926
|
-
transports: { [defaultSupportedChains[0].id]: (0, import_viem.http)() }
|
|
1927
|
-
});
|
|
1928
|
-
}
|
|
1929
|
-
if (uiKitConfig2?.kitName === "rainbowkit") {
|
|
1930
|
-
const rkConfig = await this.getConfigForRainbowKit(uiKitConfig2);
|
|
1931
|
-
if (rkConfig) return rkConfig;
|
|
1932
|
-
import_ui_builder_utils10.logger.warn(
|
|
1933
|
-
LOG_SYSTEM,
|
|
1934
|
-
"getActiveConfigForManager: RainbowKit config failed, falling back to default."
|
|
1935
|
-
);
|
|
1936
|
-
}
|
|
1937
|
-
if (!this.defaultInstanceConfig) {
|
|
1938
|
-
this.defaultInstanceConfig = this.createDefaultConfig();
|
|
1939
|
-
}
|
|
1940
|
-
return this.defaultInstanceConfig;
|
|
1941
|
-
}
|
|
1942
|
-
/**
|
|
1943
|
-
* @deprecated Prefer using methods that rely on the externally set `activeWagmiConfig`
|
|
1944
|
-
* or methods that determine contextually appropriate config like `getActiveConfigForManager` (for manager use)
|
|
1945
|
-
* or ensure `activeWagmiConfig` is set before calling wagmi actions.
|
|
1946
|
-
* This method returns the internally cached default config or the active one if set.
|
|
1947
|
-
* @returns The current default or active Wagmi Config object.
|
|
1948
|
-
*/
|
|
1949
|
-
getConfig() {
|
|
1950
|
-
import_ui_builder_utils10.logger.warn(
|
|
1951
|
-
LOG_SYSTEM,
|
|
1952
|
-
"getConfig() is deprecated. Internal calls should use activeWagmiConfig if set, or ensure default is created."
|
|
1953
|
-
);
|
|
1954
|
-
if (this.activeWagmiConfig) return this.activeWagmiConfig;
|
|
1955
|
-
if (!this.defaultInstanceConfig) {
|
|
1956
|
-
this.defaultInstanceConfig = this.createDefaultConfig();
|
|
1957
|
-
}
|
|
1958
|
-
return this.defaultInstanceConfig;
|
|
1959
|
-
}
|
|
1960
|
-
/**
|
|
1961
|
-
* Gets the current wallet connection status (isConnected, address, chainId, etc.).
|
|
1962
|
-
* This is a synchronous operation and uses the `activeWagmiConfig` if set by `EvmUiKitManager`,
|
|
1963
|
-
* otherwise falls back to the default instance config (created on demand).
|
|
1964
|
-
* For UI reactivity to connection changes, `onWalletConnectionChange` or derived hooks are preferred.
|
|
1965
|
-
* @returns The current account status from Wagmi.
|
|
1966
|
-
*/
|
|
1967
|
-
getWalletConnectionStatus() {
|
|
1968
|
-
import_ui_builder_utils10.logger.debug(LOG_SYSTEM, "getWalletConnectionStatus called.");
|
|
1969
|
-
const configToUse = this.activeWagmiConfig || this.defaultInstanceConfig || (this.defaultInstanceConfig = this.createDefaultConfig());
|
|
1970
|
-
if (!configToUse) {
|
|
1971
|
-
import_ui_builder_utils10.logger.error(LOG_SYSTEM, "No config available for getWalletConnectionStatus!");
|
|
1972
|
-
return {
|
|
1973
|
-
isConnected: false,
|
|
1974
|
-
isConnecting: false,
|
|
1975
|
-
isDisconnected: true,
|
|
1976
|
-
isReconnecting: false,
|
|
1977
|
-
status: "disconnected",
|
|
1978
|
-
address: void 0,
|
|
1979
|
-
addresses: void 0,
|
|
1980
|
-
chainId: void 0,
|
|
1981
|
-
chain: void 0,
|
|
1982
|
-
connector: void 0
|
|
1983
|
-
};
|
|
1984
|
-
}
|
|
1985
|
-
return (0, import_core2.getAccount)(configToUse);
|
|
1986
|
-
}
|
|
1987
|
-
/**
|
|
1988
|
-
* Subscribes to account and connection status changes from Wagmi.
|
|
1989
|
-
* The subscription is bound to the `activeWagmiConfig` if available at the time of call,
|
|
1990
|
-
* otherwise to the default instance config. If `activeWagmiConfig` changes later,
|
|
1991
|
-
* this specific subscription might become stale (see warning in `setActiveWagmiConfig`).
|
|
1992
|
-
* @param callback - Function to call when connection status changes.
|
|
1993
|
-
* @returns A function to unsubscribe from the changes.
|
|
1994
|
-
*/
|
|
1995
|
-
onWalletConnectionChange(callback) {
|
|
1996
|
-
if (!this.initialized) {
|
|
1997
|
-
import_ui_builder_utils10.logger.warn(LOG_SYSTEM, "onWalletConnectionChange called before initialization. No-op.");
|
|
1998
|
-
return () => {
|
|
1999
|
-
};
|
|
2000
|
-
}
|
|
2001
|
-
if (this.unsubscribe) {
|
|
2002
|
-
this.unsubscribe();
|
|
2003
|
-
import_ui_builder_utils10.logger.debug(LOG_SYSTEM, "Previous watchAccount unsubscribed.");
|
|
2004
|
-
}
|
|
2005
|
-
const configToUse = this.activeWagmiConfig || this.defaultInstanceConfig || (this.defaultInstanceConfig = this.createDefaultConfig());
|
|
2006
|
-
if (!configToUse) {
|
|
2007
|
-
import_ui_builder_utils10.logger.error(
|
|
2008
|
-
LOG_SYSTEM,
|
|
2009
|
-
"No config available for onWalletConnectionChange! Subscription not set."
|
|
2010
|
-
);
|
|
2011
|
-
return () => {
|
|
2012
|
-
};
|
|
2013
|
-
}
|
|
2014
|
-
this.unsubscribe = (0, import_core2.watchAccount)(configToUse, { onChange: callback });
|
|
2015
|
-
import_ui_builder_utils10.logger.info(
|
|
2516
|
+
__publicField(this, "walletConnectProjectId");
|
|
2517
|
+
this.walletConnectProjectId = walletConnectProjectIdFromAppConfig;
|
|
2518
|
+
import_ui_builder_utils15.logger.info(
|
|
2016
2519
|
LOG_SYSTEM,
|
|
2017
|
-
"
|
|
2018
|
-
|
|
2520
|
+
"Constructor called. Initial anticipated kitName:",
|
|
2521
|
+
initialUiKitConfig?.kitName
|
|
2522
|
+
);
|
|
2523
|
+
this.initialized = true;
|
|
2524
|
+
import_ui_builder_utils15.logger.info(
|
|
2525
|
+
LOG_SYSTEM,
|
|
2526
|
+
"WagmiWalletImplementation instance initialized (Wagmi config creation deferred)."
|
|
2019
2527
|
);
|
|
2020
|
-
return this.unsubscribe;
|
|
2021
2528
|
}
|
|
2022
|
-
// Methods that perform actions should use the most current activeWagmiConfig
|
|
2023
2529
|
/**
|
|
2024
|
-
*
|
|
2025
|
-
*
|
|
2530
|
+
* Sets the externally determined, currently active WagmiConfig instance.
|
|
2531
|
+
* This is typically called by EvmUiKitManager after it has resolved the appropriate
|
|
2532
|
+
* config for the selected UI kit (e.g., RainbowKit's config or a default custom config).
|
|
2533
|
+
* @param config - The Wagmi Config object to set as active, or null to clear it.
|
|
2026
2534
|
*/
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2535
|
+
setActiveWagmiConfig(config) {
|
|
2536
|
+
import_ui_builder_utils15.logger.info(
|
|
2537
|
+
LOG_SYSTEM,
|
|
2538
|
+
"setActiveWagmiConfig called with config:",
|
|
2539
|
+
config ? "Valid Config" : "Null"
|
|
2540
|
+
);
|
|
2541
|
+
this.activeWagmiConfig = config;
|
|
2542
|
+
if (this.unsubscribe) {
|
|
2543
|
+
import_ui_builder_utils15.logger.warn(
|
|
2030
2544
|
LOG_SYSTEM,
|
|
2031
|
-
"
|
|
2545
|
+
"setActiveWagmiConfig: Active WagmiConfig instance has changed. Existing direct watchAccount subscription (via onWalletConnectionChange) may be stale and operating on an old config instance."
|
|
2032
2546
|
);
|
|
2033
|
-
return null;
|
|
2034
2547
|
}
|
|
2035
|
-
const accountStatus = (0, import_core2.getAccount)(this.activeWagmiConfig);
|
|
2036
|
-
if (!accountStatus.isConnected || !accountStatus.chainId || !accountStatus.address) return null;
|
|
2037
|
-
return (0, import_core2.getWalletClient)(this.activeWagmiConfig, {
|
|
2038
|
-
chainId: accountStatus.chainId,
|
|
2039
|
-
account: accountStatus.address
|
|
2040
|
-
});
|
|
2041
2548
|
}
|
|
2042
2549
|
/**
|
|
2043
|
-
*
|
|
2044
|
-
*
|
|
2045
|
-
*
|
|
2046
|
-
*
|
|
2550
|
+
* Creates a default WagmiConfig instance on demand.
|
|
2551
|
+
* This configuration includes standard connectors (injected, MetaMask, Safe)
|
|
2552
|
+
* and WalletConnect if a project ID is available.
|
|
2553
|
+
* Used as a fallback or for 'custom' UI kit mode.
|
|
2554
|
+
* @returns A Wagmi Config object.
|
|
2047
2555
|
*/
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
}
|
|
2056
|
-
const accountStatus = (0, import_core2.getAccount)(this.activeWagmiConfig);
|
|
2057
|
-
const currentChainId = accountStatus.chainId;
|
|
2058
|
-
if (!currentChainId) {
|
|
2059
|
-
import_ui_builder_utils10.logger.warn(
|
|
2556
|
+
createDefaultConfig() {
|
|
2557
|
+
const baseConnectors = [(0, import_connectors.injected)(), (0, import_connectors.metaMask)(), (0, import_connectors.safe)()];
|
|
2558
|
+
if (this.walletConnectProjectId?.trim()) {
|
|
2559
|
+
baseConnectors.push((0, import_connectors.walletConnect)({ projectId: this.walletConnectProjectId }));
|
|
2560
|
+
import_ui_builder_utils15.logger.info(LOG_SYSTEM, "WalletConnect connector added to DEFAULT config.");
|
|
2561
|
+
} else {
|
|
2562
|
+
import_ui_builder_utils15.logger.warn(
|
|
2060
2563
|
LOG_SYSTEM,
|
|
2061
|
-
"
|
|
2564
|
+
"WalletConnect Project ID not provided; WC connector unavailable for DEFAULT config."
|
|
2062
2565
|
);
|
|
2063
|
-
return null;
|
|
2064
2566
|
}
|
|
2567
|
+
const transportsConfig = defaultSupportedChains.reduce(
|
|
2568
|
+
(acc, chainDefinition) => {
|
|
2569
|
+
let rpcUrlToUse = chainDefinition.rpcUrls.default?.http?.[0];
|
|
2570
|
+
const appNetworkIdString = viemChainIdToAppNetworkId[chainDefinition.id];
|
|
2571
|
+
if (appNetworkIdString) {
|
|
2572
|
+
let httpRpcOverride = getUserRpcUrl(appNetworkIdString);
|
|
2573
|
+
if (!httpRpcOverride) {
|
|
2574
|
+
const rpcOverrideSetting = import_ui_builder_utils15.appConfigService.getRpcEndpointOverride(appNetworkIdString);
|
|
2575
|
+
if (typeof rpcOverrideSetting === "string") {
|
|
2576
|
+
httpRpcOverride = rpcOverrideSetting;
|
|
2577
|
+
} else if (typeof rpcOverrideSetting === "object") {
|
|
2578
|
+
if ("http" in rpcOverrideSetting && rpcOverrideSetting.http) {
|
|
2579
|
+
httpRpcOverride = rpcOverrideSetting.http;
|
|
2580
|
+
} else if ("url" in rpcOverrideSetting && rpcOverrideSetting.url) {
|
|
2581
|
+
httpRpcOverride = rpcOverrideSetting.url;
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
if (httpRpcOverride) {
|
|
2586
|
+
import_ui_builder_utils15.logger.info(
|
|
2587
|
+
LOG_SYSTEM,
|
|
2588
|
+
`Using overridden RPC for chain ${chainDefinition.name} (default config): ${httpRpcOverride}`
|
|
2589
|
+
);
|
|
2590
|
+
rpcUrlToUse = httpRpcOverride;
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
acc[chainDefinition.id] = (0, import_viem3.http)(rpcUrlToUse);
|
|
2594
|
+
return acc;
|
|
2595
|
+
},
|
|
2596
|
+
{}
|
|
2597
|
+
);
|
|
2065
2598
|
try {
|
|
2066
|
-
const
|
|
2067
|
-
|
|
2599
|
+
const defaultConfig2 = (0, import_core2.createConfig)({
|
|
2600
|
+
chains: defaultSupportedChains,
|
|
2601
|
+
connectors: baseConnectors,
|
|
2602
|
+
transports: transportsConfig
|
|
2068
2603
|
});
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
LOG_SYSTEM,
|
|
2072
|
-
`getPublicClient: Successfully retrieved public client for chainId ${currentChainId}.`
|
|
2073
|
-
);
|
|
2074
|
-
return publicClient;
|
|
2075
|
-
}
|
|
2076
|
-
import_ui_builder_utils10.logger.warn(
|
|
2077
|
-
LOG_SYSTEM,
|
|
2078
|
-
`getPublicClient: getWagmiCorePublicClient returned undefined/null for chainId ${currentChainId}.`
|
|
2079
|
-
);
|
|
2080
|
-
return null;
|
|
2604
|
+
import_ui_builder_utils15.logger.info(LOG_SYSTEM, "Default Wagmi config created successfully on demand.");
|
|
2605
|
+
return defaultConfig2;
|
|
2081
2606
|
} catch (error) {
|
|
2082
|
-
|
|
2083
|
-
return
|
|
2607
|
+
import_ui_builder_utils15.logger.error(LOG_SYSTEM, "Error creating default Wagmi config on demand:", error);
|
|
2608
|
+
return (0, import_core2.createConfig)({
|
|
2609
|
+
chains: [defaultSupportedChains[0]],
|
|
2610
|
+
connectors: [(0, import_connectors.injected)()],
|
|
2611
|
+
transports: { [defaultSupportedChains[0].id]: (0, import_viem3.http)() }
|
|
2612
|
+
});
|
|
2084
2613
|
}
|
|
2085
2614
|
}
|
|
2086
2615
|
/**
|
|
2087
|
-
*
|
|
2088
|
-
* @
|
|
2089
|
-
|
|
2090
|
-
async getAvailableConnectors() {
|
|
2091
|
-
if (!this.initialized || !this.activeWagmiConfig) return [];
|
|
2092
|
-
return this.activeWagmiConfig.connectors.map((co) => ({ id: co.uid, name: co.name }));
|
|
2093
|
-
}
|
|
2094
|
-
/**
|
|
2095
|
-
* Initiates the connection process for a specific connector using the active Wagmi config.
|
|
2096
|
-
* @param connectorId - The ID of the connector to use.
|
|
2097
|
-
* @returns A Promise with connection result including address and chainId if successful.
|
|
2098
|
-
*/
|
|
2099
|
-
async connect(connectorId) {
|
|
2100
|
-
if (!this.initialized || !this.activeWagmiConfig)
|
|
2101
|
-
throw new Error("Wallet not initialized or no active config");
|
|
2102
|
-
const connectorToUse = this.activeWagmiConfig.connectors.find(
|
|
2103
|
-
(cn6) => cn6.id === connectorId || cn6.uid === connectorId
|
|
2104
|
-
);
|
|
2105
|
-
if (!connectorToUse) throw new Error(`Connector ${connectorId} not found`);
|
|
2106
|
-
const res = await (0, import_core2.connect)(this.activeWagmiConfig, { connector: connectorToUse });
|
|
2107
|
-
return { connected: true, address: res.accounts[0], chainId: res.chainId };
|
|
2108
|
-
}
|
|
2109
|
-
/**
|
|
2110
|
-
* Disconnects the currently connected wallet using the active Wagmi config.
|
|
2111
|
-
* @returns A Promise with disconnection result.
|
|
2112
|
-
*/
|
|
2113
|
-
async disconnect() {
|
|
2114
|
-
if (!this.initialized || !this.activeWagmiConfig)
|
|
2115
|
-
return { disconnected: false, error: "Wallet not initialized or no active config" };
|
|
2116
|
-
await (0, import_core2.disconnect)(this.activeWagmiConfig);
|
|
2117
|
-
return { disconnected: true };
|
|
2118
|
-
}
|
|
2119
|
-
/**
|
|
2120
|
-
* Prompts the user to switch to the specified network using the active Wagmi config.
|
|
2121
|
-
* @param chainId - The target chain ID to switch to.
|
|
2122
|
-
* @returns A Promise that resolves if the switch is successful, or rejects with an error.
|
|
2616
|
+
* Wrapper function to convert AppConfigService RPC overrides to the format expected by RainbowKit.
|
|
2617
|
+
* @param networkId - The network ID to get RPC override for
|
|
2618
|
+
* @returns RPC configuration in the format expected by RainbowKit
|
|
2123
2619
|
*/
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
}
|
|
2129
|
-
// ... (rest of class, ensure all wagmi/core actions use this.activeWagmiConfig if available and appropriate)
|
|
2130
|
-
};
|
|
2131
|
-
|
|
2132
|
-
// src/wallet/utils/walletImplementationManager.ts
|
|
2133
|
-
var walletImplementationInstance;
|
|
2134
|
-
var walletImplementationPromise;
|
|
2135
|
-
var LOG_SYSTEM2 = "EvmWalletImplementationManager";
|
|
2136
|
-
async function getEvmWalletImplementation() {
|
|
2137
|
-
if (walletImplementationInstance) {
|
|
2138
|
-
return walletImplementationInstance;
|
|
2139
|
-
}
|
|
2140
|
-
if (walletImplementationPromise) {
|
|
2141
|
-
return walletImplementationPromise;
|
|
2142
|
-
}
|
|
2143
|
-
walletImplementationPromise = (async () => {
|
|
2144
|
-
try {
|
|
2145
|
-
import_ui_builder_utils11.logger.info(LOG_SYSTEM2, "Initializing WagmiWalletImplementation singleton (async)... ");
|
|
2146
|
-
const initialUiKitConfig = import_ui_builder_utils11.appConfigService.getTypedNestedConfig(
|
|
2147
|
-
"walletui",
|
|
2148
|
-
"config"
|
|
2149
|
-
);
|
|
2150
|
-
const wcProjectId = import_ui_builder_utils11.appConfigService.getGlobalServiceParam("walletconnect", "projectId");
|
|
2151
|
-
const instance = new WagmiWalletImplementation(wcProjectId, initialUiKitConfig);
|
|
2152
|
-
import_ui_builder_utils11.logger.info(LOG_SYSTEM2, "WagmiWalletImplementation singleton created (async).");
|
|
2153
|
-
walletImplementationInstance = instance;
|
|
2154
|
-
return instance;
|
|
2155
|
-
} catch (error) {
|
|
2156
|
-
import_ui_builder_utils11.logger.error(LOG_SYSTEM2, "Failed to initialize WagmiWalletImplementation (async):", error);
|
|
2157
|
-
const fallbackInstance = new WagmiWalletImplementation();
|
|
2158
|
-
walletImplementationInstance = fallbackInstance;
|
|
2159
|
-
return fallbackInstance;
|
|
2160
|
-
}
|
|
2161
|
-
})();
|
|
2162
|
-
return walletImplementationPromise;
|
|
2163
|
-
}
|
|
2164
|
-
function getInitializedEvmWalletImplementation() {
|
|
2165
|
-
if (!walletImplementationInstance) {
|
|
2166
|
-
import_ui_builder_utils11.logger.warn(
|
|
2167
|
-
LOG_SYSTEM2,
|
|
2168
|
-
"getInitializedEvmWalletImplementation called before instance was ready."
|
|
2169
|
-
);
|
|
2170
|
-
}
|
|
2171
|
-
return walletImplementationInstance;
|
|
2172
|
-
}
|
|
2173
|
-
|
|
2174
|
-
// src/wallet/evmUiKitManager.ts
|
|
2175
|
-
var initialState = {
|
|
2176
|
-
currentFullUiKitConfig: null,
|
|
2177
|
-
wagmiConfig: null,
|
|
2178
|
-
kitProviderComponent: null,
|
|
2179
|
-
isKitAssetsLoaded: false,
|
|
2180
|
-
isInitializing: false,
|
|
2181
|
-
error: null
|
|
2182
|
-
};
|
|
2183
|
-
var state = { ...initialState };
|
|
2184
|
-
var listeners = /* @__PURE__ */ new Set();
|
|
2185
|
-
function notifyListeners() {
|
|
2186
|
-
listeners.forEach((listener) => {
|
|
2187
|
-
try {
|
|
2188
|
-
listener();
|
|
2189
|
-
} catch (error) {
|
|
2190
|
-
import_ui_builder_utils13.logger.error("EvmUiKitManager", "Error in listener:", error);
|
|
2620
|
+
getRpcOverrideForRainbowKit(networkId) {
|
|
2621
|
+
const userRpcUrl = getUserRpcUrl(networkId);
|
|
2622
|
+
if (userRpcUrl) {
|
|
2623
|
+
return { http: userRpcUrl };
|
|
2191
2624
|
}
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
}
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
const newKitName = newFullUiKitConfig.kitName;
|
|
2207
|
-
const kitChanged = oldKitName !== newKitName;
|
|
2208
|
-
state = {
|
|
2209
|
-
...state,
|
|
2210
|
-
isInitializing: true,
|
|
2211
|
-
error: null,
|
|
2212
|
-
currentFullUiKitConfig: newFullUiKitConfig,
|
|
2213
|
-
kitProviderComponent: kitChanged ? null : state.kitProviderComponent,
|
|
2214
|
-
isKitAssetsLoaded: kitChanged ? false : state.isKitAssetsLoaded
|
|
2215
|
-
};
|
|
2216
|
-
notifyListeners();
|
|
2217
|
-
let newWagmiConfigAttempt = null;
|
|
2218
|
-
const evmImpl = await getEvmWalletImplementation();
|
|
2219
|
-
try {
|
|
2220
|
-
if (newKitName === "rainbowkit") {
|
|
2221
|
-
if (kitChanged || !state.kitProviderComponent || !state.isKitAssetsLoaded) {
|
|
2222
|
-
import_ui_builder_utils13.logger.info("EvmUiKitManager:configure", "Ensuring RainbowKit assets are loaded...");
|
|
2223
|
-
const { ensureRainbowKitAssetsLoaded: ensureRainbowKitAssetsLoaded2 } = await Promise.resolve().then(() => (init_rainbowkitAssetManager(), rainbowkitAssetManager_exports));
|
|
2224
|
-
const rkAssets = await ensureRainbowKitAssetsLoaded2();
|
|
2225
|
-
state.kitProviderComponent = rkAssets.ProviderComponent;
|
|
2226
|
-
state.isKitAssetsLoaded = rkAssets.cssLoaded && !!rkAssets.ProviderComponent;
|
|
2227
|
-
if (!state.isKitAssetsLoaded) {
|
|
2228
|
-
throw new Error("Failed to load critical RainbowKit assets.");
|
|
2229
|
-
}
|
|
2230
|
-
}
|
|
2231
|
-
newWagmiConfigAttempt = await evmImpl.getConfigForRainbowKit(newFullUiKitConfig);
|
|
2232
|
-
import_ui_builder_utils13.logger.info("EvmUiKitManager:configure", "WagmiConfig for RainbowKit obtained.");
|
|
2233
|
-
} else if (newKitName === "custom" || !newKitName) {
|
|
2234
|
-
newWagmiConfigAttempt = await evmImpl.getActiveConfigForManager(newFullUiKitConfig);
|
|
2235
|
-
import_ui_builder_utils13.logger.info("EvmUiKitManager:configure", "ActiveConfig for custom/default obtained.");
|
|
2236
|
-
if (kitChanged) {
|
|
2237
|
-
state.kitProviderComponent = null;
|
|
2238
|
-
state.isKitAssetsLoaded = false;
|
|
2625
|
+
const rpcOverrideSetting = import_ui_builder_utils15.appConfigService.getRpcEndpointOverride(networkId);
|
|
2626
|
+
if (typeof rpcOverrideSetting === "string") {
|
|
2627
|
+
return rpcOverrideSetting;
|
|
2628
|
+
} else if (typeof rpcOverrideSetting === "object" && rpcOverrideSetting !== null) {
|
|
2629
|
+
if ("url" in rpcOverrideSetting && typeof rpcOverrideSetting.url === "string") {
|
|
2630
|
+
return {
|
|
2631
|
+
http: rpcOverrideSetting.url
|
|
2632
|
+
};
|
|
2633
|
+
} else if ("http" in rpcOverrideSetting || "ws" in rpcOverrideSetting) {
|
|
2634
|
+
const config = rpcOverrideSetting;
|
|
2635
|
+
return {
|
|
2636
|
+
http: config.http,
|
|
2637
|
+
ws: config.ws
|
|
2638
|
+
};
|
|
2239
2639
|
}
|
|
2240
|
-
} else {
|
|
2241
|
-
import_ui_builder_utils13.logger.warn("EvmUiKitManager:configure", `Unsupported kitName: ${newKitName}.`);
|
|
2242
|
-
state.kitProviderComponent = null;
|
|
2243
|
-
state.isKitAssetsLoaded = false;
|
|
2244
|
-
}
|
|
2245
|
-
state.wagmiConfig = newWagmiConfigAttempt;
|
|
2246
|
-
evmImpl.setActiveWagmiConfig(state.wagmiConfig);
|
|
2247
|
-
state.error = null;
|
|
2248
|
-
if (!newWagmiConfigAttempt && newKitName && newKitName !== "none" && newKitName !== "custom") {
|
|
2249
|
-
state.error = new Error(`Failed to obtain WagmiConfig for ${newKitName}`);
|
|
2250
|
-
import_ui_builder_utils13.logger.error("EvmUiKitManager:configure", state.error.message);
|
|
2251
2640
|
}
|
|
2252
|
-
|
|
2253
|
-
import_ui_builder_utils13.logger.error("EvmUiKitManager:configure", "Error during UI kit configuration process:", err);
|
|
2254
|
-
state.error = err instanceof Error ? err : new Error(String(err));
|
|
2255
|
-
state.wagmiConfig = null;
|
|
2256
|
-
evmImpl.setActiveWagmiConfig(null);
|
|
2257
|
-
} finally {
|
|
2258
|
-
state.isInitializing = false;
|
|
2259
|
-
import_ui_builder_utils13.logger.info(
|
|
2260
|
-
"EvmUiKitManager:configure",
|
|
2261
|
-
"Configuration attempt finished. Final wagmiConfig:",
|
|
2262
|
-
state.wagmiConfig ? "Set" : "Null",
|
|
2263
|
-
"Kit Provider Component:",
|
|
2264
|
-
state.kitProviderComponent ? "Set" : "Null",
|
|
2265
|
-
"Kit Assets Loaded:",
|
|
2266
|
-
state.isKitAssetsLoaded,
|
|
2267
|
-
"Error state:",
|
|
2268
|
-
state.error ? state.error.message : "None"
|
|
2269
|
-
);
|
|
2270
|
-
notifyListeners();
|
|
2271
|
-
}
|
|
2272
|
-
}
|
|
2273
|
-
var evmUiKitManager = {
|
|
2274
|
-
getState,
|
|
2275
|
-
subscribe,
|
|
2276
|
-
configure
|
|
2277
|
-
};
|
|
2278
|
-
|
|
2279
|
-
// src/wallet/components/EvmWalletUiRoot.tsx
|
|
2280
|
-
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
2281
|
-
var stableQueryClient = new import_react_query.QueryClient();
|
|
2282
|
-
var minimalDefaultWagmiConfig = (0, import_core3.createConfig)({
|
|
2283
|
-
chains: [import_chains3.mainnet],
|
|
2284
|
-
// At least one chain is required in wagmi v2.20+
|
|
2285
|
-
connectors: [],
|
|
2286
|
-
// Empty connectors array
|
|
2287
|
-
transports: {
|
|
2288
|
-
[import_chains3.mainnet.id]: (0, import_core3.http)()
|
|
2289
|
-
// Basic HTTP transport for the default chain
|
|
2641
|
+
return void 0;
|
|
2290
2642
|
}
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
const DynKitProvider = kitProviderComponent;
|
|
2318
|
-
const kitConfig = currentFullUiKitConfig.kitConfig || {};
|
|
2319
|
-
const providerProps = kitConfig.providerProps || {};
|
|
2320
|
-
import_ui_builder_utils14.logger.info(
|
|
2321
|
-
"EvmWalletUiRoot",
|
|
2322
|
-
"Wrapping children with dynamically loaded KitProvider (RainbowKit)."
|
|
2643
|
+
/**
|
|
2644
|
+
* Retrieves or creates the WagmiConfig specifically for RainbowKit.
|
|
2645
|
+
* This delegates to `getWagmiConfigForRainbowKit` service which handles caching
|
|
2646
|
+
* and uses RainbowKit's `getDefaultConfig`.
|
|
2647
|
+
* @param currentAdapterUiKitConfig - The fully resolved UI kit configuration for the adapter.
|
|
2648
|
+
* @returns A Promise resolving to the RainbowKit-specific Wagmi Config object, or null if creation fails or not RainbowKit.
|
|
2649
|
+
*/
|
|
2650
|
+
async getConfigForRainbowKit(currentAdapterUiKitConfig) {
|
|
2651
|
+
if (!this.initialized) {
|
|
2652
|
+
import_ui_builder_utils15.logger.error(
|
|
2653
|
+
LOG_SYSTEM,
|
|
2654
|
+
"getConfigForRainbowKit called before implementation initialization."
|
|
2655
|
+
);
|
|
2656
|
+
return null;
|
|
2657
|
+
}
|
|
2658
|
+
if (currentAdapterUiKitConfig?.kitName !== "rainbowkit") {
|
|
2659
|
+
import_ui_builder_utils15.logger.warn(
|
|
2660
|
+
LOG_SYSTEM,
|
|
2661
|
+
"getConfigForRainbowKit called, but kitName is not rainbowkit. Returning null."
|
|
2662
|
+
);
|
|
2663
|
+
return null;
|
|
2664
|
+
}
|
|
2665
|
+
import_ui_builder_utils15.logger.info(
|
|
2666
|
+
LOG_SYSTEM,
|
|
2667
|
+
"getConfigForRainbowKit: Kit is RainbowKit. Proceeding to create/get config. CurrentAdapterUiKitConfig:",
|
|
2668
|
+
currentAdapterUiKitConfig
|
|
2323
2669
|
);
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2670
|
+
const rainbowKitWagmiConfig = await getWagmiConfigForRainbowKit(
|
|
2671
|
+
currentAdapterUiKitConfig,
|
|
2672
|
+
defaultSupportedChains,
|
|
2673
|
+
viemChainIdToAppNetworkId,
|
|
2674
|
+
this.getRpcOverrideForRainbowKit.bind(this)
|
|
2329
2675
|
);
|
|
2676
|
+
if (rainbowKitWagmiConfig) {
|
|
2677
|
+
import_ui_builder_utils15.logger.info(LOG_SYSTEM, "Returning RainbowKit-specific Wagmi config for provider.");
|
|
2678
|
+
return rainbowKitWagmiConfig;
|
|
2679
|
+
}
|
|
2680
|
+
import_ui_builder_utils15.logger.warn(LOG_SYSTEM, "RainbowKit specific Wagmi config creation failed.");
|
|
2681
|
+
return null;
|
|
2330
2682
|
}
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
children: [
|
|
2360
|
-
"Error initializing wallet provider: ",
|
|
2361
|
-
error.message
|
|
2362
|
-
]
|
|
2363
|
-
}
|
|
2364
|
-
)
|
|
2365
|
-
] }) }) });
|
|
2366
|
-
};
|
|
2367
|
-
|
|
2368
|
-
// src/wallet/hooks/facade-hooks.ts
|
|
2369
|
-
var import_wagmi2 = require("wagmi");
|
|
2370
|
-
var evmFacadeHooks = {
|
|
2371
|
-
useAccount: import_wagmi2.useAccount,
|
|
2372
|
-
useConnect: import_wagmi2.useConnect,
|
|
2373
|
-
useDisconnect: import_wagmi2.useDisconnect,
|
|
2374
|
-
useSwitchChain: import_wagmi2.useSwitchChain,
|
|
2375
|
-
useChainId: import_wagmi2.useChainId,
|
|
2376
|
-
useChains: import_wagmi2.useChains,
|
|
2377
|
-
useBalance: import_wagmi2.useBalance,
|
|
2378
|
-
useSendTransaction: import_wagmi2.useSendTransaction,
|
|
2379
|
-
useWaitForTransactionReceipt: import_wagmi2.useWaitForTransactionReceipt,
|
|
2380
|
-
useSignMessage: import_wagmi2.useSignMessage,
|
|
2381
|
-
useSignTypedData: import_wagmi2.useSignTypedData
|
|
2382
|
-
};
|
|
2383
|
-
|
|
2384
|
-
// src/wallet/rainbowkit/config-generator.ts
|
|
2385
|
-
function generateRainbowKitConfigFile(userConfig) {
|
|
2386
|
-
const config = userConfig || {};
|
|
2387
|
-
const appName = config.appName || "My RainbowKit App";
|
|
2388
|
-
const learnMoreUrl = config.learnMoreUrl || "https://openzeppelin.com";
|
|
2389
|
-
const projectId = config.projectId || "YOUR_PROJECT_ID";
|
|
2390
|
-
const appInfoLines = [`appName: '${appName}'`];
|
|
2391
|
-
if (learnMoreUrl) {
|
|
2392
|
-
appInfoLines.push(`learnMoreUrl: '${learnMoreUrl}'`);
|
|
2393
|
-
}
|
|
2394
|
-
const appInfoContent = appInfoLines.join(",\n ");
|
|
2395
|
-
const fileContent = `// RainbowKit configuration for your exported application
|
|
2396
|
-
// This file is used ONLY in the exported app, not in the builder app preview
|
|
2397
|
-
|
|
2398
|
-
// Uncomment imports as needed:
|
|
2399
|
-
// import { darkTheme, lightTheme } from '@rainbow-me/rainbowkit';
|
|
2400
|
-
|
|
2401
|
-
const rainbowKitAppConfig = {
|
|
2402
|
-
wagmiParams: {
|
|
2403
|
-
appName: '${appName}',
|
|
2404
|
-
projectId: '${projectId}', // Get yours at https://cloud.walletconnect.com
|
|
2405
|
-
|
|
2406
|
-
// Additional options:
|
|
2407
|
-
// ssr: true,
|
|
2408
|
-
// wallets: [...],
|
|
2409
|
-
},
|
|
2410
|
-
providerProps: {
|
|
2411
|
-
appInfo: {
|
|
2412
|
-
${appInfoContent}
|
|
2413
|
-
},
|
|
2414
|
-
|
|
2415
|
-
// UI customization - all features work in exported apps:
|
|
2416
|
-
// theme: darkTheme(),
|
|
2417
|
-
// modalSize: 'compact',
|
|
2418
|
-
// showRecentTransactions: true,
|
|
2419
|
-
// coolMode: true,
|
|
2420
|
-
},
|
|
2421
|
-
};
|
|
2422
|
-
|
|
2423
|
-
export default rainbowKitAppConfig;`;
|
|
2424
|
-
return fileContent;
|
|
2425
|
-
}
|
|
2426
|
-
|
|
2427
|
-
// src/wallet/rainbowkit/export-service.ts
|
|
2428
|
-
function generateRainbowKitExportables(uiKitConfig2) {
|
|
2429
|
-
const filePath = "src/config/wallet/rainbowkit.config.ts";
|
|
2430
|
-
const content = uiKitConfig2.customCode || generateRainbowKitConfigFile(uiKitConfig2.kitConfig);
|
|
2431
|
-
return { [filePath]: content };
|
|
2432
|
-
}
|
|
2433
|
-
|
|
2434
|
-
// src/wallet/services/configResolutionService.ts
|
|
2435
|
-
var import_ui_builder_utils18 = require("@openzeppelin/ui-builder-utils");
|
|
2436
|
-
|
|
2437
|
-
// src/wallet/utils.ts
|
|
2438
|
-
var import_ui_builder_utils17 = require("@openzeppelin/ui-builder-utils");
|
|
2439
|
-
|
|
2440
|
-
// src/wallet/utils/uiKitService.ts
|
|
2441
|
-
var import_ui_builder_utils16 = require("@openzeppelin/ui-builder-utils");
|
|
2442
|
-
|
|
2443
|
-
// src/wallet/utils/filterWalletComponents.ts
|
|
2444
|
-
var import_ui_builder_types = require("@openzeppelin/ui-builder-types");
|
|
2445
|
-
var import_ui_builder_utils15 = require("@openzeppelin/ui-builder-utils");
|
|
2446
|
-
function filterWalletComponents(allPossibleComponents, exclusions, kitName = "custom") {
|
|
2447
|
-
import_ui_builder_utils15.logger.debug(
|
|
2448
|
-
"filterWalletComponents",
|
|
2449
|
-
`Filtering components for kit: ${kitName}. Exclusions: ${exclusions.join(", ")}.`
|
|
2450
|
-
);
|
|
2451
|
-
if (!allPossibleComponents || Object.keys(allPossibleComponents).length === 0) {
|
|
2452
|
-
import_ui_builder_utils15.logger.debug("filterWalletComponents", `No components provided to filter for kit: ${kitName}.`);
|
|
2453
|
-
return void 0;
|
|
2683
|
+
/**
|
|
2684
|
+
* Determines and returns the WagmiConfig to be used by EvmUiKitManager during its configuration process.
|
|
2685
|
+
* If RainbowKit is specified in the passed uiKitConfig, it attempts to get its specific config.
|
|
2686
|
+
* Otherwise, it falls back to creating/returning a default instance config.
|
|
2687
|
+
* @param uiKitConfig - The fully resolved UiKitConfiguration that the manager is currently processing.
|
|
2688
|
+
* @returns A Promise resolving to the determined Wagmi Config object.
|
|
2689
|
+
*/
|
|
2690
|
+
async getActiveConfigForManager(uiKitConfig2) {
|
|
2691
|
+
if (!this.initialized) {
|
|
2692
|
+
import_ui_builder_utils15.logger.error(
|
|
2693
|
+
LOG_SYSTEM,
|
|
2694
|
+
"getActiveConfigForManager called before initialization! Creating fallback."
|
|
2695
|
+
);
|
|
2696
|
+
return (0, import_core2.createConfig)({
|
|
2697
|
+
chains: [defaultSupportedChains[0]],
|
|
2698
|
+
transports: { [defaultSupportedChains[0].id]: (0, import_viem3.http)() }
|
|
2699
|
+
});
|
|
2700
|
+
}
|
|
2701
|
+
if (uiKitConfig2?.kitName === "rainbowkit") {
|
|
2702
|
+
const rkConfig = await this.getConfigForRainbowKit(uiKitConfig2);
|
|
2703
|
+
if (rkConfig) return rkConfig;
|
|
2704
|
+
import_ui_builder_utils15.logger.warn(
|
|
2705
|
+
LOG_SYSTEM,
|
|
2706
|
+
"getActiveConfigForManager: RainbowKit config failed, falling back to default."
|
|
2707
|
+
);
|
|
2708
|
+
}
|
|
2709
|
+
this.defaultInstanceConfig = this.createDefaultConfig();
|
|
2710
|
+
return this.defaultInstanceConfig;
|
|
2454
2711
|
}
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2712
|
+
/**
|
|
2713
|
+
* @deprecated Prefer using methods that rely on the externally set `activeWagmiConfig`
|
|
2714
|
+
* or methods that determine contextually appropriate config like `getActiveConfigForManager` (for manager use)
|
|
2715
|
+
* or ensure `activeWagmiConfig` is set before calling wagmi actions.
|
|
2716
|
+
* This method returns the internally cached default config or the active one if set.
|
|
2717
|
+
* @returns The current default or active Wagmi Config object.
|
|
2718
|
+
*/
|
|
2719
|
+
getConfig() {
|
|
2720
|
+
import_ui_builder_utils15.logger.warn(
|
|
2721
|
+
LOG_SYSTEM,
|
|
2722
|
+
"getConfig() is deprecated. Internal calls should use activeWagmiConfig if set, or ensure default is created."
|
|
2460
2723
|
);
|
|
2461
|
-
return
|
|
2724
|
+
if (this.activeWagmiConfig) return this.activeWagmiConfig;
|
|
2725
|
+
if (!this.defaultInstanceConfig) {
|
|
2726
|
+
this.defaultInstanceConfig = this.createDefaultConfig();
|
|
2727
|
+
}
|
|
2728
|
+
return this.defaultInstanceConfig;
|
|
2462
2729
|
}
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2730
|
+
/**
|
|
2731
|
+
* Gets the current wallet connection status (isConnected, address, chainId, etc.).
|
|
2732
|
+
* This is a synchronous operation and uses the `activeWagmiConfig` if set by `EvmUiKitManager`,
|
|
2733
|
+
* otherwise falls back to the default instance config (created on demand).
|
|
2734
|
+
* For UI reactivity to connection changes, `onWalletConnectionChange` or derived hooks are preferred.
|
|
2735
|
+
* @returns The current account status from Wagmi.
|
|
2736
|
+
*/
|
|
2737
|
+
getWalletConnectionStatus() {
|
|
2738
|
+
import_ui_builder_utils15.logger.debug(LOG_SYSTEM, "getWalletConnectionStatus called.");
|
|
2739
|
+
const configToUse = this.activeWagmiConfig || this.defaultInstanceConfig || (this.defaultInstanceConfig = this.createDefaultConfig());
|
|
2740
|
+
if (!configToUse) {
|
|
2741
|
+
import_ui_builder_utils15.logger.error(LOG_SYSTEM, "No config available for getWalletConnectionStatus!");
|
|
2742
|
+
return {
|
|
2743
|
+
isConnected: false,
|
|
2744
|
+
isConnecting: false,
|
|
2745
|
+
isDisconnected: true,
|
|
2746
|
+
isReconnecting: false,
|
|
2747
|
+
status: "disconnected",
|
|
2748
|
+
address: void 0,
|
|
2749
|
+
addresses: void 0,
|
|
2750
|
+
chainId: void 0,
|
|
2751
|
+
chain: void 0,
|
|
2752
|
+
connector: void 0
|
|
2753
|
+
};
|
|
2472
2754
|
}
|
|
2755
|
+
return (0, import_core2.getAccount)(configToUse);
|
|
2473
2756
|
}
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2757
|
+
/**
|
|
2758
|
+
* Subscribes to account and connection status changes from Wagmi.
|
|
2759
|
+
* The subscription is bound to the `activeWagmiConfig` if available at the time of call,
|
|
2760
|
+
* otherwise to the default instance config. If `activeWagmiConfig` changes later,
|
|
2761
|
+
* this specific subscription might become stale (see warning in `setActiveWagmiConfig`).
|
|
2762
|
+
* @param callback - Function to call when connection status changes.
|
|
2763
|
+
* @returns A function to unsubscribe from the changes.
|
|
2764
|
+
*/
|
|
2765
|
+
onWalletConnectionChange(callback) {
|
|
2766
|
+
if (!this.initialized) {
|
|
2767
|
+
import_ui_builder_utils15.logger.warn(LOG_SYSTEM, "onWalletConnectionChange called before initialization. No-op.");
|
|
2768
|
+
return () => {
|
|
2769
|
+
};
|
|
2770
|
+
}
|
|
2771
|
+
if (this.unsubscribe) {
|
|
2772
|
+
this.unsubscribe();
|
|
2773
|
+
import_ui_builder_utils15.logger.debug(LOG_SYSTEM, "Previous watchAccount unsubscribed.");
|
|
2774
|
+
}
|
|
2775
|
+
const configToUse = this.activeWagmiConfig || this.defaultInstanceConfig || (this.defaultInstanceConfig = this.createDefaultConfig());
|
|
2776
|
+
if (!configToUse) {
|
|
2777
|
+
import_ui_builder_utils15.logger.error(
|
|
2778
|
+
LOG_SYSTEM,
|
|
2779
|
+
"No config available for onWalletConnectionChange! Subscription not set."
|
|
2780
|
+
);
|
|
2781
|
+
return () => {
|
|
2782
|
+
};
|
|
2783
|
+
}
|
|
2784
|
+
this.unsubscribe = (0, import_core2.watchAccount)(configToUse, { onChange: callback });
|
|
2785
|
+
import_ui_builder_utils15.logger.info(
|
|
2786
|
+
LOG_SYSTEM,
|
|
2787
|
+
"watchAccount subscription established/re-established using config:",
|
|
2788
|
+
configToUse === this.activeWagmiConfig ? "activeExternal" : "defaultInstance"
|
|
2479
2789
|
);
|
|
2480
|
-
return
|
|
2790
|
+
return this.unsubscribe;
|
|
2481
2791
|
}
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
if (
|
|
2489
|
-
|
|
2490
|
-
|
|
2792
|
+
// Methods that perform actions should use the most current activeWagmiConfig
|
|
2793
|
+
/**
|
|
2794
|
+
* Gets the Viem Wallet Client for the currently connected account and chain, using the active Wagmi config.
|
|
2795
|
+
* @returns A Promise resolving to the Viem WalletClient or null if not connected or config not active.
|
|
2796
|
+
*/
|
|
2797
|
+
async getWalletClient() {
|
|
2798
|
+
if (!this.initialized || !this.activeWagmiConfig) {
|
|
2799
|
+
import_ui_builder_utils15.logger.warn(
|
|
2800
|
+
LOG_SYSTEM,
|
|
2801
|
+
"getWalletClient: Not initialized or no activeWagmiConfig. Returning null."
|
|
2491
2802
|
);
|
|
2803
|
+
return null;
|
|
2492
2804
|
}
|
|
2805
|
+
const accountStatus = (0, import_core2.getAccount)(this.activeWagmiConfig);
|
|
2806
|
+
if (!accountStatus.isConnected || !accountStatus.chainId || !accountStatus.address) return null;
|
|
2807
|
+
return (0, import_core2.getWalletClient)(this.activeWagmiConfig, {
|
|
2808
|
+
chainId: accountStatus.chainId,
|
|
2809
|
+
account: accountStatus.address
|
|
2810
|
+
});
|
|
2493
2811
|
}
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2812
|
+
/**
|
|
2813
|
+
* Gets the Viem Public Client for the currently connected chain, using the active Wagmi config.
|
|
2814
|
+
* Note: Direct public client retrieval from WagmiConfig is complex in v2. This is a placeholder.
|
|
2815
|
+
* Prefer using Wagmi actions like readContract, simulateContract which use the public client internally.
|
|
2816
|
+
* @returns A Promise resolving to the Viem PublicClient or null.
|
|
2817
|
+
*/
|
|
2818
|
+
async getPublicClient() {
|
|
2819
|
+
if (!this.initialized || !this.activeWagmiConfig) {
|
|
2820
|
+
import_ui_builder_utils15.logger.warn(
|
|
2821
|
+
LOG_SYSTEM,
|
|
2822
|
+
"getPublicClient: Not initialized or no activeWagmiConfig. Returning null."
|
|
2823
|
+
);
|
|
2824
|
+
return null;
|
|
2825
|
+
}
|
|
2826
|
+
const accountStatus = (0, import_core2.getAccount)(this.activeWagmiConfig);
|
|
2827
|
+
const currentChainId = accountStatus.chainId;
|
|
2828
|
+
if (!currentChainId) {
|
|
2829
|
+
import_ui_builder_utils15.logger.warn(
|
|
2830
|
+
LOG_SYSTEM,
|
|
2831
|
+
"getPublicClient: No connected chainId available from accountStatus. Returning null."
|
|
2832
|
+
);
|
|
2833
|
+
return null;
|
|
2834
|
+
}
|
|
2835
|
+
try {
|
|
2836
|
+
const publicClient = (0, import_core2.getPublicClient)(this.activeWagmiConfig, {
|
|
2837
|
+
chainId: currentChainId
|
|
2838
|
+
});
|
|
2839
|
+
if (publicClient) {
|
|
2840
|
+
import_ui_builder_utils15.logger.info(
|
|
2841
|
+
LOG_SYSTEM,
|
|
2842
|
+
`getPublicClient: Successfully retrieved public client for chainId ${currentChainId}.`
|
|
2843
|
+
);
|
|
2844
|
+
return publicClient;
|
|
2845
|
+
}
|
|
2846
|
+
import_ui_builder_utils15.logger.warn(
|
|
2847
|
+
LOG_SYSTEM,
|
|
2848
|
+
`getPublicClient: getWagmiCorePublicClient returned undefined/null for chainId ${currentChainId}.`
|
|
2849
|
+
);
|
|
2850
|
+
return null;
|
|
2851
|
+
} catch (error) {
|
|
2852
|
+
import_ui_builder_utils15.logger.error(LOG_SYSTEM, "Error getting public client from wagmi/core:", error);
|
|
2853
|
+
return null;
|
|
2854
|
+
}
|
|
2855
|
+
}
|
|
2856
|
+
/**
|
|
2857
|
+
* Gets the list of available wallet connectors from the active Wagmi config.
|
|
2858
|
+
* @returns A Promise resolving to an array of available connectors.
|
|
2859
|
+
*/
|
|
2860
|
+
async getAvailableConnectors() {
|
|
2861
|
+
if (!this.initialized || !this.activeWagmiConfig) return [];
|
|
2862
|
+
return this.activeWagmiConfig.connectors.map((co) => ({ id: co.uid, name: co.name }));
|
|
2863
|
+
}
|
|
2864
|
+
/**
|
|
2865
|
+
* Initiates the connection process for a specific connector using the active Wagmi config.
|
|
2866
|
+
* @param connectorId - The ID of the connector to use.
|
|
2867
|
+
* @returns A Promise with connection result including address and chainId if successful.
|
|
2868
|
+
*/
|
|
2869
|
+
async connect(connectorId) {
|
|
2870
|
+
if (!this.initialized || !this.activeWagmiConfig)
|
|
2871
|
+
throw new Error("Wallet not initialized or no active config");
|
|
2872
|
+
const connectorToUse = this.activeWagmiConfig.connectors.find(
|
|
2873
|
+
(cn6) => cn6.id === connectorId || cn6.uid === connectorId
|
|
2509
2874
|
);
|
|
2510
|
-
|
|
2875
|
+
if (!connectorToUse) throw new Error(`Connector ${connectorId} not found`);
|
|
2876
|
+
const res = await (0, import_core2.connect)(this.activeWagmiConfig, { connector: connectorToUse });
|
|
2877
|
+
return { connected: true, address: res.accounts[0], chainId: res.chainId };
|
|
2511
2878
|
}
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
)
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
NetworkSwitcher: CustomNetworkSwitcher
|
|
2522
|
-
};
|
|
2523
|
-
return filterWalletComponents(allCustomComponents, exclusions, currentKitName);
|
|
2879
|
+
/**
|
|
2880
|
+
* Disconnects the currently connected wallet using the active Wagmi config.
|
|
2881
|
+
* @returns A Promise with disconnection result.
|
|
2882
|
+
*/
|
|
2883
|
+
async disconnect() {
|
|
2884
|
+
if (!this.initialized || !this.activeWagmiConfig)
|
|
2885
|
+
return { disconnected: false, error: "Wallet not initialized or no active config" };
|
|
2886
|
+
await (0, import_core2.disconnect)(this.activeWagmiConfig);
|
|
2887
|
+
return { disconnected: true };
|
|
2524
2888
|
}
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
}
|
|
2534
|
-
const rainbowKitComponents = createRainbowKitComponents();
|
|
2535
|
-
import_ui_builder_utils16.logger.info("uiKitService", "Providing RainbowKit components.");
|
|
2536
|
-
return filterWalletComponents(rainbowKitComponents, exclusions, currentKitName);
|
|
2889
|
+
/**
|
|
2890
|
+
* Prompts the user to switch to the specified network using the active Wagmi config.
|
|
2891
|
+
* @param chainId - The target chain ID to switch to.
|
|
2892
|
+
* @returns A Promise that resolves if the switch is successful, or rejects with an error.
|
|
2893
|
+
*/
|
|
2894
|
+
async switchNetwork(chainId) {
|
|
2895
|
+
if (!this.initialized || !this.activeWagmiConfig)
|
|
2896
|
+
throw new Error("Wallet not initialized or no active config");
|
|
2897
|
+
await (0, import_core2.switchChain)(this.activeWagmiConfig, { chainId });
|
|
2537
2898
|
}
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
`UI Kit "${currentKitName}" for getResolvedWalletComponents not explicitly supported. No components provided.`
|
|
2541
|
-
);
|
|
2542
|
-
return void 0;
|
|
2543
|
-
}
|
|
2899
|
+
// ... (rest of class, ensure all wagmi/core actions use this.activeWagmiConfig if available and appropriate)
|
|
2900
|
+
};
|
|
2544
2901
|
|
|
2545
|
-
// src/wallet/utils.ts
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
async function
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
);
|
|
2558
|
-
let userNativeConfig = null;
|
|
2559
|
-
if (kitName && kitName !== "custom" && kitName !== "none" && loadConfigModule) {
|
|
2560
|
-
const conventionalConfigPath = `./config/wallet/${kitName}.config.ts`;
|
|
2902
|
+
// src/wallet/utils/walletImplementationManager.ts
|
|
2903
|
+
var walletImplementationInstance;
|
|
2904
|
+
var walletImplementationPromise;
|
|
2905
|
+
var LOG_SYSTEM2 = "EvmWalletImplementationManager";
|
|
2906
|
+
async function getEvmWalletImplementation() {
|
|
2907
|
+
if (walletImplementationInstance) {
|
|
2908
|
+
return walletImplementationInstance;
|
|
2909
|
+
}
|
|
2910
|
+
if (walletImplementationPromise) {
|
|
2911
|
+
return walletImplementationPromise;
|
|
2912
|
+
}
|
|
2913
|
+
walletImplementationPromise = (async () => {
|
|
2561
2914
|
try {
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
"
|
|
2566
|
-
`Call to load native config for ${kitName} from ${conventionalConfigPath} failed. Error:`,
|
|
2567
|
-
error
|
|
2915
|
+
import_ui_builder_utils16.logger.info(LOG_SYSTEM2, "Initializing WagmiWalletImplementation singleton (async)... ");
|
|
2916
|
+
const initialUiKitConfig = import_ui_builder_utils16.appConfigService.getTypedNestedConfig(
|
|
2917
|
+
"walletui",
|
|
2918
|
+
"config"
|
|
2568
2919
|
);
|
|
2920
|
+
const wcProjectId = import_ui_builder_utils16.appConfigService.getGlobalServiceParam("walletconnect", "projectId");
|
|
2921
|
+
const instance = new WagmiWalletImplementation(wcProjectId, initialUiKitConfig);
|
|
2922
|
+
import_ui_builder_utils16.logger.info(LOG_SYSTEM2, "WagmiWalletImplementation singleton created (async).");
|
|
2923
|
+
walletImplementationInstance = instance;
|
|
2924
|
+
return instance;
|
|
2925
|
+
} catch (error) {
|
|
2926
|
+
import_ui_builder_utils16.logger.error(LOG_SYSTEM2, "Failed to initialize WagmiWalletImplementation (async):", error);
|
|
2927
|
+
const fallbackInstance = new WagmiWalletImplementation();
|
|
2928
|
+
walletImplementationInstance = fallbackInstance;
|
|
2929
|
+
return fallbackInstance;
|
|
2569
2930
|
}
|
|
2931
|
+
})();
|
|
2932
|
+
return walletImplementationPromise;
|
|
2933
|
+
}
|
|
2934
|
+
function getInitializedEvmWalletImplementation() {
|
|
2935
|
+
if (!walletImplementationInstance) {
|
|
2936
|
+
import_ui_builder_utils16.logger.warn(
|
|
2937
|
+
LOG_SYSTEM2,
|
|
2938
|
+
"getInitializedEvmWalletImplementation called before instance was ready."
|
|
2939
|
+
);
|
|
2570
2940
|
}
|
|
2571
|
-
|
|
2572
|
-
const mergedConfig = { ...userNativeConfig, ...programmaticKitConfig };
|
|
2573
|
-
return mergedConfig;
|
|
2574
|
-
} else if (userNativeConfig) {
|
|
2575
|
-
return userNativeConfig;
|
|
2576
|
-
} else if (programmaticKitConfig) {
|
|
2577
|
-
return programmaticKitConfig;
|
|
2578
|
-
}
|
|
2579
|
-
import_ui_builder_utils17.logger.debug(
|
|
2580
|
-
"resolveAndInitializeKitConfig",
|
|
2581
|
-
`No native or programmatic kitConfig provided for ${kitName || "none"}. Returning null.`
|
|
2582
|
-
);
|
|
2583
|
-
return null;
|
|
2941
|
+
return walletImplementationInstance;
|
|
2584
2942
|
}
|
|
2585
2943
|
|
|
2586
|
-
// src/wallet/
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2944
|
+
// src/wallet/evmUiKitManager.ts
|
|
2945
|
+
var initialState = {
|
|
2946
|
+
currentFullUiKitConfig: null,
|
|
2947
|
+
wagmiConfig: null,
|
|
2948
|
+
kitProviderComponent: null,
|
|
2949
|
+
isKitAssetsLoaded: false,
|
|
2950
|
+
isInitializing: false,
|
|
2951
|
+
error: null
|
|
2952
|
+
};
|
|
2953
|
+
var state = { ...initialState };
|
|
2954
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
2955
|
+
function notifyListeners() {
|
|
2956
|
+
listeners.forEach((listener) => {
|
|
2957
|
+
try {
|
|
2958
|
+
listener();
|
|
2959
|
+
} catch (error) {
|
|
2960
|
+
import_ui_builder_utils18.logger.error("EvmUiKitManager", "Error in listener:", error);
|
|
2597
2961
|
}
|
|
2598
|
-
);
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
);
|
|
2605
|
-
const finalFullConfig = {
|
|
2606
|
-
kitName: effectiveKitName,
|
|
2607
|
-
kitConfig: {
|
|
2608
|
-
...currentAppServiceConfig.kitConfig || {},
|
|
2609
|
-
...resolvedUserNativeAndProgrammaticKitConfig || {}
|
|
2610
|
-
// customCode is NOT applied to runtime config
|
|
2611
|
-
},
|
|
2612
|
-
// Pass through customCode for export purposes only
|
|
2613
|
-
customCode: programmaticOverrides.customCode
|
|
2962
|
+
});
|
|
2963
|
+
}
|
|
2964
|
+
function subscribe(listener) {
|
|
2965
|
+
listeners.add(listener);
|
|
2966
|
+
return () => {
|
|
2967
|
+
listeners.delete(listener);
|
|
2614
2968
|
};
|
|
2615
|
-
import_ui_builder_utils18.logger.debug(
|
|
2616
|
-
"configResolutionService:resolveFullUiKitConfiguration",
|
|
2617
|
-
"Resolved finalFullConfig:",
|
|
2618
|
-
finalFullConfig
|
|
2619
|
-
);
|
|
2620
|
-
return finalFullConfig;
|
|
2621
2969
|
}
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2970
|
+
function getState() {
|
|
2971
|
+
return { ...state };
|
|
2972
|
+
}
|
|
2973
|
+
async function configure(newFullUiKitConfig) {
|
|
2974
|
+
import_ui_builder_utils18.logger.info("EvmUiKitManager:configure", "Configuring UI kit. New config:", newFullUiKitConfig);
|
|
2975
|
+
const oldKitName = state.currentFullUiKitConfig?.kitName;
|
|
2976
|
+
const newKitName = newFullUiKitConfig.kitName;
|
|
2977
|
+
const kitChanged = oldKitName !== newKitName;
|
|
2978
|
+
state = {
|
|
2979
|
+
...state,
|
|
2980
|
+
isInitializing: true,
|
|
2981
|
+
error: null,
|
|
2982
|
+
currentFullUiKitConfig: newFullUiKitConfig,
|
|
2983
|
+
kitProviderComponent: kitChanged ? null : state.kitProviderComponent,
|
|
2984
|
+
isKitAssetsLoaded: kitChanged ? false : state.isKitAssetsLoaded
|
|
2985
|
+
};
|
|
2986
|
+
notifyListeners();
|
|
2987
|
+
let newWagmiConfigAttempt = null;
|
|
2988
|
+
const evmImpl = await getEvmWalletImplementation();
|
|
2989
|
+
try {
|
|
2990
|
+
if (newKitName === "rainbowkit") {
|
|
2991
|
+
if (kitChanged || !state.kitProviderComponent || !state.isKitAssetsLoaded) {
|
|
2992
|
+
import_ui_builder_utils18.logger.info("EvmUiKitManager:configure", "Ensuring RainbowKit assets are loaded...");
|
|
2993
|
+
const { ensureRainbowKitAssetsLoaded: ensureRainbowKitAssetsLoaded2 } = await Promise.resolve().then(() => (init_rainbowkitAssetManager(), rainbowkitAssetManager_exports));
|
|
2994
|
+
const rkAssets = await ensureRainbowKitAssetsLoaded2();
|
|
2995
|
+
state.kitProviderComponent = rkAssets.ProviderComponent;
|
|
2996
|
+
state.isKitAssetsLoaded = rkAssets.cssLoaded && !!rkAssets.ProviderComponent;
|
|
2997
|
+
if (!state.isKitAssetsLoaded) {
|
|
2998
|
+
throw new Error("Failed to load critical RainbowKit assets.");
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
newWagmiConfigAttempt = await evmImpl.getConfigForRainbowKit(newFullUiKitConfig);
|
|
3002
|
+
import_ui_builder_utils18.logger.info("EvmUiKitManager:configure", "WagmiConfig for RainbowKit obtained.");
|
|
3003
|
+
} else if (newKitName === "custom" || !newKitName) {
|
|
3004
|
+
newWagmiConfigAttempt = await evmImpl.getActiveConfigForManager(newFullUiKitConfig);
|
|
3005
|
+
import_ui_builder_utils18.logger.info("EvmUiKitManager:configure", "ActiveConfig for custom/default obtained.");
|
|
3006
|
+
if (kitChanged) {
|
|
3007
|
+
state.kitProviderComponent = null;
|
|
3008
|
+
state.isKitAssetsLoaded = false;
|
|
3009
|
+
}
|
|
3010
|
+
} else {
|
|
3011
|
+
import_ui_builder_utils18.logger.warn("EvmUiKitManager:configure", `Unsupported kitName: ${newKitName}.`);
|
|
3012
|
+
state.kitProviderComponent = null;
|
|
3013
|
+
state.isKitAssetsLoaded = false;
|
|
3014
|
+
}
|
|
3015
|
+
state.wagmiConfig = newWagmiConfigAttempt;
|
|
3016
|
+
evmImpl.setActiveWagmiConfig(state.wagmiConfig);
|
|
3017
|
+
state.error = null;
|
|
3018
|
+
if (!newWagmiConfigAttempt && newKitName && newKitName !== "none" && newKitName !== "custom") {
|
|
3019
|
+
state.error = new Error(`Failed to obtain WagmiConfig for ${newKitName}`);
|
|
3020
|
+
import_ui_builder_utils18.logger.error("EvmUiKitManager:configure", state.error.message);
|
|
3021
|
+
}
|
|
3022
|
+
} catch (err) {
|
|
3023
|
+
import_ui_builder_utils18.logger.error("EvmUiKitManager:configure", "Error during UI kit configuration process:", err);
|
|
3024
|
+
state.error = err instanceof Error ? err : new Error(String(err));
|
|
3025
|
+
state.wagmiConfig = null;
|
|
3026
|
+
evmImpl.setActiveWagmiConfig(null);
|
|
3027
|
+
} finally {
|
|
3028
|
+
state.isInitializing = false;
|
|
3029
|
+
import_ui_builder_utils18.logger.info(
|
|
3030
|
+
"EvmUiKitManager:configure",
|
|
3031
|
+
"Configuration attempt finished. Final wagmiConfig:",
|
|
3032
|
+
state.wagmiConfig ? "Set" : "Null",
|
|
3033
|
+
"Kit Provider Component:",
|
|
3034
|
+
state.kitProviderComponent ? "Set" : "Null",
|
|
3035
|
+
"Kit Assets Loaded:",
|
|
3036
|
+
state.isKitAssetsLoaded,
|
|
3037
|
+
"Error state:",
|
|
3038
|
+
state.error ? state.error.message : "None"
|
|
3039
|
+
);
|
|
3040
|
+
notifyListeners();
|
|
3041
|
+
}
|
|
2629
3042
|
}
|
|
3043
|
+
var evmUiKitManager = {
|
|
3044
|
+
getState,
|
|
3045
|
+
subscribe,
|
|
3046
|
+
configure
|
|
3047
|
+
};
|
|
2630
3048
|
|
|
2631
|
-
// src/
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
3049
|
+
// src/wallet/components/EvmWalletUiRoot.tsx
|
|
3050
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
3051
|
+
var stableQueryClient = new import_react_query.QueryClient();
|
|
3052
|
+
var minimalDefaultWagmiConfig = (0, import_core3.createConfig)({
|
|
3053
|
+
chains: [import_chains3.mainnet],
|
|
3054
|
+
// At least one chain is required in wagmi v2.20+
|
|
3055
|
+
connectors: [],
|
|
3056
|
+
// Empty connectors array
|
|
3057
|
+
transports: {
|
|
3058
|
+
[import_chains3.mainnet.id]: (0, import_core3.http)()
|
|
3059
|
+
// Basic HTTP transport for the default chain
|
|
2635
3060
|
}
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
3061
|
+
});
|
|
3062
|
+
var EvmWalletUiRoot = ({ children }) => {
|
|
3063
|
+
const [managerState, setManagerState] = (0, import_react9.useState)(
|
|
3064
|
+
evmUiKitManager.getState()
|
|
3065
|
+
);
|
|
3066
|
+
(0, import_react9.useEffect)(() => {
|
|
3067
|
+
const handleStateChange = () => {
|
|
3068
|
+
setManagerState(evmUiKitManager.getState());
|
|
3069
|
+
};
|
|
3070
|
+
const unsubscribe = evmUiKitManager.subscribe(handleStateChange);
|
|
3071
|
+
handleStateChange();
|
|
3072
|
+
return unsubscribe;
|
|
3073
|
+
}, []);
|
|
3074
|
+
const queryClient = (0, import_react9.useMemo)(() => stableQueryClient, []);
|
|
3075
|
+
const {
|
|
3076
|
+
wagmiConfig,
|
|
3077
|
+
kitProviderComponent,
|
|
3078
|
+
isKitAssetsLoaded,
|
|
3079
|
+
currentFullUiKitConfig,
|
|
3080
|
+
isInitializing,
|
|
3081
|
+
error
|
|
3082
|
+
} = managerState;
|
|
3083
|
+
const configForWagmiProvider = wagmiConfig || minimalDefaultWagmiConfig;
|
|
3084
|
+
const isWagmiContextEffectivelyReady = !!wagmiConfig && !error;
|
|
3085
|
+
let finalChildren = children;
|
|
3086
|
+
if (isWagmiContextEffectivelyReady && currentFullUiKitConfig?.kitName === "rainbowkit" && kitProviderComponent && isKitAssetsLoaded) {
|
|
3087
|
+
const DynKitProvider = kitProviderComponent;
|
|
3088
|
+
const kitConfig = currentFullUiKitConfig.kitConfig || {};
|
|
3089
|
+
const providerProps = kitConfig.providerProps || {};
|
|
3090
|
+
import_ui_builder_utils19.logger.info(
|
|
3091
|
+
"EvmWalletUiRoot",
|
|
3092
|
+
"Wrapping children with dynamically loaded KitProvider (RainbowKit)."
|
|
3093
|
+
);
|
|
3094
|
+
finalChildren = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(DynKitProvider, { ...providerProps, children });
|
|
3095
|
+
} else if (currentFullUiKitConfig?.kitName === "rainbowkit" && !isWagmiContextEffectivelyReady) {
|
|
3096
|
+
import_ui_builder_utils19.logger.info(
|
|
3097
|
+
"EvmWalletUiRoot",
|
|
3098
|
+
"RainbowKit configured, but context or assets not ready. Button may show its loading/error state."
|
|
2639
3099
|
);
|
|
2640
3100
|
}
|
|
2641
|
-
return
|
|
2642
|
-
|
|
3101
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_wagmi.WagmiProvider, { config: configForWagmiProvider, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react_query.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(WagmiProviderInitializedContext.Provider, { value: isWagmiContextEffectivelyReady, children: [
|
|
3102
|
+
finalChildren,
|
|
3103
|
+
isInitializing && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
3104
|
+
"div",
|
|
3105
|
+
{
|
|
3106
|
+
style: {
|
|
3107
|
+
position: "fixed",
|
|
3108
|
+
top: "10px",
|
|
3109
|
+
right: "10px",
|
|
3110
|
+
background: "rgba(0,0,0,0.1)",
|
|
3111
|
+
padding: "5px",
|
|
3112
|
+
borderRadius: "3px",
|
|
3113
|
+
fontSize: "0.8em"
|
|
3114
|
+
},
|
|
3115
|
+
children: "Updating network..."
|
|
3116
|
+
}
|
|
3117
|
+
),
|
|
3118
|
+
error && !wagmiConfig && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
3119
|
+
"div",
|
|
3120
|
+
{
|
|
3121
|
+
style: {
|
|
3122
|
+
position: "fixed",
|
|
3123
|
+
bottom: "10px",
|
|
3124
|
+
left: "10px",
|
|
3125
|
+
background: "red",
|
|
3126
|
+
color: "white",
|
|
3127
|
+
padding: "10px"
|
|
3128
|
+
},
|
|
3129
|
+
children: [
|
|
3130
|
+
"Error initializing wallet provider: ",
|
|
3131
|
+
error.message
|
|
3132
|
+
]
|
|
3133
|
+
}
|
|
3134
|
+
)
|
|
3135
|
+
] }) }) });
|
|
3136
|
+
};
|
|
2643
3137
|
|
|
2644
|
-
// src/
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
3138
|
+
// src/wallet/hooks/facade-hooks.ts
|
|
3139
|
+
var import_wagmi2 = require("wagmi");
|
|
3140
|
+
var evmFacadeHooks = {
|
|
3141
|
+
useAccount: import_wagmi2.useAccount,
|
|
3142
|
+
useConnect: import_wagmi2.useConnect,
|
|
3143
|
+
useDisconnect: import_wagmi2.useDisconnect,
|
|
3144
|
+
useSwitchChain: import_wagmi2.useSwitchChain,
|
|
3145
|
+
useChainId: import_wagmi2.useChainId,
|
|
3146
|
+
useChains: import_wagmi2.useChains,
|
|
3147
|
+
useBalance: import_wagmi2.useBalance,
|
|
3148
|
+
useSendTransaction: import_wagmi2.useSendTransaction,
|
|
3149
|
+
useWaitForTransactionReceipt: import_wagmi2.useWaitForTransactionReceipt,
|
|
3150
|
+
useSignMessage: import_wagmi2.useSignMessage,
|
|
3151
|
+
useSignTypedData: import_wagmi2.useSignTypedData
|
|
3152
|
+
};
|
|
2654
3153
|
|
|
2655
|
-
// src/
|
|
2656
|
-
function
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
3154
|
+
// src/wallet/rainbowkit/config-generator.ts
|
|
3155
|
+
function generateRainbowKitConfigFile(userConfig) {
|
|
3156
|
+
const config = userConfig || {};
|
|
3157
|
+
const appName = config.appName || "My RainbowKit App";
|
|
3158
|
+
const learnMoreUrl = config.learnMoreUrl || "https://openzeppelin.com";
|
|
3159
|
+
const projectId = config.projectId || "YOUR_PROJECT_ID";
|
|
3160
|
+
const appInfoLines = [`appName: '${appName}'`];
|
|
3161
|
+
if (learnMoreUrl) {
|
|
3162
|
+
appInfoLines.push(`learnMoreUrl: '${learnMoreUrl}'`);
|
|
2663
3163
|
}
|
|
2664
|
-
|
|
2665
|
-
|
|
3164
|
+
const appInfoContent = appInfoLines.join(",\n ");
|
|
3165
|
+
const fileContent = `// RainbowKit configuration for your exported application
|
|
3166
|
+
// This file is used ONLY in the exported app, not in the builder app preview
|
|
2666
3167
|
|
|
2667
|
-
//
|
|
2668
|
-
|
|
2669
|
-
function isValidEvmAddress(address) {
|
|
2670
|
-
return (0, import_viem2.isAddress)(address);
|
|
2671
|
-
}
|
|
3168
|
+
// Uncomment imports as needed:
|
|
3169
|
+
// import { darkTheme, lightTheme } from '@rainbow-me/rainbowkit';
|
|
2672
3170
|
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
3171
|
+
const rainbowKitAppConfig = {
|
|
3172
|
+
wagmiParams: {
|
|
3173
|
+
appName: '${appName}',
|
|
3174
|
+
projectId: '${projectId}', // Get yours at https://cloud.walletconnect.com
|
|
3175
|
+
|
|
3176
|
+
// Additional options:
|
|
3177
|
+
// ssr: true,
|
|
3178
|
+
// wallets: [...],
|
|
3179
|
+
},
|
|
3180
|
+
providerProps: {
|
|
3181
|
+
appInfo: {
|
|
3182
|
+
${appInfoContent}
|
|
3183
|
+
},
|
|
3184
|
+
|
|
3185
|
+
// UI customization - all features work in exported apps:
|
|
3186
|
+
// theme: darkTheme(),
|
|
3187
|
+
// modalSize: 'compact',
|
|
3188
|
+
// showRecentTransactions: true,
|
|
3189
|
+
// coolMode: true,
|
|
3190
|
+
},
|
|
2682
3191
|
};
|
|
2683
3192
|
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
import_ui_builder_utils19.logger.info("transformAbiToSchema", `Transforming ABI to ContractSchema for: ${contractName}`);
|
|
2687
|
-
const functions = [];
|
|
2688
|
-
for (const item of abi) {
|
|
2689
|
-
if (item.type === "function") {
|
|
2690
|
-
const abiFunctionItem = item;
|
|
2691
|
-
functions.push({
|
|
2692
|
-
// Generate a unique ID for the function within the schema.
|
|
2693
|
-
// This often combines name and input types to handle overloads.
|
|
2694
|
-
id: `${abiFunctionItem.name}_${abiFunctionItem.inputs?.map((i) => i.type).join("_") || ""}`,
|
|
2695
|
-
name: abiFunctionItem.name || "",
|
|
2696
|
-
// Fallback for unnamed functions (though rare).
|
|
2697
|
-
displayName: formatMethodName(abiFunctionItem.name || ""),
|
|
2698
|
-
// Create a more readable name for UI.
|
|
2699
|
-
// Recursively map ABI inputs and outputs to our FunctionParameter structure.
|
|
2700
|
-
// This ensures that any non-standard properties (like 'internalType') are stripped.
|
|
2701
|
-
inputs: mapAbiParametersToSchemaParameters(abiFunctionItem.inputs),
|
|
2702
|
-
outputs: mapAbiParametersToSchemaParameters(abiFunctionItem.outputs),
|
|
2703
|
-
type: "function",
|
|
2704
|
-
// Explicitly set, as we filtered for this type.
|
|
2705
|
-
stateMutability: abiFunctionItem.stateMutability,
|
|
2706
|
-
// Preserve EVM-specific state mutability.
|
|
2707
|
-
// Determine if the function modifies blockchain state based on its `stateMutability`.
|
|
2708
|
-
// This is a crucial piece of information for the UI (e.g., to differentiate read vs. write calls).
|
|
2709
|
-
modifiesState: !abiFunctionItem.stateMutability || // If undefined, assume it modifies state (safer default)
|
|
2710
|
-
!["view", "pure"].includes(abiFunctionItem.stateMutability)
|
|
2711
|
-
});
|
|
2712
|
-
}
|
|
2713
|
-
}
|
|
2714
|
-
const contractSchema = {
|
|
2715
|
-
ecosystem: "evm",
|
|
2716
|
-
// This transformer is specific to EVM.
|
|
2717
|
-
name: contractName,
|
|
2718
|
-
address,
|
|
2719
|
-
functions
|
|
2720
|
-
};
|
|
2721
|
-
import_ui_builder_utils19.logger.info(
|
|
2722
|
-
"transformAbiToSchema",
|
|
2723
|
-
`Transformation complete. Found ${contractSchema.functions.length} functions.`
|
|
2724
|
-
);
|
|
2725
|
-
return contractSchema;
|
|
2726
|
-
}
|
|
2727
|
-
function mapAbiParametersToSchemaParameters(abiParams) {
|
|
2728
|
-
if (!abiParams) {
|
|
2729
|
-
return [];
|
|
2730
|
-
}
|
|
2731
|
-
return abiParams.map((param) => {
|
|
2732
|
-
const schemaParam = {
|
|
2733
|
-
name: param.name || "",
|
|
2734
|
-
// Ensure name is a string, fallback if undefined in ABI.
|
|
2735
|
-
type: param.type,
|
|
2736
|
-
// The raw type string from the ABI (e.g., 'uint256', 'address', 'tuple').
|
|
2737
|
-
displayName: formatInputName(param.name || "", param.type)
|
|
2738
|
-
// Generate a user-friendly name.
|
|
2739
|
-
// `description` is not a standard part of an ABI parameter, so it's not mapped here.
|
|
2740
|
-
// It can be added later by the user in the builder app UI.
|
|
2741
|
-
};
|
|
2742
|
-
if (param.type.startsWith("tuple") && "components" in param && // Type guard for discriminated union (AbiParameter)
|
|
2743
|
-
param.components && param.components.length > 0) {
|
|
2744
|
-
schemaParam.components = mapAbiParametersToSchemaParameters(
|
|
2745
|
-
param.components
|
|
2746
|
-
);
|
|
2747
|
-
}
|
|
2748
|
-
return schemaParam;
|
|
2749
|
-
});
|
|
2750
|
-
}
|
|
2751
|
-
function mapSchemaParameterToAbiParameter(param) {
|
|
2752
|
-
if (param.type.startsWith("tuple") && param.components && param.components.length > 0) {
|
|
2753
|
-
return {
|
|
2754
|
-
name: param.name || void 0,
|
|
2755
|
-
// ABI parameter names can be undefined (e.g., for return values).
|
|
2756
|
-
type: param.type,
|
|
2757
|
-
// Cast to satisfy viem's specific tuple type string.
|
|
2758
|
-
// Recursively map nested components back to AbiParameter format.
|
|
2759
|
-
components: param.components.map(mapSchemaParameterToAbiParameter)
|
|
2760
|
-
};
|
|
2761
|
-
}
|
|
2762
|
-
return {
|
|
2763
|
-
name: param.name || void 0,
|
|
2764
|
-
type: param.type
|
|
2765
|
-
// `internalType` is not part of our `FunctionParameter` model, so it's not added back here.
|
|
2766
|
-
// Other ABI-specific fields like `indexed` (for events) are also not relevant here as
|
|
2767
|
-
// this function is focused on function parameters for `AbiFunction`.
|
|
2768
|
-
};
|
|
3193
|
+
export default rainbowKitAppConfig;`;
|
|
3194
|
+
return fileContent;
|
|
2769
3195
|
}
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
stateMutability: functionDetails.stateMutability ?? "view"
|
|
2777
|
-
};
|
|
3196
|
+
|
|
3197
|
+
// src/wallet/rainbowkit/export-service.ts
|
|
3198
|
+
function generateRainbowKitExportables(uiKitConfig2) {
|
|
3199
|
+
const filePath = "src/config/wallet/rainbowkit.config.ts";
|
|
3200
|
+
const content = uiKitConfig2.customCode || generateRainbowKitConfigFile(uiKitConfig2.kitConfig);
|
|
3201
|
+
return { [filePath]: content };
|
|
2778
3202
|
}
|
|
2779
3203
|
|
|
2780
|
-
// src/
|
|
3204
|
+
// src/wallet/services/configResolutionService.ts
|
|
3205
|
+
var import_ui_builder_utils23 = require("@openzeppelin/ui-builder-utils");
|
|
3206
|
+
|
|
3207
|
+
// src/wallet/utils.ts
|
|
2781
3208
|
var import_ui_builder_utils22 = require("@openzeppelin/ui-builder-utils");
|
|
2782
3209
|
|
|
2783
|
-
// src/
|
|
3210
|
+
// src/wallet/utils/uiKitService.ts
|
|
2784
3211
|
var import_ui_builder_utils21 = require("@openzeppelin/ui-builder-utils");
|
|
2785
3212
|
|
|
2786
|
-
// src/
|
|
3213
|
+
// src/wallet/utils/filterWalletComponents.ts
|
|
3214
|
+
var import_ui_builder_types = require("@openzeppelin/ui-builder-types");
|
|
2787
3215
|
var import_ui_builder_utils20 = require("@openzeppelin/ui-builder-utils");
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
url.searchParams.append("module", module2);
|
|
2793
|
-
url.searchParams.append("action", action);
|
|
2794
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
2795
|
-
url.searchParams.append(key, value);
|
|
2796
|
-
});
|
|
2797
|
-
if (apiKey) {
|
|
2798
|
-
url.searchParams.append("apikey", apiKey);
|
|
2799
|
-
}
|
|
2800
|
-
return url.toString();
|
|
2801
|
-
}
|
|
2802
|
-
function shouldUseV2Api(networkConfig) {
|
|
2803
|
-
if (!networkConfig.supportsEtherscanV2) {
|
|
2804
|
-
return false;
|
|
2805
|
-
}
|
|
2806
|
-
return true;
|
|
2807
|
-
}
|
|
2808
|
-
async function loadAbiFromEtherscanV2(address, networkConfig) {
|
|
2809
|
-
const explorerConfig = resolveExplorerConfig(networkConfig);
|
|
2810
|
-
const url = buildV2ApiUrl(
|
|
2811
|
-
networkConfig.chainId,
|
|
2812
|
-
"contract",
|
|
2813
|
-
"getabi",
|
|
2814
|
-
{ address },
|
|
2815
|
-
explorerConfig.apiKey
|
|
3216
|
+
function filterWalletComponents(allPossibleComponents, exclusions, kitName = "custom") {
|
|
3217
|
+
import_ui_builder_utils20.logger.debug(
|
|
3218
|
+
"filterWalletComponents",
|
|
3219
|
+
`Filtering components for kit: ${kitName}. Exclusions: ${exclusions.join(", ")}.`
|
|
2816
3220
|
);
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
"loadAbiFromEtherscanV2",
|
|
2821
|
-
`Fetching ABI from Etherscan V2 API for address: ${address} on chain ${networkConfig.chainId}`
|
|
2822
|
-
);
|
|
2823
|
-
response = await fetch(url);
|
|
2824
|
-
} catch (networkError) {
|
|
2825
|
-
import_ui_builder_utils20.logger.error(
|
|
2826
|
-
"loadAbiFromEtherscanV2",
|
|
2827
|
-
`Network error fetching ABI from Explorer V2 API: ${networkError}`
|
|
2828
|
-
);
|
|
2829
|
-
throw new Error(`Network error fetching ABI: ${networkError.message}`);
|
|
2830
|
-
}
|
|
2831
|
-
if (!response.ok) {
|
|
2832
|
-
import_ui_builder_utils20.logger.error(
|
|
2833
|
-
"loadAbiFromEtherscanV2",
|
|
2834
|
-
`Explorer V2 API request failed with status: ${response.status}`
|
|
2835
|
-
);
|
|
2836
|
-
throw new Error(`Explorer V2 API request failed: ${response.status} ${response.statusText}`);
|
|
3221
|
+
if (!allPossibleComponents || Object.keys(allPossibleComponents).length === 0) {
|
|
3222
|
+
import_ui_builder_utils20.logger.debug("filterWalletComponents", `No components provided to filter for kit: ${kitName}.`);
|
|
3223
|
+
return void 0;
|
|
2837
3224
|
}
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
"loadAbiFromEtherscanV2",
|
|
2844
|
-
`Failed to parse Explorer V2 API response as JSON: ${jsonError}`
|
|
3225
|
+
if (exclusions.length === 0) {
|
|
3226
|
+
import_ui_builder_utils20.logger.debug(
|
|
3227
|
+
"filterWalletComponents",
|
|
3228
|
+
`Providing all components for kit: ${kitName}.`,
|
|
3229
|
+
allPossibleComponents
|
|
2845
3230
|
);
|
|
2846
|
-
|
|
3231
|
+
return allPossibleComponents;
|
|
2847
3232
|
}
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
)
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
`Invalid API key for Etherscan V2. Please check your API key configuration.`
|
|
2857
|
-
);
|
|
2858
|
-
}
|
|
2859
|
-
if (apiResult.result?.includes("Contract source code not verified")) {
|
|
2860
|
-
throw new Error(
|
|
2861
|
-
`Contract not verified on ${networkConfig.name} explorer (address: ${address}). ABI not available. You can provide the contract's ABI manually.`
|
|
2862
|
-
);
|
|
2863
|
-
}
|
|
2864
|
-
if (apiResult.result?.includes("Invalid chain")) {
|
|
2865
|
-
throw new Error(
|
|
2866
|
-
`Chain ID ${networkConfig.chainId} is not supported by Etherscan V2 API. Please check if this chain is available.`
|
|
2867
|
-
);
|
|
3233
|
+
const filteredComponents = {};
|
|
3234
|
+
let componentCount = 0;
|
|
3235
|
+
for (const key in allPossibleComponents) {
|
|
3236
|
+
const componentKey = key;
|
|
3237
|
+
if (!exclusions.includes(componentKey)) {
|
|
3238
|
+
if (allPossibleComponents[componentKey]) {
|
|
3239
|
+
filteredComponents[componentKey] = allPossibleComponents[componentKey];
|
|
3240
|
+
componentCount++;
|
|
2868
3241
|
}
|
|
2869
3242
|
}
|
|
2870
|
-
throw new Error(`Explorer V2 API Error: ${apiResult.result || apiResult.message}`);
|
|
2871
3243
|
}
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
throw new Error("Parsed ABI from Explorer V2 API is not an array.");
|
|
2878
|
-
}
|
|
2879
|
-
} catch (error) {
|
|
2880
|
-
import_ui_builder_utils20.logger.error(
|
|
2881
|
-
"loadAbiFromEtherscanV2",
|
|
2882
|
-
`Failed to parse ABI JSON string from Explorer V2 API result: ${error}`
|
|
3244
|
+
if (componentCount > 0) {
|
|
3245
|
+
import_ui_builder_utils20.logger.debug(
|
|
3246
|
+
"filterWalletComponents",
|
|
3247
|
+
`Providing filtered components for kit: ${kitName} after exclusions (${exclusions.join(", ")}).`,
|
|
3248
|
+
filteredComponents
|
|
2883
3249
|
);
|
|
2884
|
-
|
|
3250
|
+
return filteredComponents;
|
|
2885
3251
|
}
|
|
2886
|
-
import_ui_builder_utils20.logger.
|
|
2887
|
-
|
|
2888
|
-
`Successfully parsed ABI for ${networkConfig.name} with ${abi.length} items using V2 API.`
|
|
2889
|
-
);
|
|
2890
|
-
const contractName = `Contract_${address.substring(0, 6)}`;
|
|
2891
|
-
const schema = transformAbiToSchema(abi, contractName, address);
|
|
2892
|
-
return {
|
|
2893
|
-
schema,
|
|
2894
|
-
originalAbi: originalAbiString
|
|
2895
|
-
};
|
|
3252
|
+
import_ui_builder_utils20.logger.debug("filterWalletComponents", `All components were excluded for kit: ${kitName}.`);
|
|
3253
|
+
return void 0;
|
|
2896
3254
|
}
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
};
|
|
2905
|
-
}
|
|
2906
|
-
try {
|
|
2907
|
-
const url = buildV2ApiUrl(networkConfig.chainId, "proxy", "eth_blockNumber", {}, apiKey);
|
|
2908
|
-
const response = await fetch(url);
|
|
2909
|
-
const latency = Date.now() - startTime;
|
|
2910
|
-
if (!response.ok) {
|
|
2911
|
-
return {
|
|
2912
|
-
success: false,
|
|
2913
|
-
error: `HTTP ${response.status}: ${response.statusText}`,
|
|
2914
|
-
latency
|
|
2915
|
-
};
|
|
2916
|
-
}
|
|
2917
|
-
const data = await response.json();
|
|
2918
|
-
if (data.status === "0" && data.message) {
|
|
2919
|
-
if (data.result?.includes("Invalid API Key")) {
|
|
2920
|
-
return {
|
|
2921
|
-
success: false,
|
|
2922
|
-
error: "Invalid API key. Please check your Etherscan API key.",
|
|
2923
|
-
latency
|
|
2924
|
-
};
|
|
2925
|
-
}
|
|
2926
|
-
if (data.result?.includes("Invalid chain")) {
|
|
2927
|
-
return {
|
|
2928
|
-
success: false,
|
|
2929
|
-
error: `Chain ID ${networkConfig.chainId} is not supported by Etherscan V2 API.`,
|
|
2930
|
-
latency
|
|
2931
|
-
};
|
|
2932
|
-
}
|
|
2933
|
-
return {
|
|
2934
|
-
success: false,
|
|
2935
|
-
error: data.result || data.message,
|
|
2936
|
-
latency
|
|
2937
|
-
};
|
|
3255
|
+
function getComponentExclusionsFromConfig(kitConfig) {
|
|
3256
|
+
if (kitConfig && typeof kitConfig === "object" && "components" in kitConfig) {
|
|
3257
|
+
const componentsCfg = kitConfig.components;
|
|
3258
|
+
if (componentsCfg && typeof componentsCfg === "object" && "exclude" in componentsCfg && Array.isArray(componentsCfg.exclude)) {
|
|
3259
|
+
return componentsCfg.exclude.filter(
|
|
3260
|
+
(key) => typeof key === "string" && import_ui_builder_types.ECOSYSTEM_WALLET_COMPONENT_KEYS.includes(key)
|
|
3261
|
+
);
|
|
2938
3262
|
}
|
|
2939
|
-
return {
|
|
2940
|
-
success: true,
|
|
2941
|
-
latency
|
|
2942
|
-
};
|
|
2943
|
-
} catch (error) {
|
|
2944
|
-
return {
|
|
2945
|
-
success: false,
|
|
2946
|
-
error: error instanceof Error ? error.message : "Connection test failed",
|
|
2947
|
-
latency: Date.now() - startTime
|
|
2948
|
-
};
|
|
2949
3263
|
}
|
|
3264
|
+
return [];
|
|
2950
3265
|
}
|
|
2951
3266
|
|
|
2952
|
-
// src/
|
|
2953
|
-
function
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
if (userConfig) {
|
|
2959
|
-
import_ui_builder_utils21.logger.info("ExplorerConfig", `Using user-configured explorer for ${networkConfig.name}`);
|
|
2960
|
-
return {
|
|
2961
|
-
// Prefer user overrides when provided
|
|
2962
|
-
explorerUrl: userConfig.explorerUrl ?? networkConfig.explorerUrl,
|
|
2963
|
-
apiUrl: userConfig.apiUrl ?? networkConfig.apiUrl,
|
|
2964
|
-
// If user did not provide an API key, fall back to global V2 key (when applicable)
|
|
2965
|
-
// then to app-configured per-explorer identifier key
|
|
2966
|
-
apiKey: userConfig.apiKey ?? globalV2ApiKey ?? appApiKey,
|
|
2967
|
-
name: userConfig.name ?? `${networkConfig.name} Explorer`,
|
|
2968
|
-
isCustom: userConfig.isCustom ?? false,
|
|
2969
|
-
applyToAllNetworks: userConfig.applyToAllNetworks,
|
|
2970
|
-
appliedNetworkIds: userConfig.appliedNetworkIds,
|
|
2971
|
-
defaultProvider: userConfig.defaultProvider
|
|
2972
|
-
};
|
|
2973
|
-
}
|
|
2974
|
-
if (isV2 && globalV2ApiKey) {
|
|
2975
|
-
import_ui_builder_utils21.logger.info("ExplorerConfig", `Using global Etherscan V2 API key for ${networkConfig.name}`);
|
|
2976
|
-
return {
|
|
2977
|
-
explorerUrl: networkConfig.explorerUrl,
|
|
2978
|
-
apiUrl: networkConfig.apiUrl,
|
|
2979
|
-
apiKey: globalV2ApiKey,
|
|
2980
|
-
name: `${networkConfig.name} Explorer (V2 API)`,
|
|
2981
|
-
isCustom: false
|
|
2982
|
-
};
|
|
2983
|
-
}
|
|
2984
|
-
if (appApiKey) {
|
|
2985
|
-
import_ui_builder_utils21.logger.info("ExplorerConfig", `Using app-configured API key for ${networkConfig.name}`);
|
|
2986
|
-
return {
|
|
2987
|
-
explorerUrl: networkConfig.explorerUrl,
|
|
2988
|
-
apiUrl: networkConfig.apiUrl,
|
|
2989
|
-
apiKey: appApiKey,
|
|
2990
|
-
name: `${networkConfig.name} Explorer`,
|
|
2991
|
-
isCustom: false
|
|
2992
|
-
};
|
|
2993
|
-
}
|
|
2994
|
-
import_ui_builder_utils21.logger.info(
|
|
2995
|
-
"ExplorerConfig",
|
|
2996
|
-
`Using default explorer for ${networkConfig.name} (no API key configured)`
|
|
3267
|
+
// src/wallet/utils/uiKitService.ts
|
|
3268
|
+
function getResolvedWalletComponents(uiKitConfiguration) {
|
|
3269
|
+
import_ui_builder_utils21.logger.debug(
|
|
3270
|
+
"uiKitService:getResolvedWalletComponents",
|
|
3271
|
+
"Received uiKitConfiguration:",
|
|
3272
|
+
JSON.stringify(uiKitConfiguration)
|
|
2997
3273
|
);
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
function getEvmExplorerAddressUrl(address, networkConfig) {
|
|
3006
|
-
if (!isValidEvmAddress(address)) {
|
|
3007
|
-
return null;
|
|
3008
|
-
}
|
|
3009
|
-
const explorerConfig = resolveExplorerConfig(networkConfig);
|
|
3010
|
-
if (!explorerConfig.explorerUrl) {
|
|
3011
|
-
return null;
|
|
3012
|
-
}
|
|
3013
|
-
const baseUrl = explorerConfig.explorerUrl.replace(/\/+$/, "");
|
|
3014
|
-
return `${baseUrl}/address/${address}`;
|
|
3015
|
-
}
|
|
3016
|
-
function getEvmExplorerTxUrl(txHash, networkConfig) {
|
|
3017
|
-
if (!txHash) {
|
|
3018
|
-
return null;
|
|
3019
|
-
}
|
|
3020
|
-
const explorerConfig = resolveExplorerConfig(networkConfig);
|
|
3021
|
-
if (!explorerConfig.explorerUrl) {
|
|
3022
|
-
return null;
|
|
3023
|
-
}
|
|
3024
|
-
const baseUrl = explorerConfig.explorerUrl.replace(/\/+$/, "");
|
|
3025
|
-
return `${baseUrl}/tx/${txHash}`;
|
|
3026
|
-
}
|
|
3027
|
-
function validateEvmExplorerConfig(explorerConfig) {
|
|
3028
|
-
if (explorerConfig.explorerUrl) {
|
|
3029
|
-
try {
|
|
3030
|
-
new URL(explorerConfig.explorerUrl);
|
|
3031
|
-
} catch {
|
|
3032
|
-
return false;
|
|
3033
|
-
}
|
|
3034
|
-
}
|
|
3035
|
-
if (explorerConfig.apiUrl) {
|
|
3036
|
-
try {
|
|
3037
|
-
new URL(explorerConfig.apiUrl);
|
|
3038
|
-
} catch {
|
|
3039
|
-
return false;
|
|
3040
|
-
}
|
|
3041
|
-
}
|
|
3042
|
-
if (explorerConfig.apiKey !== void 0 && explorerConfig.apiKey.trim().length === 0) {
|
|
3043
|
-
return false;
|
|
3044
|
-
}
|
|
3045
|
-
return true;
|
|
3046
|
-
}
|
|
3047
|
-
async function testEvmExplorerConnection(explorerConfig, networkConfig) {
|
|
3048
|
-
const requiresApiKey = networkConfig && "requiresExplorerApiKey" in networkConfig ? networkConfig.requiresExplorerApiKey !== false : true;
|
|
3049
|
-
if (requiresApiKey && !explorerConfig.apiKey) {
|
|
3050
|
-
return {
|
|
3051
|
-
success: false,
|
|
3052
|
-
error: "API key is required for testing connection to this explorer"
|
|
3053
|
-
};
|
|
3054
|
-
}
|
|
3055
|
-
if (networkConfig && shouldUseV2Api(networkConfig)) {
|
|
3056
|
-
return testEtherscanV2Connection(networkConfig, explorerConfig.apiKey);
|
|
3057
|
-
}
|
|
3058
|
-
let apiUrl = explorerConfig.apiUrl;
|
|
3059
|
-
if (!apiUrl && networkConfig?.apiUrl) {
|
|
3060
|
-
apiUrl = networkConfig.apiUrl;
|
|
3274
|
+
const currentKitName = uiKitConfiguration.kitName || "custom";
|
|
3275
|
+
if (currentKitName === "none") {
|
|
3276
|
+
import_ui_builder_utils21.logger.info(
|
|
3277
|
+
"uiKitService",
|
|
3278
|
+
'UI Kit set to "none" for getResolvedWalletComponents, not providing wallet components.'
|
|
3279
|
+
);
|
|
3280
|
+
return void 0;
|
|
3061
3281
|
}
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3282
|
+
const exclusions = getComponentExclusionsFromConfig(uiKitConfiguration.kitConfig);
|
|
3283
|
+
import_ui_builder_utils21.logger.debug(
|
|
3284
|
+
"uiKitService",
|
|
3285
|
+
`Extracted component exclusions for ${currentKitName}: ${exclusions.join(", ") || "none"}.`
|
|
3286
|
+
);
|
|
3287
|
+
if (currentKitName === "custom") {
|
|
3288
|
+
const allCustomComponents = {
|
|
3289
|
+
ConnectButton: CustomConnectButton,
|
|
3290
|
+
AccountDisplay: CustomAccountDisplay,
|
|
3291
|
+
NetworkSwitcher: CustomNetworkSwitcher
|
|
3066
3292
|
};
|
|
3293
|
+
return filterWalletComponents(allCustomComponents, exclusions, currentKitName);
|
|
3067
3294
|
}
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3295
|
+
if (currentKitName === "rainbowkit") {
|
|
3296
|
+
const validation = validateRainbowKitConfig(uiKitConfiguration.kitConfig);
|
|
3297
|
+
if (!validation.isValid) {
|
|
3298
|
+
import_ui_builder_utils21.logger.warn(
|
|
3299
|
+
"uiKitService",
|
|
3300
|
+
`Invalid RainbowKit configuration for components: ${validation.error}. No components provided.`
|
|
3301
|
+
);
|
|
3302
|
+
return void 0;
|
|
3075
3303
|
}
|
|
3076
|
-
const
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3304
|
+
const rainbowKitComponents = createRainbowKitComponents();
|
|
3305
|
+
import_ui_builder_utils21.logger.info("uiKitService", "Providing RainbowKit components.");
|
|
3306
|
+
return filterWalletComponents(rainbowKitComponents, exclusions, currentKitName);
|
|
3307
|
+
}
|
|
3308
|
+
import_ui_builder_utils21.logger.warn(
|
|
3309
|
+
"uiKitService",
|
|
3310
|
+
`UI Kit "${currentKitName}" for getResolvedWalletComponents not explicitly supported. No components provided.`
|
|
3311
|
+
);
|
|
3312
|
+
return void 0;
|
|
3313
|
+
}
|
|
3314
|
+
|
|
3315
|
+
// src/wallet/utils.ts
|
|
3316
|
+
function getResolvedWalletComponents2(uiKitConfig2) {
|
|
3317
|
+
return getResolvedWalletComponents(uiKitConfig2);
|
|
3318
|
+
}
|
|
3319
|
+
async function resolveAndInitializeKitConfig(kitName, programmaticKitConfig, loadConfigModule) {
|
|
3320
|
+
import_ui_builder_utils22.logger.debug(
|
|
3321
|
+
"resolveAndInitializeKitConfig",
|
|
3322
|
+
`Resolving native config for kit: ${kitName || "none"}`,
|
|
3323
|
+
{
|
|
3324
|
+
hasProgrammaticKitConfig: !!programmaticKitConfig,
|
|
3325
|
+
hasLoadConfigModule: !!loadConfigModule
|
|
3084
3326
|
}
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3327
|
+
);
|
|
3328
|
+
let userNativeConfig = null;
|
|
3329
|
+
if (kitName && kitName !== "custom" && kitName !== "none" && loadConfigModule) {
|
|
3330
|
+
const conventionalConfigPath = `./config/wallet/${kitName}.config.ts`;
|
|
3331
|
+
try {
|
|
3332
|
+
userNativeConfig = await loadConfigModule(conventionalConfigPath);
|
|
3333
|
+
} catch (error) {
|
|
3334
|
+
import_ui_builder_utils22.logger.warn(
|
|
3335
|
+
"resolveAndInitializeKitConfig",
|
|
3336
|
+
`Call to load native config for ${kitName} from ${conventionalConfigPath} failed. Error:`,
|
|
3337
|
+
error
|
|
3338
|
+
);
|
|
3092
3339
|
}
|
|
3093
|
-
return {
|
|
3094
|
-
success: true,
|
|
3095
|
-
latency
|
|
3096
|
-
};
|
|
3097
|
-
} catch (error) {
|
|
3098
|
-
return {
|
|
3099
|
-
success: false,
|
|
3100
|
-
error: error instanceof Error ? error.message : "Connection test failed",
|
|
3101
|
-
latency: Date.now() - startTime
|
|
3102
|
-
};
|
|
3103
3340
|
}
|
|
3341
|
+
if (userNativeConfig && programmaticKitConfig) {
|
|
3342
|
+
const mergedConfig = { ...userNativeConfig, ...programmaticKitConfig };
|
|
3343
|
+
return mergedConfig;
|
|
3344
|
+
} else if (userNativeConfig) {
|
|
3345
|
+
return userNativeConfig;
|
|
3346
|
+
} else if (programmaticKitConfig) {
|
|
3347
|
+
return programmaticKitConfig;
|
|
3348
|
+
}
|
|
3349
|
+
import_ui_builder_utils22.logger.debug(
|
|
3350
|
+
"resolveAndInitializeKitConfig",
|
|
3351
|
+
`No native or programmatic kitConfig provided for ${kitName || "none"}. Returning null.`
|
|
3352
|
+
);
|
|
3353
|
+
return null;
|
|
3354
|
+
}
|
|
3355
|
+
|
|
3356
|
+
// src/wallet/services/configResolutionService.ts
|
|
3357
|
+
async function resolveFullUiKitConfiguration(programmaticOverrides, initialAppServiceKitName, currentAppServiceConfig, options) {
|
|
3358
|
+
import_ui_builder_utils23.logger.debug(
|
|
3359
|
+
"configResolutionService:resolveFullUiKitConfiguration",
|
|
3360
|
+
"Starting resolution with:",
|
|
3361
|
+
{
|
|
3362
|
+
programmaticOverrides,
|
|
3363
|
+
initialAppServiceKitName,
|
|
3364
|
+
currentAppServiceConfig,
|
|
3365
|
+
hasLoadNativeCallback: !!options?.loadUiKitNativeConfig,
|
|
3366
|
+
hasCustomCode: !!programmaticOverrides.customCode
|
|
3367
|
+
}
|
|
3368
|
+
);
|
|
3369
|
+
const effectiveKitName = programmaticOverrides.kitName || initialAppServiceKitName || currentAppServiceConfig.kitName || "custom";
|
|
3370
|
+
const resolvedUserNativeAndProgrammaticKitConfig = await resolveAndInitializeKitConfig(
|
|
3371
|
+
effectiveKitName,
|
|
3372
|
+
programmaticOverrides.kitConfig,
|
|
3373
|
+
options?.loadUiKitNativeConfig
|
|
3374
|
+
);
|
|
3375
|
+
const finalFullConfig = {
|
|
3376
|
+
kitName: effectiveKitName,
|
|
3377
|
+
kitConfig: {
|
|
3378
|
+
...currentAppServiceConfig.kitConfig || {},
|
|
3379
|
+
...resolvedUserNativeAndProgrammaticKitConfig || {}
|
|
3380
|
+
// customCode is NOT applied to runtime config
|
|
3381
|
+
},
|
|
3382
|
+
// Pass through customCode for export purposes only
|
|
3383
|
+
customCode: programmaticOverrides.customCode
|
|
3384
|
+
};
|
|
3385
|
+
import_ui_builder_utils23.logger.debug(
|
|
3386
|
+
"configResolutionService:resolveFullUiKitConfiguration",
|
|
3387
|
+
"Resolved finalFullConfig:",
|
|
3388
|
+
finalFullConfig
|
|
3389
|
+
);
|
|
3390
|
+
return finalFullConfig;
|
|
3104
3391
|
}
|
|
3105
3392
|
|
|
3106
3393
|
// src/abi/etherscan.ts
|
|
3394
|
+
var import_ui_builder_utils24 = require("@openzeppelin/ui-builder-utils");
|
|
3107
3395
|
async function loadAbiFromEtherscan(address, networkConfig) {
|
|
3108
3396
|
if (shouldUseV2Api(networkConfig)) {
|
|
3109
|
-
|
|
3397
|
+
import_ui_builder_utils24.logger.info("loadAbiFromEtherscan", "Using V2 API for fetching ABI");
|
|
3110
3398
|
return loadAbiFromEtherscanV2(address, networkConfig);
|
|
3111
3399
|
}
|
|
3112
|
-
|
|
3400
|
+
import_ui_builder_utils24.logger.info("loadAbiFromEtherscan", "Using V1 API for fetching ABI");
|
|
3113
3401
|
return loadAbiFromEtherscanV1(address, networkConfig);
|
|
3114
3402
|
}
|
|
3115
3403
|
async function loadAbiFromEtherscanV1(address, networkConfig) {
|
|
3116
3404
|
const explorerConfig = resolveExplorerConfig(networkConfig);
|
|
3117
3405
|
if (!explorerConfig.apiUrl) {
|
|
3118
|
-
|
|
3406
|
+
import_ui_builder_utils24.logger.error(
|
|
3119
3407
|
"loadAbiFromEtherscanV1",
|
|
3120
3408
|
`API URL is missing for ${networkConfig.name} explorer.`
|
|
3121
3409
|
);
|
|
@@ -3130,20 +3418,20 @@ async function loadAbiFromEtherscanV1(address, networkConfig) {
|
|
|
3130
3418
|
}
|
|
3131
3419
|
let response;
|
|
3132
3420
|
try {
|
|
3133
|
-
|
|
3421
|
+
import_ui_builder_utils24.logger.info(
|
|
3134
3422
|
"loadAbiFromEtherscanV1",
|
|
3135
3423
|
`Fetching ABI from ${explorerConfig.apiUrl} for address: ${address}`
|
|
3136
3424
|
);
|
|
3137
3425
|
response = await fetch(url);
|
|
3138
3426
|
} catch (networkError) {
|
|
3139
|
-
|
|
3427
|
+
import_ui_builder_utils24.logger.error(
|
|
3140
3428
|
"loadAbiFromEtherscanV1",
|
|
3141
3429
|
`Network error fetching ABI from Explorer API: ${networkError}`
|
|
3142
3430
|
);
|
|
3143
3431
|
throw new Error(`Network error fetching ABI: ${networkError.message}`);
|
|
3144
3432
|
}
|
|
3145
3433
|
if (!response.ok) {
|
|
3146
|
-
|
|
3434
|
+
import_ui_builder_utils24.logger.error(
|
|
3147
3435
|
"loadAbiFromEtherscanV1",
|
|
3148
3436
|
`Explorer API request failed with status: ${response.status}`
|
|
3149
3437
|
);
|
|
@@ -3153,14 +3441,14 @@ async function loadAbiFromEtherscanV1(address, networkConfig) {
|
|
|
3153
3441
|
try {
|
|
3154
3442
|
apiResult = await response.json();
|
|
3155
3443
|
} catch (jsonError) {
|
|
3156
|
-
|
|
3444
|
+
import_ui_builder_utils24.logger.error(
|
|
3157
3445
|
"loadAbiFromEtherscanV1",
|
|
3158
3446
|
`Failed to parse Explorer API response as JSON: ${jsonError}`
|
|
3159
3447
|
);
|
|
3160
3448
|
throw new Error("Invalid JSON response received from Explorer API.");
|
|
3161
3449
|
}
|
|
3162
3450
|
if (apiResult.status !== "1") {
|
|
3163
|
-
|
|
3451
|
+
import_ui_builder_utils24.logger.warn(
|
|
3164
3452
|
"loadAbiFromEtherscanV1",
|
|
3165
3453
|
`Explorer API error: Status ${apiResult.status}, Message: ${apiResult.message}, Result: ${apiResult.result}`
|
|
3166
3454
|
);
|
|
@@ -3179,13 +3467,13 @@ async function loadAbiFromEtherscanV1(address, networkConfig) {
|
|
|
3179
3467
|
throw new Error("Parsed ABI from Explorer API is not an array.");
|
|
3180
3468
|
}
|
|
3181
3469
|
} catch (error) {
|
|
3182
|
-
|
|
3470
|
+
import_ui_builder_utils24.logger.error(
|
|
3183
3471
|
"loadAbiFromEtherscanV1",
|
|
3184
3472
|
`Failed to parse ABI JSON string from Explorer API result: ${error}`
|
|
3185
3473
|
);
|
|
3186
3474
|
throw new Error(`Invalid ABI JSON received from Explorer API: ${error.message}`);
|
|
3187
3475
|
}
|
|
3188
|
-
|
|
3476
|
+
import_ui_builder_utils24.logger.info(
|
|
3189
3477
|
"loadAbiFromEtherscanV1",
|
|
3190
3478
|
`Successfully parsed ABI for ${networkConfig.name} with ${abi.length} items.`
|
|
3191
3479
|
);
|
|
@@ -3199,17 +3487,17 @@ async function loadAbiFromEtherscanV1(address, networkConfig) {
|
|
|
3199
3487
|
|
|
3200
3488
|
// src/abi/loader.ts
|
|
3201
3489
|
var import_viem5 = require("viem");
|
|
3202
|
-
var
|
|
3490
|
+
var import_ui_builder_utils29 = require("@openzeppelin/ui-builder-utils");
|
|
3203
3491
|
|
|
3204
3492
|
// src/proxy/detection.ts
|
|
3205
3493
|
var import_viem4 = require("viem");
|
|
3206
|
-
var
|
|
3494
|
+
var import_ui_builder_utils27 = require("@openzeppelin/ui-builder-utils");
|
|
3207
3495
|
|
|
3208
3496
|
// src/configuration/execution.ts
|
|
3209
|
-
var
|
|
3497
|
+
var import_ui_builder_utils26 = require("@openzeppelin/ui-builder-utils");
|
|
3210
3498
|
|
|
3211
3499
|
// src/validation/eoa.ts
|
|
3212
|
-
var
|
|
3500
|
+
var import_ui_builder_utils25 = require("@openzeppelin/ui-builder-utils");
|
|
3213
3501
|
var SYSTEM_LOG_TAG = "EoaValidator";
|
|
3214
3502
|
async function validateEoaConfig(config, walletStatus) {
|
|
3215
3503
|
if (!config.allowAny) {
|
|
@@ -3224,7 +3512,7 @@ async function validateEoaConfig(config, walletStatus) {
|
|
|
3224
3512
|
return `Connected wallet address (${walletStatus.address}) does not match the required specific EOA address (${config.specificAddress}). Please connect the correct wallet.`;
|
|
3225
3513
|
}
|
|
3226
3514
|
} else if (walletStatus.isConnected && !walletStatus.address) {
|
|
3227
|
-
|
|
3515
|
+
import_ui_builder_utils25.logger.warn(
|
|
3228
3516
|
SYSTEM_LOG_TAG,
|
|
3229
3517
|
"Wallet is connected but address is unavailable for EOA validation."
|
|
3230
3518
|
);
|
|
@@ -3248,7 +3536,7 @@ async function validateRelayerConfig(config) {
|
|
|
3248
3536
|
// src/configuration/execution.ts
|
|
3249
3537
|
var SYSTEM_LOG_TAG2 = "adapter-evm-execution-config";
|
|
3250
3538
|
async function getEvmSupportedExecutionMethods() {
|
|
3251
|
-
|
|
3539
|
+
import_ui_builder_utils26.logger.warn(
|
|
3252
3540
|
"adapter-evm-execution-config",
|
|
3253
3541
|
"getEvmSupportedExecutionMethods is using placeholder implementation."
|
|
3254
3542
|
);
|
|
@@ -3274,11 +3562,11 @@ async function getEvmSupportedExecutionMethods() {
|
|
|
3274
3562
|
]);
|
|
3275
3563
|
}
|
|
3276
3564
|
async function _validateMultisigConfig(_config, _walletStatus) {
|
|
3277
|
-
|
|
3565
|
+
import_ui_builder_utils26.logger.info(SYSTEM_LOG_TAG2, "Multisig execution config validation: Not yet fully implemented.");
|
|
3278
3566
|
return true;
|
|
3279
3567
|
}
|
|
3280
3568
|
async function validateEvmExecutionConfig(config, walletStatus) {
|
|
3281
|
-
|
|
3569
|
+
import_ui_builder_utils26.logger.info(SYSTEM_LOG_TAG2, "Validating EVM execution config:", { config, walletStatus });
|
|
3282
3570
|
switch (config.method) {
|
|
3283
3571
|
case "eoa":
|
|
3284
3572
|
return validateEoaConfig(config, walletStatus);
|
|
@@ -3288,7 +3576,7 @@ async function validateEvmExecutionConfig(config, walletStatus) {
|
|
|
3288
3576
|
return _validateMultisigConfig(config, walletStatus);
|
|
3289
3577
|
default: {
|
|
3290
3578
|
const unknownMethod = config.method;
|
|
3291
|
-
|
|
3579
|
+
import_ui_builder_utils26.logger.warn(
|
|
3292
3580
|
SYSTEM_LOG_TAG2,
|
|
3293
3581
|
`Unsupported execution method type encountered: ${unknownMethod}`
|
|
3294
3582
|
);
|
|
@@ -3297,130 +3585,6 @@ async function validateEvmExecutionConfig(config, walletStatus) {
|
|
|
3297
3585
|
}
|
|
3298
3586
|
}
|
|
3299
3587
|
|
|
3300
|
-
// src/configuration/rpc.ts
|
|
3301
|
-
var import_ui_builder_utils25 = require("@openzeppelin/ui-builder-utils");
|
|
3302
|
-
function buildRpcUrl(config) {
|
|
3303
|
-
return config.url;
|
|
3304
|
-
}
|
|
3305
|
-
function resolveRpcUrl(networkConfig) {
|
|
3306
|
-
const logSystem = "RpcResolver";
|
|
3307
|
-
const networkId = networkConfig.id;
|
|
3308
|
-
const userRpcConfig = import_ui_builder_utils25.userRpcConfigService.getUserRpcConfig(networkId);
|
|
3309
|
-
if (userRpcConfig) {
|
|
3310
|
-
const userRpcUrl = buildRpcUrl(userRpcConfig);
|
|
3311
|
-
if ((0, import_ui_builder_utils25.isValidUrl)(userRpcUrl)) {
|
|
3312
|
-
import_ui_builder_utils25.logger.info(
|
|
3313
|
-
logSystem,
|
|
3314
|
-
`Using user-configured RPC URL for network ${networkId}: ${userRpcConfig.name || "Custom"}`
|
|
3315
|
-
);
|
|
3316
|
-
return userRpcUrl;
|
|
3317
|
-
} else {
|
|
3318
|
-
import_ui_builder_utils25.logger.warn(
|
|
3319
|
-
logSystem,
|
|
3320
|
-
`User-configured RPC URL for ${networkId} is invalid: ${userRpcUrl}. Falling back.`
|
|
3321
|
-
);
|
|
3322
|
-
}
|
|
3323
|
-
}
|
|
3324
|
-
const rpcOverrideSetting = import_ui_builder_utils25.appConfigService.getRpcEndpointOverride(networkId);
|
|
3325
|
-
let rpcUrlFromOverride;
|
|
3326
|
-
if (typeof rpcOverrideSetting === "string") {
|
|
3327
|
-
rpcUrlFromOverride = rpcOverrideSetting;
|
|
3328
|
-
} else if (typeof rpcOverrideSetting === "object" && rpcOverrideSetting) {
|
|
3329
|
-
if ("url" in rpcOverrideSetting && "isCustom" in rpcOverrideSetting) {
|
|
3330
|
-
const userConfig = rpcOverrideSetting;
|
|
3331
|
-
rpcUrlFromOverride = buildRpcUrl(userConfig);
|
|
3332
|
-
} else if ("http" in rpcOverrideSetting) {
|
|
3333
|
-
rpcUrlFromOverride = rpcOverrideSetting.http;
|
|
3334
|
-
}
|
|
3335
|
-
}
|
|
3336
|
-
if (rpcUrlFromOverride) {
|
|
3337
|
-
import_ui_builder_utils25.logger.info(
|
|
3338
|
-
logSystem,
|
|
3339
|
-
`Using overridden RPC URL for network ${networkId}: ${rpcUrlFromOverride}`
|
|
3340
|
-
);
|
|
3341
|
-
if ((0, import_ui_builder_utils25.isValidUrl)(rpcUrlFromOverride)) {
|
|
3342
|
-
return rpcUrlFromOverride;
|
|
3343
|
-
} else {
|
|
3344
|
-
import_ui_builder_utils25.logger.warn(
|
|
3345
|
-
logSystem,
|
|
3346
|
-
`Overridden RPC URL for ${networkId} is invalid: ${rpcUrlFromOverride}. Falling back.`
|
|
3347
|
-
);
|
|
3348
|
-
}
|
|
3349
|
-
}
|
|
3350
|
-
if (networkConfig.rpcUrl && (0, import_ui_builder_utils25.isValidUrl)(networkConfig.rpcUrl)) {
|
|
3351
|
-
import_ui_builder_utils25.logger.debug(
|
|
3352
|
-
logSystem,
|
|
3353
|
-
`Using default RPC URL for network ${networkId}: ${networkConfig.rpcUrl}`
|
|
3354
|
-
);
|
|
3355
|
-
return networkConfig.rpcUrl;
|
|
3356
|
-
}
|
|
3357
|
-
import_ui_builder_utils25.logger.error(
|
|
3358
|
-
logSystem,
|
|
3359
|
-
`No valid RPC URL could be resolved for network ${networkId}. Checked user config, override, and networkConfig.rpcUrl.`
|
|
3360
|
-
);
|
|
3361
|
-
throw new Error(
|
|
3362
|
-
`No valid RPC URL configured for network ${networkConfig.name} (ID: ${networkId}).`
|
|
3363
|
-
);
|
|
3364
|
-
}
|
|
3365
|
-
function validateEvmRpcEndpoint(rpcConfig) {
|
|
3366
|
-
try {
|
|
3367
|
-
if (!(0, import_ui_builder_utils25.isValidUrl)(rpcConfig.url)) {
|
|
3368
|
-
import_ui_builder_utils25.logger.error("validateEvmRpcEndpoint", `Invalid RPC URL format: ${rpcConfig.url}`);
|
|
3369
|
-
return false;
|
|
3370
|
-
}
|
|
3371
|
-
return true;
|
|
3372
|
-
} catch (error) {
|
|
3373
|
-
import_ui_builder_utils25.logger.error("validateEvmRpcEndpoint", "Error validating RPC endpoint:", error);
|
|
3374
|
-
return false;
|
|
3375
|
-
}
|
|
3376
|
-
}
|
|
3377
|
-
async function testEvmRpcConnection(rpcConfig, timeoutMs = 5e3) {
|
|
3378
|
-
if (!rpcConfig.url) {
|
|
3379
|
-
return { success: false, error: "RPC URL is required" };
|
|
3380
|
-
}
|
|
3381
|
-
const controller = new AbortController();
|
|
3382
|
-
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
3383
|
-
try {
|
|
3384
|
-
const startTime = Date.now();
|
|
3385
|
-
const response = await fetch(rpcConfig.url, {
|
|
3386
|
-
method: "POST",
|
|
3387
|
-
headers: {
|
|
3388
|
-
"Content-Type": "application/json"
|
|
3389
|
-
},
|
|
3390
|
-
body: JSON.stringify({
|
|
3391
|
-
jsonrpc: "2.0",
|
|
3392
|
-
method: "eth_blockNumber",
|
|
3393
|
-
params: [],
|
|
3394
|
-
id: 1
|
|
3395
|
-
}),
|
|
3396
|
-
signal: controller.signal
|
|
3397
|
-
});
|
|
3398
|
-
if (!response.ok) {
|
|
3399
|
-
return { success: false, error: `HTTP error: ${response.status}` };
|
|
3400
|
-
}
|
|
3401
|
-
const data = await response.json();
|
|
3402
|
-
const latency = Date.now() - startTime;
|
|
3403
|
-
if (data.error) {
|
|
3404
|
-
return { success: false, error: data.error.message || "RPC error" };
|
|
3405
|
-
}
|
|
3406
|
-
return { success: true, latency };
|
|
3407
|
-
} catch (error) {
|
|
3408
|
-
import_ui_builder_utils25.logger.error("testEvmRpcConnection", "Connection test failed:", error);
|
|
3409
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
3410
|
-
return {
|
|
3411
|
-
success: false,
|
|
3412
|
-
error: `Connection timeout after ${timeoutMs}ms`
|
|
3413
|
-
};
|
|
3414
|
-
}
|
|
3415
|
-
return {
|
|
3416
|
-
success: false,
|
|
3417
|
-
error: error instanceof Error ? error.message : "Connection failed"
|
|
3418
|
-
};
|
|
3419
|
-
} finally {
|
|
3420
|
-
clearTimeout(timeoutId);
|
|
3421
|
-
}
|
|
3422
|
-
}
|
|
3423
|
-
|
|
3424
3588
|
// src/proxy/detection.ts
|
|
3425
3589
|
function detectProxyFromAbi(abi) {
|
|
3426
3590
|
const functions = abi.filter((item) => item.type === "function");
|
|
@@ -3511,7 +3675,7 @@ function detectProxyFromAbi(abi) {
|
|
|
3511
3675
|
};
|
|
3512
3676
|
}
|
|
3513
3677
|
async function getImplementationAddress(proxyAddress, networkConfig, proxyType) {
|
|
3514
|
-
|
|
3678
|
+
import_ui_builder_utils27.logger.info(
|
|
3515
3679
|
"getImplementationAddress",
|
|
3516
3680
|
`Resolving implementation for ${proxyType} proxy: ${proxyAddress}`
|
|
3517
3681
|
);
|
|
@@ -3528,7 +3692,7 @@ async function getImplementationAddress(proxyAddress, networkConfig, proxyType)
|
|
|
3528
3692
|
case "beacon":
|
|
3529
3693
|
return await getBeaconImplementation(proxyAddress, networkConfig);
|
|
3530
3694
|
case "diamond":
|
|
3531
|
-
|
|
3695
|
+
import_ui_builder_utils27.logger.info("getImplementationAddress", "Diamond proxies not fully supported yet");
|
|
3532
3696
|
return null;
|
|
3533
3697
|
case "minimal":
|
|
3534
3698
|
return await getMinimalProxyImplementation(proxyAddress, networkConfig);
|
|
@@ -3536,7 +3700,7 @@ async function getImplementationAddress(proxyAddress, networkConfig, proxyType)
|
|
|
3536
3700
|
return await tryCommonImplementationMethods(proxyAddress, networkConfig);
|
|
3537
3701
|
}
|
|
3538
3702
|
} catch (error) {
|
|
3539
|
-
|
|
3703
|
+
import_ui_builder_utils27.logger.warn("getImplementationAddress", `Failed to resolve implementation: ${error}`);
|
|
3540
3704
|
return null;
|
|
3541
3705
|
}
|
|
3542
3706
|
}
|
|
@@ -3548,7 +3712,7 @@ async function getAdminAddress(proxyAddress, networkConfig) {
|
|
|
3548
3712
|
if (legacyAdmin) return legacyAdmin;
|
|
3549
3713
|
return null;
|
|
3550
3714
|
} catch (error) {
|
|
3551
|
-
|
|
3715
|
+
import_ui_builder_utils27.logger.warn("getAdminAddress", `Failed to resolve admin: ${error}`);
|
|
3552
3716
|
return null;
|
|
3553
3717
|
}
|
|
3554
3718
|
}
|
|
@@ -3563,20 +3727,20 @@ async function getEIP1967Admin(proxyAddress, networkConfig) {
|
|
|
3563
3727
|
async function getLegacyOZAdmin(proxyAddress, networkConfig) {
|
|
3564
3728
|
try {
|
|
3565
3729
|
const slot = (0, import_viem4.keccak256)((0, import_viem4.toHex)("org.zeppelinos.proxy.admin"));
|
|
3566
|
-
|
|
3730
|
+
import_ui_builder_utils27.logger.info("getLegacyOZAdmin", `Trying legacy OZ admin slot: ${slot}`);
|
|
3567
3731
|
return await readStorageSlot(proxyAddress, slot, networkConfig);
|
|
3568
3732
|
} catch (error) {
|
|
3569
|
-
|
|
3733
|
+
import_ui_builder_utils27.logger.warn("getLegacyOZAdmin", `Failed computing or reading legacy admin slot: ${error}`);
|
|
3570
3734
|
return null;
|
|
3571
3735
|
}
|
|
3572
3736
|
}
|
|
3573
3737
|
async function getLegacyOZImplementation(proxyAddress, networkConfig) {
|
|
3574
3738
|
try {
|
|
3575
3739
|
const slot = (0, import_viem4.keccak256)((0, import_viem4.toHex)("org.zeppelinos.proxy.implementation"));
|
|
3576
|
-
|
|
3740
|
+
import_ui_builder_utils27.logger.info("getLegacyOZImplementation", `Trying legacy OZ slot: ${slot}`);
|
|
3577
3741
|
return await readStorageSlot(proxyAddress, slot, networkConfig);
|
|
3578
3742
|
} catch (error) {
|
|
3579
|
-
|
|
3743
|
+
import_ui_builder_utils27.logger.warn("getLegacyOZImplementation", `Failed computing or reading legacy slot: ${error}`);
|
|
3580
3744
|
return null;
|
|
3581
3745
|
}
|
|
3582
3746
|
}
|
|
@@ -3600,7 +3764,7 @@ async function getMinimalProxyImplementation(proxyAddress, networkConfig) {
|
|
|
3600
3764
|
}
|
|
3601
3765
|
return null;
|
|
3602
3766
|
} catch (error) {
|
|
3603
|
-
|
|
3767
|
+
import_ui_builder_utils27.logger.warn("getMinimalProxyImplementation", `Error reading bytecode: ${error}`);
|
|
3604
3768
|
return null;
|
|
3605
3769
|
}
|
|
3606
3770
|
}
|
|
@@ -3615,7 +3779,7 @@ async function tryCommonImplementationMethods(proxyAddress, networkConfig) {
|
|
|
3615
3779
|
try {
|
|
3616
3780
|
const result = await callContractFunction(proxyAddress, method, [], networkConfig);
|
|
3617
3781
|
if (result && result !== "0x0000000000000000000000000000000000000000") {
|
|
3618
|
-
|
|
3782
|
+
import_ui_builder_utils27.logger.info(
|
|
3619
3783
|
"tryCommonImplementationMethods",
|
|
3620
3784
|
`Found implementation via ${method}: ${result}`
|
|
3621
3785
|
);
|
|
@@ -3641,13 +3805,13 @@ async function readStorageSlot(address, slot, networkConfig) {
|
|
|
3641
3805
|
slot
|
|
3642
3806
|
});
|
|
3643
3807
|
if (storageValue && storageValue !== "0x0000000000000000000000000000000000000000000000000000000000000000") {
|
|
3644
|
-
|
|
3808
|
+
import_ui_builder_utils27.logger.info("readStorageSlot", `Found non-zero value at slot ${slot}: ${storageValue}`);
|
|
3645
3809
|
const implAddress = "0x" + storageValue.slice(-40);
|
|
3646
3810
|
return implAddress;
|
|
3647
3811
|
}
|
|
3648
3812
|
return null;
|
|
3649
3813
|
} catch (error) {
|
|
3650
|
-
|
|
3814
|
+
import_ui_builder_utils27.logger.warn("readStorageSlot", `Failed to read storage slot ${slot}: ${error}`);
|
|
3651
3815
|
return null;
|
|
3652
3816
|
}
|
|
3653
3817
|
}
|
|
@@ -3668,7 +3832,7 @@ async function callContractFunction(address, signature, params, networkConfig) {
|
|
|
3668
3832
|
}
|
|
3669
3833
|
return null;
|
|
3670
3834
|
} catch (error) {
|
|
3671
|
-
|
|
3835
|
+
import_ui_builder_utils27.logger.warn("callContractFunction", `Failed to call ${signature}: ${error}`);
|
|
3672
3836
|
return null;
|
|
3673
3837
|
}
|
|
3674
3838
|
}
|
|
@@ -3680,17 +3844,16 @@ async function getContractBytecode(address, networkConfig) {
|
|
|
3680
3844
|
});
|
|
3681
3845
|
return bytecode || null;
|
|
3682
3846
|
} catch (error) {
|
|
3683
|
-
|
|
3847
|
+
import_ui_builder_utils27.logger.warn("getContractBytecode", `Failed to get bytecode: ${error}`);
|
|
3684
3848
|
return null;
|
|
3685
3849
|
}
|
|
3686
3850
|
}
|
|
3687
3851
|
|
|
3688
3852
|
// src/abi/sourcify.ts
|
|
3689
|
-
var
|
|
3690
|
-
var SOURCIFY_APP_BASE = "https://sourcify.dev";
|
|
3853
|
+
var import_ui_builder_utils28 = require("@openzeppelin/ui-builder-utils");
|
|
3854
|
+
var SOURCIFY_APP_BASE = "https://repo.sourcify.dev";
|
|
3691
3855
|
function getSourcifyContractAppUrl(chainId, address) {
|
|
3692
|
-
|
|
3693
|
-
return `${SOURCIFY_APP_BASE}/status/${chainId}/${normalizedAddress}`;
|
|
3856
|
+
return `${SOURCIFY_APP_BASE}/${chainId}/${address}`;
|
|
3694
3857
|
}
|
|
3695
3858
|
var SOURCIFY_API_BASE = "https://sourcify.dev/server/v2";
|
|
3696
3859
|
function buildSourcifyApiUrl(chainId, address) {
|
|
@@ -3705,7 +3868,7 @@ async function loadAbiFromSourcify(address, networkConfig, timeoutMs = 4e3) {
|
|
|
3705
3868
|
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
3706
3869
|
try {
|
|
3707
3870
|
const url = buildSourcifyApiUrl(networkConfig.chainId, address);
|
|
3708
|
-
|
|
3871
|
+
import_ui_builder_utils28.logger.info("loadAbiFromSourcify", `Fetching contract from ${url}`);
|
|
3709
3872
|
const response = await fetch(url, { signal: controller.signal });
|
|
3710
3873
|
if (!response.ok) {
|
|
3711
3874
|
throw new Error(`Sourcify request failed: ${response.status} ${response.statusText}`);
|
|
@@ -3720,7 +3883,7 @@ async function loadAbiFromSourcify(address, networkConfig, timeoutMs = 4e3) {
|
|
|
3720
3883
|
const schema = transformAbiToSchema(abi, contractName, address);
|
|
3721
3884
|
return { schema, originalAbi: JSON.stringify(abi) };
|
|
3722
3885
|
} catch (error) {
|
|
3723
|
-
|
|
3886
|
+
import_ui_builder_utils28.logger.warn("loadAbiFromSourcify", `Failed to fetch ABI from Sourcify: ${String(error)}`);
|
|
3724
3887
|
throw error;
|
|
3725
3888
|
} finally {
|
|
3726
3889
|
clearTimeout(timeout);
|
|
@@ -3728,9 +3891,6 @@ async function loadAbiFromSourcify(address, networkConfig, timeoutMs = 4e3) {
|
|
|
3728
3891
|
}
|
|
3729
3892
|
|
|
3730
3893
|
// src/abi/loader.ts
|
|
3731
|
-
function hasDefaultProvider(config) {
|
|
3732
|
-
return config !== null && typeof config === "object" && "defaultProvider" in config;
|
|
3733
|
-
}
|
|
3734
3894
|
async function loadAbiFromJson(abiJsonString) {
|
|
3735
3895
|
let abi;
|
|
3736
3896
|
try {
|
|
@@ -3739,10 +3899,10 @@ async function loadAbiFromJson(abiJsonString) {
|
|
|
3739
3899
|
throw new Error("Parsed JSON is not an array.");
|
|
3740
3900
|
}
|
|
3741
3901
|
} catch (error) {
|
|
3742
|
-
|
|
3902
|
+
import_ui_builder_utils29.logger.error("loadAbiFromJson", "Failed to parse source string as JSON ABI:", error);
|
|
3743
3903
|
throw new Error(`Invalid JSON ABI provided: ${error.message}`);
|
|
3744
3904
|
}
|
|
3745
|
-
|
|
3905
|
+
import_ui_builder_utils29.logger.info("loadAbiFromJson", `Successfully parsed JSON ABI with ${abi.length} items.`);
|
|
3746
3906
|
const contractName = "ContractFromABI";
|
|
3747
3907
|
return transformAbiToSchema(abi, contractName, void 0);
|
|
3748
3908
|
}
|
|
@@ -3761,7 +3921,7 @@ async function loadEvmContract(artifacts, networkConfig, options = {}) {
|
|
|
3761
3921
|
const trimmed = contractDefinition.trim();
|
|
3762
3922
|
const hasJsonContent = trimmed.includes("[") && trimmed.includes("]") && trimmed.includes("{");
|
|
3763
3923
|
if (hasJsonContent) {
|
|
3764
|
-
|
|
3924
|
+
import_ui_builder_utils29.logger.info("loadEvmContract", "Manual contract definition provided. Attempting to parse...");
|
|
3765
3925
|
try {
|
|
3766
3926
|
const schema = await loadAbiFromJson(contractDefinition);
|
|
3767
3927
|
return {
|
|
@@ -3777,14 +3937,14 @@ async function loadEvmContract(artifacts, networkConfig, options = {}) {
|
|
|
3777
3937
|
// Note: No proxy detection for manual ABIs - user provides what they want
|
|
3778
3938
|
};
|
|
3779
3939
|
} catch (error) {
|
|
3780
|
-
|
|
3940
|
+
import_ui_builder_utils29.logger.error("loadEvmContract", "Failed to parse manually provided ABI:", error);
|
|
3781
3941
|
throw new Error(`The provided ABI JSON is invalid: ${error.message}`);
|
|
3782
3942
|
}
|
|
3783
3943
|
}
|
|
3784
3944
|
}
|
|
3785
3945
|
const forcedRaw = artifacts.__forcedProvider || artifacts.service;
|
|
3786
3946
|
const forcedProvider = isEvmProviderKey(forcedRaw) ? forcedRaw : null;
|
|
3787
|
-
|
|
3947
|
+
import_ui_builder_utils29.logger.info(
|
|
3788
3948
|
"loadEvmContract",
|
|
3789
3949
|
`No manual ABI detected. Attempting Etherscan fetch for address: ${contractAddress}...`
|
|
3790
3950
|
);
|
|
@@ -3813,7 +3973,7 @@ function buildContractResult(contractAddress, abiResult, networkConfig, sourcePr
|
|
|
3813
3973
|
contractName: abiResult.schema.name,
|
|
3814
3974
|
verificationStatus: "verified",
|
|
3815
3975
|
fetchTimestamp: /* @__PURE__ */ new Date(),
|
|
3816
|
-
definitionHash: (0,
|
|
3976
|
+
definitionHash: (0, import_ui_builder_utils29.simpleHash)(abiResult.originalAbi)
|
|
3817
3977
|
},
|
|
3818
3978
|
proxyInfo
|
|
3819
3979
|
};
|
|
@@ -3821,13 +3981,13 @@ function buildContractResult(contractAddress, abiResult, networkConfig, sourcePr
|
|
|
3821
3981
|
async function loadImplementationAbi(_contractAddress, implementationAddress, networkConfig, _proxyType) {
|
|
3822
3982
|
try {
|
|
3823
3983
|
const implementationResult = await loadAbiFromEtherscan(implementationAddress, networkConfig);
|
|
3824
|
-
|
|
3984
|
+
import_ui_builder_utils29.logger.info(
|
|
3825
3985
|
"loadImplementationAbi",
|
|
3826
3986
|
`Successfully fetched implementation ABI with ${implementationResult.schema.functions.length} functions`
|
|
3827
3987
|
);
|
|
3828
3988
|
return implementationResult;
|
|
3829
3989
|
} catch (implementationError) {
|
|
3830
|
-
|
|
3990
|
+
import_ui_builder_utils29.logger.warn(
|
|
3831
3991
|
"loadImplementationAbi",
|
|
3832
3992
|
`Failed to load implementation ABI: ${implementationError}`
|
|
3833
3993
|
);
|
|
@@ -3840,7 +4000,7 @@ async function handleProxyDetection(contractAddress, initialResult, networkConfi
|
|
|
3840
4000
|
if (!proxyDetection.isProxy) {
|
|
3841
4001
|
return null;
|
|
3842
4002
|
}
|
|
3843
|
-
|
|
4003
|
+
import_ui_builder_utils29.logger.info(
|
|
3844
4004
|
"handleProxyDetection",
|
|
3845
4005
|
`Proxy detected: ${proxyDetection.proxyType} (confidence: ${proxyDetection.confidence})`
|
|
3846
4006
|
);
|
|
@@ -3852,7 +4012,7 @@ async function handleProxyDetection(contractAddress, initialResult, networkConfi
|
|
|
3852
4012
|
);
|
|
3853
4013
|
const adminAddress = await getAdminAddress(contractAddress, networkConfig);
|
|
3854
4014
|
if (!implementationAddress) {
|
|
3855
|
-
|
|
4015
|
+
import_ui_builder_utils29.logger.info("handleProxyDetection", "Proxy detected but implementation address not found");
|
|
3856
4016
|
return buildContractResult(contractAddress, initialResult, networkConfig, initialProvider, {
|
|
3857
4017
|
isProxy: true,
|
|
3858
4018
|
proxyType,
|
|
@@ -3860,7 +4020,7 @@ async function handleProxyDetection(contractAddress, initialResult, networkConfi
|
|
|
3860
4020
|
detectionMethod: "automatic"
|
|
3861
4021
|
});
|
|
3862
4022
|
}
|
|
3863
|
-
|
|
4023
|
+
import_ui_builder_utils29.logger.info("handleProxyDetection", `Found implementation at: ${implementationAddress}`);
|
|
3864
4024
|
const implementationResult = await loadImplementationAbi(
|
|
3865
4025
|
contractAddress,
|
|
3866
4026
|
implementationAddress,
|
|
@@ -3895,9 +4055,13 @@ async function handleProxyDetection(contractAddress, initialResult, networkConfi
|
|
|
3895
4055
|
}
|
|
3896
4056
|
async function loadContractWithProxyDetection(contractAddress, networkConfig, options = {}, forcedProvider = null) {
|
|
3897
4057
|
try {
|
|
3898
|
-
|
|
3899
|
-
const
|
|
3900
|
-
|
|
4058
|
+
let uiDefault = null;
|
|
4059
|
+
const svcCfg = import_ui_builder_utils29.userNetworkServiceConfigService.get(networkConfig.id, "contract-definitions");
|
|
4060
|
+
if (svcCfg && typeof svcCfg === "object" && "defaultProvider" in svcCfg) {
|
|
4061
|
+
const raw = svcCfg.defaultProvider;
|
|
4062
|
+
if (isEvmProviderKey(raw)) uiDefault = raw;
|
|
4063
|
+
}
|
|
4064
|
+
const appDefaultRaw = import_ui_builder_utils29.appConfigService.getGlobalServiceParam(
|
|
3901
4065
|
"contractdefinition",
|
|
3902
4066
|
"defaultProvider"
|
|
3903
4067
|
);
|
|
@@ -3916,13 +4080,13 @@ async function loadContractWithProxyDetection(contractAddress, networkConfig, op
|
|
|
3916
4080
|
const remainingOverall = Math.max(100, overallDeadline - Date.now());
|
|
3917
4081
|
const attemptTimeout = Math.min(PER_PROVIDER_TIMEOUT_MS, remainingOverall);
|
|
3918
4082
|
if (provider === EvmProviderKeys.Etherscan) {
|
|
3919
|
-
initialResult = await (0,
|
|
4083
|
+
initialResult = await (0, import_ui_builder_utils29.withTimeout)(
|
|
3920
4084
|
loadAbiFromEtherscan(contractAddress, networkConfig),
|
|
3921
4085
|
attemptTimeout,
|
|
3922
4086
|
"etherscan"
|
|
3923
4087
|
);
|
|
3924
4088
|
} else if (provider === EvmProviderKeys.Sourcify) {
|
|
3925
|
-
initialResult = await (0,
|
|
4089
|
+
initialResult = await (0, import_ui_builder_utils29.withTimeout)(
|
|
3926
4090
|
loadAbiFromSourcify(contractAddress, networkConfig, attemptTimeout),
|
|
3927
4091
|
attemptTimeout,
|
|
3928
4092
|
"sourcify"
|
|
@@ -3938,7 +4102,7 @@ async function loadContractWithProxyDetection(contractAddress, networkConfig, op
|
|
|
3938
4102
|
}
|
|
3939
4103
|
}
|
|
3940
4104
|
if (!initialResult) throw lastError ?? new Error("No provider succeeded");
|
|
3941
|
-
|
|
4105
|
+
import_ui_builder_utils29.logger.info(
|
|
3942
4106
|
"loadContractWithProxyDetection",
|
|
3943
4107
|
`Successfully fetched initial ABI for ${contractAddress} with ${initialResult.schema.functions.length} functions`
|
|
3944
4108
|
);
|
|
@@ -3955,7 +4119,7 @@ async function loadContractWithProxyDetection(contractAddress, networkConfig, op
|
|
|
3955
4119
|
}
|
|
3956
4120
|
return buildContractResult(contractAddress, initialResult, networkConfig, usedProvider);
|
|
3957
4121
|
} catch (error) {
|
|
3958
|
-
|
|
4122
|
+
import_ui_builder_utils29.logger.warn("loadContractWithProxyDetection", `Contract loading failed: ${error}`);
|
|
3959
4123
|
if (forcedProvider) {
|
|
3960
4124
|
throw error;
|
|
3961
4125
|
}
|
|
@@ -4043,7 +4207,7 @@ function getEvmCompatibleFieldTypes(parameterType) {
|
|
|
4043
4207
|
|
|
4044
4208
|
// src/mapping/field-generator.ts
|
|
4045
4209
|
var import_lodash = require("lodash");
|
|
4046
|
-
var
|
|
4210
|
+
var import_ui_builder_utils30 = require("@openzeppelin/ui-builder-utils");
|
|
4047
4211
|
function extractArrayElementType(parameterType) {
|
|
4048
4212
|
const arrayMatch = parameterType.match(/^(.+)\[\d*\]$/);
|
|
4049
4213
|
if (arrayMatch) {
|
|
@@ -4064,7 +4228,7 @@ function generateEvmDefaultField(parameter) {
|
|
|
4064
4228
|
type: fieldType,
|
|
4065
4229
|
placeholder: `Enter ${parameter.displayName || parameter.name || parameter.type}`,
|
|
4066
4230
|
helperText: parameter.description || "",
|
|
4067
|
-
defaultValue: (0,
|
|
4231
|
+
defaultValue: (0, import_ui_builder_utils30.getDefaultValueForType)(fieldType),
|
|
4068
4232
|
validation: getDefaultValidation(),
|
|
4069
4233
|
width: "full"
|
|
4070
4234
|
};
|
|
@@ -4101,11 +4265,11 @@ function isEvmViewFunction(functionDetails) {
|
|
|
4101
4265
|
|
|
4102
4266
|
// src/query/handler.ts
|
|
4103
4267
|
var import_viem7 = require("viem");
|
|
4104
|
-
var
|
|
4268
|
+
var import_ui_builder_utils33 = require("@openzeppelin/ui-builder-utils");
|
|
4105
4269
|
|
|
4106
4270
|
// src/transform/input-parser.ts
|
|
4107
4271
|
var import_viem6 = require("viem");
|
|
4108
|
-
var
|
|
4272
|
+
var import_ui_builder_utils31 = require("@openzeppelin/ui-builder-utils");
|
|
4109
4273
|
function parseEvmInput(param, rawValue, isRecursive = false) {
|
|
4110
4274
|
const { type, name } = param;
|
|
4111
4275
|
const baseType = type.replace(/\[\d*\]$/, "");
|
|
@@ -4223,7 +4387,7 @@ function parseEvmInput(param, rawValue, isRecursive = false) {
|
|
|
4223
4387
|
} else if (baseType === "string") {
|
|
4224
4388
|
return String(rawValue);
|
|
4225
4389
|
}
|
|
4226
|
-
|
|
4390
|
+
import_ui_builder_utils31.logger.warn(
|
|
4227
4391
|
"parseEvmInput",
|
|
4228
4392
|
`Unknown EVM parameter type encountered: '${type}'. Using raw value.`
|
|
4229
4393
|
);
|
|
@@ -4236,10 +4400,10 @@ function parseEvmInput(param, rawValue, isRecursive = false) {
|
|
|
4236
4400
|
}
|
|
4237
4401
|
|
|
4238
4402
|
// src/transform/output-formatter.ts
|
|
4239
|
-
var
|
|
4403
|
+
var import_ui_builder_utils32 = require("@openzeppelin/ui-builder-utils");
|
|
4240
4404
|
function formatEvmFunctionResult(decodedValue, functionDetails) {
|
|
4241
4405
|
if (!functionDetails.outputs || !Array.isArray(functionDetails.outputs)) {
|
|
4242
|
-
|
|
4406
|
+
import_ui_builder_utils32.logger.warn(
|
|
4243
4407
|
"formatEvmFunctionResult",
|
|
4244
4408
|
`Output ABI definition missing or invalid for function ${functionDetails.name}.`
|
|
4245
4409
|
);
|
|
@@ -4267,7 +4431,7 @@ function formatEvmFunctionResult(decodedValue, functionDetails) {
|
|
|
4267
4431
|
}
|
|
4268
4432
|
} catch (error) {
|
|
4269
4433
|
const errorMessage = `Error formatting result for ${functionDetails.name}: ${error.message}`;
|
|
4270
|
-
|
|
4434
|
+
import_ui_builder_utils32.logger.error("formatEvmFunctionResult", errorMessage, {
|
|
4271
4435
|
functionName: functionDetails.name,
|
|
4272
4436
|
decodedValue,
|
|
4273
4437
|
error
|
|
@@ -4278,8 +4442,7 @@ function formatEvmFunctionResult(decodedValue, functionDetails) {
|
|
|
4278
4442
|
|
|
4279
4443
|
// src/query/handler.ts
|
|
4280
4444
|
async function getPublicClientForQuery(walletImplementation, networkConfig) {
|
|
4281
|
-
|
|
4282
|
-
if (customRpcConfig) {
|
|
4445
|
+
if (getUserRpcUrl(networkConfig.id)) {
|
|
4283
4446
|
const resolvedRpc2 = resolveRpcUrl(networkConfig);
|
|
4284
4447
|
return createPublicClientWithRpc(networkConfig, resolvedRpc2);
|
|
4285
4448
|
}
|
|
@@ -4291,14 +4454,14 @@ async function getPublicClientForQuery(walletImplementation, networkConfig) {
|
|
|
4291
4454
|
if (clientFromWallet) {
|
|
4292
4455
|
return clientFromWallet;
|
|
4293
4456
|
} else {
|
|
4294
|
-
|
|
4457
|
+
import_ui_builder_utils33.logger.warn(
|
|
4295
4458
|
"getPublicClientForQuery",
|
|
4296
4459
|
`Could not get public client from connected wallet for chain ${walletChainId}. Falling back.`
|
|
4297
4460
|
);
|
|
4298
4461
|
}
|
|
4299
4462
|
}
|
|
4300
4463
|
const resolvedRpc = resolveRpcUrl(networkConfig);
|
|
4301
|
-
|
|
4464
|
+
import_ui_builder_utils33.logger.info(
|
|
4302
4465
|
"getPublicClientForQuery",
|
|
4303
4466
|
`Wallet not connected/on wrong chain OR failed to get wallet client. Creating dedicated public client for query on ${networkConfig.name} using RPC: ${resolvedRpc}`
|
|
4304
4467
|
);
|
|
@@ -4309,7 +4472,7 @@ function createPublicClientWithRpc(networkConfig, rpcUrl) {
|
|
|
4309
4472
|
if (networkConfig.viemChain) {
|
|
4310
4473
|
chainForViem = networkConfig.viemChain;
|
|
4311
4474
|
} else {
|
|
4312
|
-
|
|
4475
|
+
import_ui_builder_utils33.logger.warn(
|
|
4313
4476
|
"createPublicClientWithRpc",
|
|
4314
4477
|
`Viem chain object (viemChain) not provided in EvmNetworkConfig for ${networkConfig.name} (query). Creating a minimal one.`
|
|
4315
4478
|
);
|
|
@@ -4336,7 +4499,7 @@ function createPublicClientWithRpc(networkConfig, rpcUrl) {
|
|
|
4336
4499
|
});
|
|
4337
4500
|
return publicClient;
|
|
4338
4501
|
} catch (error) {
|
|
4339
|
-
|
|
4502
|
+
import_ui_builder_utils33.logger.error(
|
|
4340
4503
|
"createPublicClientWithRpc",
|
|
4341
4504
|
"Failed to create network-specific public client for query:",
|
|
4342
4505
|
error
|
|
@@ -4347,7 +4510,7 @@ function createPublicClientWithRpc(networkConfig, rpcUrl) {
|
|
|
4347
4510
|
}
|
|
4348
4511
|
}
|
|
4349
4512
|
async function queryEvmViewFunction(contractAddress, functionId, networkConfig, params, contractSchema, walletImplementation, loadContractFn) {
|
|
4350
|
-
|
|
4513
|
+
import_ui_builder_utils33.logger.info(
|
|
4351
4514
|
"queryEvmViewFunction",
|
|
4352
4515
|
`Querying view function: ${functionId} on ${contractAddress} (${networkConfig.name})`,
|
|
4353
4516
|
{ params }
|
|
@@ -4378,9 +4541,9 @@ async function queryEvmViewFunction(contractAddress, functionId, networkConfig,
|
|
|
4378
4541
|
}
|
|
4379
4542
|
return parseEvmInput(inputParam, rawValue, false);
|
|
4380
4543
|
});
|
|
4381
|
-
|
|
4544
|
+
import_ui_builder_utils33.logger.debug("queryEvmViewFunction", "Parsed Args for readContract:", args);
|
|
4382
4545
|
const functionAbiItem = createAbiFunctionItem(functionDetails);
|
|
4383
|
-
|
|
4546
|
+
import_ui_builder_utils33.logger.debug(
|
|
4384
4547
|
"queryEvmViewFunction",
|
|
4385
4548
|
`[Query ${functionDetails.name}] Calling readContract with ABI:`,
|
|
4386
4549
|
functionAbiItem,
|
|
@@ -4396,7 +4559,7 @@ async function queryEvmViewFunction(contractAddress, functionId, networkConfig,
|
|
|
4396
4559
|
args
|
|
4397
4560
|
});
|
|
4398
4561
|
} catch (readError) {
|
|
4399
|
-
|
|
4562
|
+
import_ui_builder_utils33.logger.error(
|
|
4400
4563
|
"queryEvmViewFunction",
|
|
4401
4564
|
`[Query ${functionDetails.name}] publicClient.readContract specific error:`,
|
|
4402
4565
|
readError
|
|
@@ -4405,7 +4568,7 @@ async function queryEvmViewFunction(contractAddress, functionId, networkConfig,
|
|
|
4405
4568
|
`Viem readContract failed for ${functionDetails.name}: ${readError.message}`
|
|
4406
4569
|
);
|
|
4407
4570
|
}
|
|
4408
|
-
|
|
4571
|
+
import_ui_builder_utils33.logger.debug(
|
|
4409
4572
|
"queryEvmViewFunction",
|
|
4410
4573
|
`[Query ${functionDetails.name}] Raw decoded result:`,
|
|
4411
4574
|
decodedResult
|
|
@@ -4413,7 +4576,7 @@ async function queryEvmViewFunction(contractAddress, functionId, networkConfig,
|
|
|
4413
4576
|
return decodedResult;
|
|
4414
4577
|
} catch (error) {
|
|
4415
4578
|
const errorMessage = `Failed to query view function ${functionId} on network ${networkConfig.name}: ${error.message}`;
|
|
4416
|
-
|
|
4579
|
+
import_ui_builder_utils33.logger.error("queryEvmViewFunction", errorMessage, {
|
|
4417
4580
|
contractAddress,
|
|
4418
4581
|
functionId,
|
|
4419
4582
|
params,
|
|
@@ -4427,7 +4590,7 @@ async function queryEvmViewFunction(contractAddress, functionId, networkConfig,
|
|
|
4427
4590
|
// src/transaction/relayer.ts
|
|
4428
4591
|
var import_viem8 = require("viem");
|
|
4429
4592
|
var import_relayer_sdk = require("@openzeppelin/relayer-sdk");
|
|
4430
|
-
var
|
|
4593
|
+
var import_ui_builder_utils34 = require("@openzeppelin/ui-builder-utils");
|
|
4431
4594
|
var RelayerExecutionStrategy = class {
|
|
4432
4595
|
async execute(transactionData, executionConfig, _walletImplementation, onStatusChange, runtimeApiKey) {
|
|
4433
4596
|
const relayerConfig = executionConfig;
|
|
@@ -4462,7 +4625,7 @@ var RelayerExecutionStrategy = class {
|
|
|
4462
4625
|
* @throws If the API call fails or returns an unsuccessful response.
|
|
4463
4626
|
*/
|
|
4464
4627
|
async getEvmRelayers(serviceUrl, accessToken, networkConfig) {
|
|
4465
|
-
|
|
4628
|
+
import_ui_builder_utils34.logger.info(
|
|
4466
4629
|
"[Relayer] Getting relayers with access token",
|
|
4467
4630
|
accessToken.slice(0, 5).padEnd(accessToken.length, "*")
|
|
4468
4631
|
);
|
|
@@ -4510,7 +4673,7 @@ var RelayerExecutionStrategy = class {
|
|
|
4510
4673
|
* @throws If any API call fails or returns an unsuccessful response.
|
|
4511
4674
|
*/
|
|
4512
4675
|
async getEvmRelayer(serviceUrl, accessToken, relayerId, networkConfig) {
|
|
4513
|
-
|
|
4676
|
+
import_ui_builder_utils34.logger.info("[Relayer] Getting detailed relayer info", relayerId);
|
|
4514
4677
|
const sdkConfig = new import_relayer_sdk.Configuration({
|
|
4515
4678
|
basePath: serviceUrl,
|
|
4516
4679
|
accessToken
|
|
@@ -4520,11 +4683,11 @@ var RelayerExecutionStrategy = class {
|
|
|
4520
4683
|
const [relayerResponse, balanceResponse, statusResponse] = await Promise.all([
|
|
4521
4684
|
relayersApi.getRelayer(relayerId),
|
|
4522
4685
|
relayersApi.getRelayerBalance(relayerId).catch((err) => {
|
|
4523
|
-
|
|
4686
|
+
import_ui_builder_utils34.logger.warn("[Relayer] Failed to fetch balance", err);
|
|
4524
4687
|
return null;
|
|
4525
4688
|
}),
|
|
4526
4689
|
relayersApi.getRelayerStatus(relayerId).catch((err) => {
|
|
4527
|
-
|
|
4690
|
+
import_ui_builder_utils34.logger.warn("[Relayer] Failed to fetch status", err);
|
|
4528
4691
|
return null;
|
|
4529
4692
|
})
|
|
4530
4693
|
]);
|
|
@@ -4547,7 +4710,7 @@ var RelayerExecutionStrategy = class {
|
|
|
4547
4710
|
const currencySymbol = networkConfig.nativeCurrency.symbol;
|
|
4548
4711
|
enhancedDetails.balance = `${balanceInEth} ${currencySymbol}`;
|
|
4549
4712
|
} catch (error) {
|
|
4550
|
-
|
|
4713
|
+
import_ui_builder_utils34.logger.warn("[Relayer] Failed to format balance, using raw value", String(error));
|
|
4551
4714
|
enhancedDetails.balance = String(balanceResponse.data.data.balance);
|
|
4552
4715
|
}
|
|
4553
4716
|
}
|
|
@@ -4565,10 +4728,10 @@ var RelayerExecutionStrategy = class {
|
|
|
4565
4728
|
}
|
|
4566
4729
|
}
|
|
4567
4730
|
}
|
|
4568
|
-
|
|
4731
|
+
import_ui_builder_utils34.logger.info("[Relayer] Retrieved enhanced relayer details", JSON.stringify(enhancedDetails));
|
|
4569
4732
|
return enhancedDetails;
|
|
4570
4733
|
} catch (error) {
|
|
4571
|
-
|
|
4734
|
+
import_ui_builder_utils34.logger.error(
|
|
4572
4735
|
"[Relayer] Failed to get relayer details",
|
|
4573
4736
|
error instanceof Error ? error.message : String(error)
|
|
4574
4737
|
);
|
|
@@ -4593,7 +4756,7 @@ var RelayerExecutionStrategy = class {
|
|
|
4593
4756
|
let valueNumber = 0;
|
|
4594
4757
|
const MAX_SAFE = BigInt(Number.MAX_SAFE_INTEGER);
|
|
4595
4758
|
if (valueBigint > MAX_SAFE) {
|
|
4596
|
-
|
|
4759
|
+
import_ui_builder_utils34.logger.warn(
|
|
4597
4760
|
"[Relayer] Value exceeds JS safe integer. Truncating for request.",
|
|
4598
4761
|
valueBigint.toString()
|
|
4599
4762
|
);
|
|
@@ -4608,7 +4771,7 @@ var RelayerExecutionStrategy = class {
|
|
|
4608
4771
|
// If no explicit gas limit is provided, keep a conservative default but warn.
|
|
4609
4772
|
gas_limit: (() => {
|
|
4610
4773
|
if (typeof evmOptions?.gasLimit === "number") return evmOptions.gasLimit;
|
|
4611
|
-
|
|
4774
|
+
import_ui_builder_utils34.logger.warn(
|
|
4612
4775
|
"[Relayer]",
|
|
4613
4776
|
"No gasLimit provided; using default 210000. Consider setting explicitly."
|
|
4614
4777
|
);
|
|
@@ -4680,10 +4843,10 @@ var RelayerExecutionStrategy = class {
|
|
|
4680
4843
|
};
|
|
4681
4844
|
|
|
4682
4845
|
// src/transaction/sender.ts
|
|
4683
|
-
var
|
|
4846
|
+
var import_ui_builder_utils35 = require("@openzeppelin/ui-builder-utils");
|
|
4684
4847
|
var SYSTEM_LOG_TAG3 = "adapter-evm-sender";
|
|
4685
4848
|
async function waitForEvmTransactionConfirmation(txHash, walletImplementation) {
|
|
4686
|
-
|
|
4849
|
+
import_ui_builder_utils35.logger.info(SYSTEM_LOG_TAG3, `Waiting for tx: ${txHash}`);
|
|
4687
4850
|
try {
|
|
4688
4851
|
const resolvedPublicClient = await walletImplementation.getPublicClient();
|
|
4689
4852
|
if (!resolvedPublicClient) {
|
|
@@ -4692,15 +4855,15 @@ async function waitForEvmTransactionConfirmation(txHash, walletImplementation) {
|
|
|
4692
4855
|
const receipt = await resolvedPublicClient.waitForTransactionReceipt({
|
|
4693
4856
|
hash: txHash
|
|
4694
4857
|
});
|
|
4695
|
-
|
|
4858
|
+
import_ui_builder_utils35.logger.info(SYSTEM_LOG_TAG3, "Received receipt:", receipt);
|
|
4696
4859
|
if (receipt.status === "success") {
|
|
4697
4860
|
return { status: "success", receipt };
|
|
4698
4861
|
} else {
|
|
4699
|
-
|
|
4862
|
+
import_ui_builder_utils35.logger.error(SYSTEM_LOG_TAG3, "Transaction reverted:", receipt);
|
|
4700
4863
|
return { status: "error", receipt, error: new Error("Transaction reverted.") };
|
|
4701
4864
|
}
|
|
4702
4865
|
} catch (error) {
|
|
4703
|
-
|
|
4866
|
+
import_ui_builder_utils35.logger.error(SYSTEM_LOG_TAG3, "Error waiting for transaction confirmation:", error);
|
|
4704
4867
|
return {
|
|
4705
4868
|
status: "error",
|
|
4706
4869
|
error: error instanceof Error ? error : new Error(String(error))
|
|
@@ -4710,9 +4873,9 @@ async function waitForEvmTransactionConfirmation(txHash, walletImplementation) {
|
|
|
4710
4873
|
|
|
4711
4874
|
// src/transaction/formatter.ts
|
|
4712
4875
|
var import_viem9 = require("viem");
|
|
4713
|
-
var
|
|
4876
|
+
var import_ui_builder_utils36 = require("@openzeppelin/ui-builder-utils");
|
|
4714
4877
|
function formatEvmTransactionData(contractSchema, functionId, submittedInputs, fields) {
|
|
4715
|
-
|
|
4878
|
+
import_ui_builder_utils36.logger.info(
|
|
4716
4879
|
"formatEvmTransactionData",
|
|
4717
4880
|
`Formatting EVM transaction data for function: ${functionId}`
|
|
4718
4881
|
);
|
|
@@ -4750,7 +4913,7 @@ function formatEvmTransactionData(contractSchema, functionId, submittedInputs, f
|
|
|
4750
4913
|
const isPayable = functionDetails.stateMutability === "payable";
|
|
4751
4914
|
let transactionValue = 0n;
|
|
4752
4915
|
if (isPayable) {
|
|
4753
|
-
|
|
4916
|
+
import_ui_builder_utils36.logger.warn(
|
|
4754
4917
|
"formatEvmTransactionData",
|
|
4755
4918
|
"Payable function detected, but sending 0 ETH. Implement value input."
|
|
4756
4919
|
);
|
|
@@ -4771,7 +4934,7 @@ function formatEvmTransactionData(contractSchema, functionId, submittedInputs, f
|
|
|
4771
4934
|
}
|
|
4772
4935
|
|
|
4773
4936
|
// src/transaction/eoa.ts
|
|
4774
|
-
var
|
|
4937
|
+
var import_ui_builder_utils37 = require("@openzeppelin/ui-builder-utils");
|
|
4775
4938
|
var SYSTEM_LOG_TAG4 = "EoaExecutionStrategy";
|
|
4776
4939
|
var EoaExecutionStrategy = class {
|
|
4777
4940
|
async execute(transactionData, executionConfig, walletImplementation, onStatusChange, _runtimeApiKey) {
|
|
@@ -4784,9 +4947,9 @@ var EoaExecutionStrategy = class {
|
|
|
4784
4947
|
if (validationResult !== true) {
|
|
4785
4948
|
throw new Error(validationResult);
|
|
4786
4949
|
}
|
|
4787
|
-
|
|
4950
|
+
import_ui_builder_utils37.logger.info(SYSTEM_LOG_TAG4, "Using EOA execution strategy.");
|
|
4788
4951
|
try {
|
|
4789
|
-
|
|
4952
|
+
import_ui_builder_utils37.logger.debug(SYSTEM_LOG_TAG4, "Calling walletClient.writeContract with:", {
|
|
4790
4953
|
account: accountStatus.address,
|
|
4791
4954
|
address: transactionData.address,
|
|
4792
4955
|
abi: transactionData.abi,
|
|
@@ -4805,10 +4968,10 @@ var EoaExecutionStrategy = class {
|
|
|
4805
4968
|
value: transactionData.value,
|
|
4806
4969
|
chain: walletClient.chain
|
|
4807
4970
|
});
|
|
4808
|
-
|
|
4971
|
+
import_ui_builder_utils37.logger.info(SYSTEM_LOG_TAG4, "EOA Transaction initiated. Hash:", hash);
|
|
4809
4972
|
return { txHash: hash };
|
|
4810
4973
|
} catch (error) {
|
|
4811
|
-
|
|
4974
|
+
import_ui_builder_utils37.logger.error(SYSTEM_LOG_TAG4, "Error during EOA writeContract call:", error);
|
|
4812
4975
|
const errorMessage = error instanceof Error ? error.message : "Unknown EOA transaction error";
|
|
4813
4976
|
throw new Error(`Transaction failed (EOA): ${errorMessage}`);
|
|
4814
4977
|
}
|
|
@@ -4816,12 +4979,12 @@ var EoaExecutionStrategy = class {
|
|
|
4816
4979
|
async getAuthenticatedWalletClient(walletImplementation) {
|
|
4817
4980
|
const walletClient = await walletImplementation.getWalletClient();
|
|
4818
4981
|
if (!walletClient) {
|
|
4819
|
-
|
|
4982
|
+
import_ui_builder_utils37.logger.error(SYSTEM_LOG_TAG4, "Wallet client not available. Is wallet connected?");
|
|
4820
4983
|
throw new Error("Wallet is not connected or client is unavailable.");
|
|
4821
4984
|
}
|
|
4822
4985
|
const accountStatus = walletImplementation.getWalletConnectionStatus();
|
|
4823
4986
|
if (!accountStatus.isConnected || !accountStatus.address) {
|
|
4824
|
-
|
|
4987
|
+
import_ui_builder_utils37.logger.error(SYSTEM_LOG_TAG4, "Account not available. Is wallet connected?");
|
|
4825
4988
|
throw new Error("Wallet is not connected or account address is unavailable.");
|
|
4826
4989
|
}
|
|
4827
4990
|
return { walletClient, accountStatus };
|
|
@@ -4860,7 +5023,7 @@ var AdvancedInfo = ({ showAdvancedInfo, onToggle }) => {
|
|
|
4860
5023
|
// src/transaction/components/CustomGasParameters.tsx
|
|
4861
5024
|
var import_lucide_react6 = require("lucide-react");
|
|
4862
5025
|
var import_ui_builder_ui7 = require("@openzeppelin/ui-builder-ui");
|
|
4863
|
-
var
|
|
5026
|
+
var import_ui_builder_utils38 = require("@openzeppelin/ui-builder-utils");
|
|
4864
5027
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
4865
5028
|
var CustomGasParameters = ({
|
|
4866
5029
|
control,
|
|
@@ -4893,7 +5056,7 @@ var CustomGasParameters = ({
|
|
|
4893
5056
|
import_ui_builder_ui7.AccordionItem,
|
|
4894
5057
|
{
|
|
4895
5058
|
value: "eip1559",
|
|
4896
|
-
className: (0,
|
|
5059
|
+
className: (0, import_ui_builder_utils38.cn)(
|
|
4897
5060
|
"rounded-lg border shadow-sm overflow-hidden transition-all",
|
|
4898
5061
|
gasType === "eip1559" ? "border-primary bg-primary/5" : "border-border bg-card hover:border-muted-foreground/50"
|
|
4899
5062
|
),
|
|
@@ -4950,7 +5113,7 @@ var CustomGasParameters = ({
|
|
|
4950
5113
|
import_ui_builder_ui7.AccordionItem,
|
|
4951
5114
|
{
|
|
4952
5115
|
value: "legacy",
|
|
4953
|
-
className: (0,
|
|
5116
|
+
className: (0, import_ui_builder_utils38.cn)(
|
|
4954
5117
|
"rounded-lg border shadow-sm overflow-hidden transition-all",
|
|
4955
5118
|
gasType === "legacy" ? "border-primary bg-primary/5" : "border-border bg-card hover:border-muted-foreground/50"
|
|
4956
5119
|
),
|
|
@@ -5246,7 +5409,7 @@ var EvmRelayerOptions = ({ options, onChange }) => {
|
|
|
5246
5409
|
};
|
|
5247
5410
|
|
|
5248
5411
|
// src/wallet/utils/connection.ts
|
|
5249
|
-
var
|
|
5412
|
+
var import_ui_builder_utils39 = require("@openzeppelin/ui-builder-utils");
|
|
5250
5413
|
var LOG_SYSTEM3 = "adapter-evm-connection";
|
|
5251
5414
|
function evmSupportsWalletConnection() {
|
|
5252
5415
|
return true;
|
|
@@ -5254,7 +5417,7 @@ function evmSupportsWalletConnection() {
|
|
|
5254
5417
|
async function getEvmAvailableConnectors() {
|
|
5255
5418
|
const impl = await getEvmWalletImplementation();
|
|
5256
5419
|
if (!impl) {
|
|
5257
|
-
|
|
5420
|
+
import_ui_builder_utils39.logger.warn(LOG_SYSTEM3, "getEvmAvailableConnectors: Wallet implementation not ready.");
|
|
5258
5421
|
return [];
|
|
5259
5422
|
}
|
|
5260
5423
|
return impl.getAvailableConnectors();
|
|
@@ -5262,7 +5425,7 @@ async function getEvmAvailableConnectors() {
|
|
|
5262
5425
|
async function connectAndEnsureCorrectNetwork(connectorId, targetChainId) {
|
|
5263
5426
|
const impl = await getEvmWalletImplementation();
|
|
5264
5427
|
if (!impl) {
|
|
5265
|
-
|
|
5428
|
+
import_ui_builder_utils39.logger.error(LOG_SYSTEM3, "connectAndEnsureCorrectNetwork: Wallet implementation not ready.");
|
|
5266
5429
|
return { connected: false, error: "Wallet system not initialized." };
|
|
5267
5430
|
}
|
|
5268
5431
|
const connectionResult = await impl.connect(connectorId);
|
|
@@ -5270,7 +5433,7 @@ async function connectAndEnsureCorrectNetwork(connectorId, targetChainId) {
|
|
|
5270
5433
|
return { connected: false, error: connectionResult.error || "Connection failed" };
|
|
5271
5434
|
}
|
|
5272
5435
|
if (connectionResult.chainId !== targetChainId) {
|
|
5273
|
-
|
|
5436
|
+
import_ui_builder_utils39.logger.info(
|
|
5274
5437
|
LOG_SYSTEM3,
|
|
5275
5438
|
`Connected to chain ${connectionResult.chainId}, but target is ${targetChainId}. Attempting switch.`
|
|
5276
5439
|
);
|
|
@@ -5279,23 +5442,23 @@ async function connectAndEnsureCorrectNetwork(connectorId, targetChainId) {
|
|
|
5279
5442
|
const postSwitchStatus = impl.getWalletConnectionStatus();
|
|
5280
5443
|
if (postSwitchStatus.chainId !== targetChainId) {
|
|
5281
5444
|
const switchError = `Failed to switch to target network ${targetChainId}. Current: ${postSwitchStatus.chainId}`;
|
|
5282
|
-
|
|
5445
|
+
import_ui_builder_utils39.logger.error(LOG_SYSTEM3, switchError);
|
|
5283
5446
|
try {
|
|
5284
5447
|
await impl.disconnect();
|
|
5285
5448
|
} catch (e) {
|
|
5286
|
-
|
|
5449
|
+
import_ui_builder_utils39.logger.warn(LOG_SYSTEM3, "Failed to disconnect after network switch failure.", e);
|
|
5287
5450
|
}
|
|
5288
5451
|
return { connected: false, error: switchError };
|
|
5289
5452
|
}
|
|
5290
|
-
|
|
5453
|
+
import_ui_builder_utils39.logger.info(LOG_SYSTEM3, `Successfully switched to target chain ${targetChainId}.`);
|
|
5291
5454
|
return { ...connectionResult, chainId: postSwitchStatus.chainId };
|
|
5292
5455
|
} catch (error) {
|
|
5293
5456
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
5294
|
-
|
|
5457
|
+
import_ui_builder_utils39.logger.error(LOG_SYSTEM3, "Network switch failed:", errorMessage);
|
|
5295
5458
|
try {
|
|
5296
5459
|
await impl.disconnect();
|
|
5297
5460
|
} catch (e) {
|
|
5298
|
-
|
|
5461
|
+
import_ui_builder_utils39.logger.warn(LOG_SYSTEM3, "Failed to disconnect after network switch failure.", e);
|
|
5299
5462
|
}
|
|
5300
5463
|
return { connected: false, error: `Network switch failed: ${errorMessage}` };
|
|
5301
5464
|
}
|
|
@@ -5305,7 +5468,7 @@ async function connectAndEnsureCorrectNetwork(connectorId, targetChainId) {
|
|
|
5305
5468
|
async function disconnectEvmWallet() {
|
|
5306
5469
|
const impl = await getEvmWalletImplementation();
|
|
5307
5470
|
if (!impl) {
|
|
5308
|
-
|
|
5471
|
+
import_ui_builder_utils39.logger.warn(LOG_SYSTEM3, "disconnectEvmWallet: Wallet implementation not ready.");
|
|
5309
5472
|
return { disconnected: false, error: "Wallet system not initialized." };
|
|
5310
5473
|
}
|
|
5311
5474
|
return impl.disconnect();
|
|
@@ -5313,7 +5476,7 @@ async function disconnectEvmWallet() {
|
|
|
5313
5476
|
function getEvmWalletConnectionStatus() {
|
|
5314
5477
|
const impl = getInitializedEvmWalletImplementation();
|
|
5315
5478
|
if (!impl) {
|
|
5316
|
-
|
|
5479
|
+
import_ui_builder_utils39.logger.warn(
|
|
5317
5480
|
LOG_SYSTEM3,
|
|
5318
5481
|
"getEvmWalletConnectionStatus: Wallet implementation not ready. Returning default disconnected state."
|
|
5319
5482
|
);
|
|
@@ -5363,18 +5526,36 @@ var EvmAdapter = class {
|
|
|
5363
5526
|
throw new Error("EvmAdapter requires a valid EVM network configuration.");
|
|
5364
5527
|
}
|
|
5365
5528
|
this.networkConfig = networkConfig;
|
|
5366
|
-
|
|
5529
|
+
import_ui_builder_utils40.logger.info(
|
|
5367
5530
|
"EvmAdapter",
|
|
5368
5531
|
`Adapter initialized for network: ${networkConfig.name} (ID: ${networkConfig.id})`
|
|
5369
5532
|
);
|
|
5370
5533
|
const initialGlobalConfig = loadInitialConfigFromAppService();
|
|
5371
5534
|
this.initialAppServiceKitName = initialGlobalConfig.kitName || "custom";
|
|
5372
|
-
|
|
5535
|
+
import_ui_builder_utils40.logger.info(
|
|
5373
5536
|
"EvmAdapter:constructor",
|
|
5374
5537
|
"Initial kitName from AppConfigService noted:",
|
|
5375
5538
|
this.initialAppServiceKitName
|
|
5376
5539
|
);
|
|
5377
5540
|
}
|
|
5541
|
+
/**
|
|
5542
|
+
* @inheritdoc
|
|
5543
|
+
*/
|
|
5544
|
+
getNetworkServiceForms() {
|
|
5545
|
+
return getEvmNetworkServiceForms(this.networkConfig);
|
|
5546
|
+
}
|
|
5547
|
+
/**
|
|
5548
|
+
* @inheritdoc
|
|
5549
|
+
*/
|
|
5550
|
+
async validateNetworkServiceConfig(serviceId, values) {
|
|
5551
|
+
return validateEvmNetworkServiceConfig(serviceId, values);
|
|
5552
|
+
}
|
|
5553
|
+
/**
|
|
5554
|
+
* @inheritdoc
|
|
5555
|
+
*/
|
|
5556
|
+
async testNetworkServiceConnection(serviceId, values) {
|
|
5557
|
+
return testEvmNetworkServiceConnection(serviceId, values, this.networkConfig);
|
|
5558
|
+
}
|
|
5378
5559
|
/**
|
|
5379
5560
|
* @inheritdoc
|
|
5380
5561
|
*/
|
|
@@ -5586,7 +5767,7 @@ var EvmAdapter = class {
|
|
|
5586
5767
|
onWalletConnectionChange(callback) {
|
|
5587
5768
|
const walletImplementation = getInitializedEvmWalletImplementation();
|
|
5588
5769
|
if (!walletImplementation) {
|
|
5589
|
-
|
|
5770
|
+
import_ui_builder_utils40.logger.warn(
|
|
5590
5771
|
"EvmAdapter:onWalletConnectionChange",
|
|
5591
5772
|
"Wallet implementation not ready. Subscription may not work."
|
|
5592
5773
|
);
|
|
@@ -5635,7 +5816,7 @@ var EvmAdapter = class {
|
|
|
5635
5816
|
options
|
|
5636
5817
|
);
|
|
5637
5818
|
await evmUiKitManager.configure(finalFullConfig);
|
|
5638
|
-
|
|
5819
|
+
import_ui_builder_utils40.logger.info(
|
|
5639
5820
|
"EvmAdapter:configureUiKit",
|
|
5640
5821
|
"EvmUiKitManager configuration requested with final config:",
|
|
5641
5822
|
finalFullConfig
|
|
@@ -5645,7 +5826,7 @@ var EvmAdapter = class {
|
|
|
5645
5826
|
* @inheritdoc
|
|
5646
5827
|
*/
|
|
5647
5828
|
getEcosystemReactUiContextProvider() {
|
|
5648
|
-
|
|
5829
|
+
import_ui_builder_utils40.logger.info("EvmAdapter:getEcosystemReactUiContextProvider", "Returning EvmWalletUiRoot.");
|
|
5649
5830
|
return EvmWalletUiRoot;
|
|
5650
5831
|
}
|
|
5651
5832
|
/**
|
|
@@ -5669,7 +5850,7 @@ var EvmAdapter = class {
|
|
|
5669
5850
|
getEcosystemWalletComponents() {
|
|
5670
5851
|
const currentManagerState = evmUiKitManager.getState();
|
|
5671
5852
|
if (!currentManagerState.currentFullUiKitConfig) {
|
|
5672
|
-
|
|
5853
|
+
import_ui_builder_utils40.logger.debug(
|
|
5673
5854
|
// Changed from warn to debug, as this can be normal during init sequence
|
|
5674
5855
|
"EvmAdapter:getEcosystemWalletComponents",
|
|
5675
5856
|
"No UI kit configuration available in manager yet. Returning undefined components."
|
|
@@ -5808,7 +5989,7 @@ Get your WalletConnect projectId from <a href="https://cloud.walletconnect.com"
|
|
|
5808
5989
|
summary: result.summary
|
|
5809
5990
|
};
|
|
5810
5991
|
} catch (error) {
|
|
5811
|
-
|
|
5992
|
+
import_ui_builder_utils40.logger.error("EVM contract definition comparison failed:", error.message);
|
|
5812
5993
|
throw new Error(`Contract definition comparison failed: ${error.message}`);
|
|
5813
5994
|
}
|
|
5814
5995
|
}
|