Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut committed Dec 17, 2024
1 parent 0c7dcec commit 3f89c38
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
3 changes: 2 additions & 1 deletion packages/ui/cypress/tests/multisig-creation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
47 changes: 33 additions & 14 deletions packages/ui/src/components/CallInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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) => (
Expand All @@ -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) {
Expand Down Expand Up @@ -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) => {
Expand All @@ -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>
</>
Expand Down

0 comments on commit 3f89c38

Please sign in to comment.