Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/nanoid-3.3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut authored Dec 20, 2024
2 parents a1ae3e6 + ec16131 commit 1a2a73e
Show file tree
Hide file tree
Showing 23 changed files with 261 additions and 199 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"lint:fix": "yarn workspaces foreach run lint:fix",
"formatAll": "prettier --write .",
"start:chopsticks-test-build-and-launch-all": "concurrently --kill-others 'npm run start:chopsticks' 'npm run ui:start-with-chopsticks' 'npm run docker:down && npm run docker:db && npm run build:indexer && npm run indexer:start:chopsticks-local' 'npm run start:graphql-server'",
"start:chopsticks": "npx --yes @acala-network/[email protected] --config chopsticks-config.yml",
"start:chopsticks": "npx --yes @acala-network/[email protected].2-1 --config chopsticks-config.yml",
"start:graphql-server": "cd squid && npm run start:graphql-server",
"indexer:start:chopsticks-ci": "cd squid && npm run start:chopsticks-ci",
"indexer:start:chopsticks-local": "cd squid && npm run start:chopsticks-local",
Expand Down
1 change: 1 addition & 0 deletions packages/ui/cypress/support/page-objects/landingPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const landingPage = {
multisigCreationInfoBanner: (timeout = 4000) =>
cy.get('[data-cy=banner-multisig-creation-info]', { timeout }),
creationInfoBannerCloseButton: () => cy.get('[data-cy=button-close-multisig-creation-info]'),
transactionListLoader: () => cy.get('[data-cy=loader-transaction-list]'),

// page specific assertion
shouldHaveNoAccountErrorAndWikiLink() {
Expand Down
8 changes: 6 additions & 2 deletions packages/ui/cypress/tests/address-bar.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,15 @@ describe('Account address in the address bar', () => {
watchedAccounts: [publicKey]
})

multisigPage.accountHeader().within(() => {
accountDisplay.addressLabel().should('contain.text', address.slice(0, 6))
})

// check that there is an address in the address bar
cy.url({ timeout: 3000 }).should('include', address)

// react-router takes some time to get the search params inside the links
cy.wait(1000)
// wait for the loader to be done otherwise the test fails
landingPage.transactionListLoader().should('not.exist')

topMenuItems.homeButton().click()
cy.url().should('include', address)
Expand Down
35 changes: 14 additions & 21 deletions packages/ui/cypress/tests/default-multisigs.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,17 @@ describe('default Multisigs', () => {
watchedAccounts: [lolmcshizPubKey]
})

multisigPage.accountHeader().within(() => {
accountDisplay
.addressLabel()
.invoke('text')
.as('defaultPolkadotAddress')
.should('not.contain', polkadotSelectedMultiproxy.slice(0, 6))
})

cy.log('@defaultPolkadotAddress', cy.get('@defaultPolkadotAddress'))

// select another one
topMenuItems.desktopMenu().within(() =>
topMenuItems.desktopMenu().within(() => {
topMenuItems
.multiproxySelectorDesktop()
.wait(1000)
.multiproxySelectorInputDesktop()
.should('not.have.value', '')
.click()
.type(`${polkadotSelectedMultiproxy.slice(0, 6)}{downArrow}{enter}`)
)
.type(`${polkadotSelectedMultiproxy.slice(0, 6)}{downArrow}{enter}`, {
delay: 100,
timeout: 6000
})
})

// verify that it's displayed
multisigPage.accountHeader().within(() => {
Expand All @@ -47,19 +40,19 @@ describe('default Multisigs', () => {
accountDisplay
.addressLabel()
.invoke('text')
.as('defaultKusamaAddress')
.should('not.contain', kusamaSelectedMultiproxy.slice(0, 6))
})

cy.log('@defaultKusamaAddress', cy.get('@defaultKusamaAddress'))

// select another one
topMenuItems.desktopMenu().within(() =>
topMenuItems
.multiproxySelectorDesktop()
.wait(1000)
.multiproxySelectorInputDesktop()
.should('not.have.value', '')
.click()
.type(`${kusamaSelectedMultiproxy.slice(0, 6)}{downArrow}{enter}`)
.type(`${kusamaSelectedMultiproxy.slice(0, 6)}{downArrow}{enter}`, {
delay: 100,
timeout: 6000
})
)

// verify that it's displayed
Expand Down
37 changes: 17 additions & 20 deletions 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 All @@ -115,17 +117,14 @@ describe('Multisig creation', () => {

verifySignatories()

// this is commented because chopsticks doesnot support archive_unstable_hashByHeight
// see https://github.com/AcalaNetwork/chopsticks/issues/852

// there should be a pending pure proxy creation
// multisigPage
// .transactionList()
// .should('be.visible')
// .within(() => {
// multisigPage.pendingTransactionItem().should('have.length', 1)
// multisigPage.pendingTransactionCallName().should('contain.text', 'proxy.createPure')
// })
multisigPage
.transactionList()
.should('be.visible')
.within(() => {
multisigPage.pendingTransactionItem().should('have.length', 1)
multisigPage.pendingTransactionCallName().should('contain.text', 'Proxy.create_pure')
})
})

it('Create a multisig without a pure proxy', () => {
Expand All @@ -136,7 +135,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 Expand Up @@ -173,15 +171,14 @@ describe('Multisig creation', () => {

verifySignatories()

// this is commented because chopsticks doesnot support archive_unstable_hashByHeight
// see https://github.com/AcalaNetwork/chopsticks/issues/852
// multisigPage
// .transactionList()
// .should('be.visible')
// .within(() => {
// multisigPage.pendingTransactionItem().should('have.length', 1)
// multisigPage.pendingTransactionCallName().should('contain.text', 'remark:')
// })
// there should be a pending remark
multisigPage
.transactionList()
.should('be.visible')
.within(() => {
multisigPage.pendingTransactionItem().should('have.length', 1)
multisigPage.pendingTransactionCallName().should('contain.text', 'System.remark')
})
})
})

Expand Down
38 changes: 24 additions & 14 deletions packages/ui/cypress/tests/watched-accounts.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import { multisigPage } from '../support/page-objects/multisigPage'
import { editNamesModal } from '../support/page-objects/modals/editNamesModal'
import { testAccounts } from '../fixtures/testAccounts'
import { knownMultisigs } from '../fixtures/knownMultisigs'
import { getShortAddress } from '../utils/getShortAddress'

const addWatchAccount = (address: string, name?: string) => {
settingsPage.accountAddressInput().type(`${address}{enter}`, { delay: 20 })
settingsPage.accountAddressInput().type(`${address}{enter}`, { delay: 20, timeout: 6000 })

if (name) {
settingsPage.accountNameInput().type(name)
Expand Down Expand Up @@ -304,7 +305,7 @@ describe('Watched Accounts', () => {

it('can see all multisigs that a watched signatory is a member of', () => {
const { publicKey: signatoryPublicKey } = testAccounts['Multisig Member Account 1']
const expectedAddresses = [
const expectedMultiproxies = [
{
address: knownMultisigs['test-simple-multisig-1'].address,
expectedBadge: 'multi'
Expand All @@ -323,24 +324,33 @@ describe('Watched Accounts', () => {
// ensure all multisigs are displayed in the multiproxy selector
topMenuItems
.multiproxySelectorOptionDesktop()
.should('have.length', expectedAddresses.length)
.each(($el, index) => {
.should('have.length', expectedMultiproxies.length)
.each(($el) => {
cy.wrap($el).within(() => {
accountDisplay
.addressLabel()
.should('contain.text', expectedAddresses[index].address.slice(0, 6))
accountDisplay.watchedIcon().should('be.visible')
if (expectedAddresses[index].expectedBadge === 'pure') {
accountDisplay.pureBadge().should('be.visible')
} else {
accountDisplay.multisigBadge().should('be.visible')
}
.invoke('text')
.then((address) => {
const account = expectedMultiproxies.find((a) => {
return getShortAddress(a.address) === (address as unknown as string)
})
cy.wrap(account).should('not.be.undefined')
accountDisplay.watchedIcon().should('be.visible')
if (account?.expectedBadge === 'pure') {
accountDisplay.pureBadge().should('be.visible')
} else {
accountDisplay.multisigBadge().should('be.visible')
}
})
})
})
// ensure each multisig that the signatory is a member of can be viewed
expectedAddresses.forEach(({ address }, index) => {
topMenuItems.multiproxySelectorDesktop().click()
topMenuItems.multiproxySelectorOptionDesktop().eq(index).click()
expectedMultiproxies.forEach(({ address }) => {
topMenuItems
.multiproxySelectorDesktop()
.click()
.type(`${address.slice(0, 6)}{downArrow}{enter}`)

multisigPage
.accountHeader()
.should('be.visible')
Expand Down
1 change: 1 addition & 0 deletions packages/ui/cypress/utils/getShortAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const getShortAddress = (address: string) => `${address.slice(0, 6)}..${address.slice(-6)}`
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@polkadot/react-identicon": "^3.11.3",
"@polkadot/util-crypto": "^13.2.3",
"@reactive-dot/core": "^0.27.1",
"@reactive-dot/react": "^0.27.1",
"@reactive-dot/react": "^0.28.0",
"@tanstack/react-query": "^5.62.2",
"@walletconnect/web3wallet": "^1.16.1",
"dayjs": "^1.11.13",
Expand Down
58 changes: 40 additions & 18 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 @@ -57,12 +57,18 @@ const isWhiteListedCall = (type: string, value: string) => {
'ConvictionVoting.vote',
'ConvictionVoting.remove_vote',
'ConvictionVoting.undelegate',
'ConvictionVoting.unlock'
].includes(`${type}.${value}`)
'ConvictionVoting.unlock',
// Hydration
'Tokens.transfer'
].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 @@ -74,11 +80,23 @@ 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
const bigIntKey = ['value', 'fee', 'max_additional', 'balance'].find(
(key) => typeof value[key] === 'bigint'
)
// We should make sure this is not done for hydration
const bigIntKey =
!preventBalanceFormating &&
['value', 'fee', 'max_additional', 'balance'].find((key) => typeof value[key] === 'bigint')

if (bigIntKey) {
return formatBalance(value[bigIntKey], bigIntKey, chainInfo, id)
Expand Down Expand Up @@ -162,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 @@ -178,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 Expand Up @@ -252,7 +274,7 @@ const CallInfo = ({
() => aggregatedData.callData && getDecodeUrl(aggregatedData.callData),
[aggregatedData, getDecodeUrl]
)
const hasArgs = useMemo(() => decodedCall && Object.keys(decodedCall).length > 0, [decodedCall])
const hasArgs = useMemo(() => decodedCall && decodedCall?.value?.value, [decodedCall])

return (
<div
Expand Down
Loading

0 comments on commit 1a2a73e

Please sign in to comment.