From 3f89c389fa8cf0f27f4bbe51a2500398c93d4f3b Mon Sep 17 00:00:00 2001 From: Thibaut Sardan <github@thib.top> Date: Tue, 17 Dec 2024 11:51:06 +0100 Subject: [PATCH] fix tests --- .../ui/cypress/tests/multisig-creation.cy.ts | 3 +- packages/ui/src/components/CallInfo.tsx | 47 +++++++++++++------ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/packages/ui/cypress/tests/multisig-creation.cy.ts b/packages/ui/cypress/tests/multisig-creation.cy.ts index 345e7fa6d..720a58229 100644 --- a/packages/ui/cypress/tests/multisig-creation.cy.ts +++ b/packages/ui/cypress/tests/multisig-creation.cy.ts @@ -99,6 +99,8 @@ describe('Multisig creation', () => { // Step 2 newMultisigPage.step2.thresholdInput().type('2') newMultisigPage.step2.nameInput().type(multisigName) + newMultisigPage.step2.checkboxUsePureProxy().click() + newMultisigPage.step2.checkboxUsePureProxy().should('be.checked') newMultisigPage.nextButton().should('contain', 'Next').click() // Step 3 @@ -136,7 +138,6 @@ describe('Multisig creation', () => { // Step 2 newMultisigPage.step2.thresholdInput().type('3') newMultisigPage.step2.nameInput().type(multisigName) - newMultisigPage.step2.checkboxUsePureProxy().click() newMultisigPage.step2.checkboxUsePureProxy().should('not.be.checked') newMultisigPage.nextButton().should('contain', 'Next').click() diff --git a/packages/ui/src/components/CallInfo.tsx b/packages/ui/src/components/CallInfo.tsx index d9fd54d84..ff45a0e20 100644 --- a/packages/ui/src/components/CallInfo.tsx +++ b/packages/ui/src/components/CallInfo.tsx @@ -33,7 +33,7 @@ interface CreateTreeParams { chainInfo?: ChainInfoHuman } -const isWhiteListedCall = (type: string, value: string) => { +const isWhiteListedCall = (extrinsicName: string) => { return [ 'Balances.transfer', 'Balances.transfer_keep_alive', @@ -60,11 +60,15 @@ const isWhiteListedCall = (type: string, value: string) => { 'ConvictionVoting.unlock', // Hydration 'Tokens.transfer' - ].includes(`${type}.${value}`) + ].includes(extrinsicName) } -const isBatchedCall = (type: string, value: string) => { - return ['Utility.batch', 'Utility.batch_all', 'Utility.force_batch'].includes(`${type}.${value}`) +const isPreventBalanceFormat = (extrinsicName: string) => { + return ['Tokens.transfer'].includes(extrinsicName) +} + +const isBatchedCall = (extrinsicName: string) => { + return ['Utility.batch', 'Utility.batch_all', 'Utility.force_batch'].includes(extrinsicName) } const formatBalance = (amount: bigint, label: string, chainInfo: ChainInfoHuman, id: string) => ( @@ -76,11 +80,22 @@ const formatBalance = (amount: bigint, label: string, chainInfo: ChainInfoHuman, </li> ) -const eachFieldRendered = (value: Record<string, any>, chainInfo: ChainInfoHuman, id: string) => { +interface EachFieldRenderedParams { + value: Record<string, any> + chainInfo: ChainInfoHuman + id: string + preventBalanceFormating?: boolean +} +const eachFieldRendered = ({ + value, + chainInfo, + id, + preventBalanceFormating = false +}: EachFieldRenderedParams) => { // for transfer, nomination, staking, bounties // We should make sure this is not done for hydration const bigIntKey = - chainInfo.tokenSymbol !== 'HDX' && + !preventBalanceFormating && ['value', 'fee', 'max_additional', 'balance'].find((key) => typeof value[key] === 'bigint') if (bigIntKey) { @@ -165,7 +180,10 @@ const preparedCall = ({ }: PreparedCallParams) => { if (!decodedCall) return - if (isBatchedCall(decodedCall.type, decodedCall.value.type)) { + const extrinsicName = getExtrinsicName(decodedCall.type, decodedCall.value.type) + const preventBalanceFormating = isPreventBalanceFormat(extrinsicName) + + if (isBatchedCall(extrinsicName)) { const lowerLevelCalls = decodedCall.value.value.calls as Array<Record<string, any>> return lowerLevelCalls.map((call, index) => { @@ -181,19 +199,20 @@ const preparedCall = ({ }) } - if (isWhiteListedCall(decodedCall.type, decodedCall.value.type)) { + if (isWhiteListedCall(extrinsicName)) { const lowerLevelCall = decodedCall.value.value if (typeof lowerLevelCall === 'object') { return ( <> - {isBatch && ( - <ExtrinsicNameStyled> - {getExtrinsicName(decodedCall.type, decodedCall.value.type)} - </ExtrinsicNameStyled> - )} + {isBatch && <ExtrinsicNameStyled>{extrinsicName}</ExtrinsicNameStyled>} <ul> {Object.entries(lowerLevelCall).map(([key, value], index) => - eachFieldRendered({ [key]: value }, chainInfo, `${decodedCall.type}-${index}`) + eachFieldRendered({ + value: { [key]: value }, + chainInfo, + id: `${decodedCall.type}-${index}`, + preventBalanceFormating + }) )} </ul> </>