From 56ff31d86f65cbcc0577ef73aaa8c75131307304 Mon Sep 17 00:00:00 2001 From: BrickheadJohnny Date: Thu, 31 Oct 2024 13:01:44 +0100 Subject: [PATCH] fix(WalletActivityRequirement): support legacy `ALCHEMY_` requirements too --- .../WalletActivityRequirement.tsx | 61 +++++++++++-------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/src/requirements/WalletActivity/WalletActivityRequirement.tsx b/src/requirements/WalletActivity/WalletActivityRequirement.tsx index 5d38066bc6..0965762d03 100644 --- a/src/requirements/WalletActivity/WalletActivityRequirement.tsx +++ b/src/requirements/WalletActivity/WalletActivityRequirement.tsx @@ -33,20 +33,22 @@ const requirementIcons: Record< COVALENT_TX_VALUE_RELATIVE: Coins, } +type CovalentRequirementType = + | "COVALENT_FIRST_TX" + | "COVALENT_FIRST_TX_RELATIVE" + | "COVALENT_CONTRACT_DEPLOY" + | "COVALENT_CONTRACT_DEPLOY_RELATIVE" + | "COVALENT_TX_COUNT" + | "COVALENT_TX_COUNT_RELATIVE" + | "COVALENT_TX_VALUE" + | "COVALENT_TX_VALUE_RELATIVE" + const WalletActivityRequirement = (props: RequirementProps): JSX.Element => { - const requirement = useRequirementContext< - | "COVALENT_FIRST_TX" - | "COVALENT_FIRST_TX_RELATIVE" - | "COVALENT_CONTRACT_DEPLOY" - | "COVALENT_CONTRACT_DEPLOY_RELATIVE" - | "COVALENT_TX_COUNT" - | "COVALENT_TX_COUNT_RELATIVE" - | "COVALENT_TX_VALUE" - | "COVALENT_TX_VALUE_RELATIVE" - >() - - const maxAmount = requirement.data?.timestamps?.maxAmount - const minAmount = requirement.data?.timestamps?.minAmount + const requirement = useRequirementContext() + const reqData = requirement.data as any // Important note: we needed a hotfix for the requirement icon, but we should find a proper solution for this. + + const maxAmount = reqData?.timestamps?.maxAmount + const minAmount = reqData?.timestamps?.minAmount const getFirstTxRelativeContent = () => { const formattedMin = formatRelativeTimeFromNow(minAmount) @@ -84,7 +86,12 @@ const WalletActivityRequirement = (props: RequirementProps): JSX.Element => { return "Have at least one transaction" } - const IconComponent = requirementIcons[requirement.type] + const reqType = requirement.type.replace( + "ALCHEMY", + "COVALENT" + ) as CovalentRequirementType + + const IconComponent = requirementIcons[reqType] return ( { {...props} > {(() => { - switch (requirement.type) { + switch (reqType) { case "COVALENT_FIRST_TX": if (!minAmount && !maxAmount) return "Have at least one transaction" return ( @@ -109,27 +116,27 @@ const WalletActivityRequirement = (props: RequirementProps): JSX.Element => { <> {`Deployed ${ - requirement.data.txCount > 1 ? requirement.data.txCount : "a" - } ${pluralize(requirement.data.txCount, "contract", false)}`} + reqData.txCount > 1 ? reqData.txCount : "a" + } ${pluralize(reqData.txCount, "contract", false)}`} ) case "COVALENT_CONTRACT_DEPLOY_RELATIVE": { const formattedMinAmount = formatRelativeTimeFromNow( - requirement.data.timestamps.minAmount + reqData.timestamps.minAmount ) const formattedMaxAmount = formatRelativeTimeFromNow( - requirement.data.timestamps.maxAmount + reqData.timestamps.maxAmount ) return ( <> {`Deployed ${ - requirement.data.txCount > 1 ? requirement.data.txCount : "a" - } contract${requirement.data.txCount > 1 ? "s" : ""}`} + reqData.txCount > 1 ? reqData.txCount : "a" + } contract${reqData.txCount > 1 ? "s" : ""}`} {formattedMaxAmount && formattedMinAmount ? ( <> @@ -152,8 +159,8 @@ const WalletActivityRequirement = (props: RequirementProps): JSX.Element => { <> {`Have ${ - requirement.data.txCount > 1 ? requirement.data.txCount : "a" - } transaction${requirement.data.txCount > 1 ? "s" : ""}`} + reqData.txCount > 1 ? reqData.txCount : "a" + } transaction${reqData.txCount > 1 ? "s" : ""}`} {requirement.address && ( @@ -170,19 +177,19 @@ const WalletActivityRequirement = (props: RequirementProps): JSX.Element => { ) case "COVALENT_TX_COUNT_RELATIVE": { const formattedMinAmount = formatRelativeTimeFromNow( - requirement.data.timestamps.minAmount + reqData.timestamps.minAmount ) const formattedMaxAmount = formatRelativeTimeFromNow( - requirement.data.timestamps.maxAmount + reqData.timestamps.maxAmount ) return ( <> {`Have ${ - requirement.data.txCount > 1 ? requirement.data.txCount : "a" - } transaction${requirement.data.txCount > 1 ? "s" : ""}`} + reqData.txCount > 1 ? reqData.txCount : "a" + } transaction${reqData.txCount > 1 ? "s" : ""}`} {formattedMaxAmount && formattedMinAmount ? ( <>