From 0c98b155620c8805176eeff98c17638d45945f28 Mon Sep 17 00:00:00 2001 From: aelmanaa Date: Mon, 9 Dec 2024 10:54:38 +0100 Subject: [PATCH] update --- .../DeployPoolStep.tsx | 50 +++++++++---------- .../StoredContractAddress.tsx | 38 +++++++++----- .../CCIP/TutorialSetup/SolidityParam.tsx | 4 +- 3 files changed, 54 insertions(+), 38 deletions(-) diff --git a/src/components/CCIP/TutorialBlockchainSelector/DeployPoolStep.tsx b/src/components/CCIP/TutorialBlockchainSelector/DeployPoolStep.tsx index 68cf8d0866c..a956f5ba2f7 100644 --- a/src/components/CCIP/TutorialBlockchainSelector/DeployPoolStep.tsx +++ b/src/components/CCIP/TutorialBlockchainSelector/DeployPoolStep.tsx @@ -32,38 +32,38 @@ export const DeployPoolStep = ({ chain }: DeployPoolStepProps) => {
@@ -77,9 +77,9 @@ export const DeployPoolStep = ({ chain }: DeployPoolStepProps) => { {poolType === "lock" ? ( <> } /> { example="[]" /> } /> { } /> ) : ( <> } /> { } /> } /> diff --git a/src/components/CCIP/TutorialBlockchainSelector/StoredContractAddress.tsx b/src/components/CCIP/TutorialBlockchainSelector/StoredContractAddress.tsx index 392e9b51a0e..b16a18b19ef 100644 --- a/src/components/CCIP/TutorialBlockchainSelector/StoredContractAddress.tsx +++ b/src/components/CCIP/TutorialBlockchainSelector/StoredContractAddress.tsx @@ -2,27 +2,41 @@ import { useStore } from "@nanostores/react" import { laneStore } from "@stores/lanes" import type { DeployedContracts } from "@stores/lanes" import { ReactCopyText } from "@components/ReactCopyText" -import { ethers } from "ethers" +import { utils } from "ethers" + +type AddressFields = Extract interface StoredContractAddressProps { - type: keyof DeployedContracts + type: AddressFields chain: "source" | "destination" - required?: boolean + code?: boolean encode?: boolean } -export const StoredContractAddress = ({ type, chain, required = true, encode = false }: StoredContractAddressProps) => { +export const StoredContractAddress = ({ type, chain, code = true, encode = false }: StoredContractAddressProps) => { const state = useStore(laneStore) const contracts = chain === "source" ? state.sourceContracts : state.destinationContracts - const address = contracts[type] + const value = contracts[type] + + // Format and encode addresses + const displayAddress = (() => { + if (!value) return "" + + if (Array.isArray(value)) { + const validAddresses = value.filter((addr): addr is string => typeof addr === "string" && utils.isAddress(addr)) + if (!validAddresses.length) return "" + + return encode + ? validAddresses.map((addr) => utils.defaultAbiCoder.encode(["address"], [addr])).join(", ") + : validAddresses.join(", ") + } - if (!address) { - return required ? [No address saved yet] : null - } + if (typeof value === "string" && value) { + return encode ? utils.defaultAbiCoder.encode(["address"], [utils.getAddress(value)]) : utils.getAddress(value) + } - const displayAddress = encode - ? ethers.utils.defaultAbiCoder.encode(["address"], [address]).toString() - : address.toString() + return "" + })() - return + return } diff --git a/src/components/CCIP/TutorialSetup/SolidityParam.tsx b/src/components/CCIP/TutorialSetup/SolidityParam.tsx index e166a5d0da9..b17105c56e4 100644 --- a/src/components/CCIP/TutorialSetup/SolidityParam.tsx +++ b/src/components/CCIP/TutorialSetup/SolidityParam.tsx @@ -14,7 +14,9 @@ export const SolidityParam = ({ name, type, description, example }: SolidityPara {type}

{description}

- {example && } + { + example && (typeof example === "string" ? : example) // Render React element directly + }
)