diff --git a/packages/ui/cypress/tests/setIdentity.cy.ts b/packages/ui/cypress/tests/setIdentity.cy.ts index a44a167c..48a87600 100644 --- a/packages/ui/cypress/tests/setIdentity.cy.ts +++ b/packages/ui/cypress/tests/setIdentity.cy.ts @@ -82,7 +82,7 @@ describe('Set an identity', () => { sendTxModal.buttonSend().should('not.exist') sendTxModal.buttonSending().should('be.visible') // expected https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frococo-rpc.polkadot.io#/extrinsics/decode/0x1f0102000412ad770206045069201514711dc2456908b0af226442d475d12a5334e9c4513e001901000564696973056c6565670000000000000000 - cy.wrap(txRequests[0].payload.method).should( + cy.wrap(txRequests[0].payload).should( 'eq', '0x1f0102000412ad770206045069201514711dc2456908b0af226442d475d12a5334e9c4513e001901000564696973056c6565670000000000000000' ) diff --git a/packages/ui/src/utils/encodeAccounts.ts b/packages/ui/src/utils/encodeAccounts.ts index c1114d05..0dea90a3 100644 --- a/packages/ui/src/utils/encodeAccounts.ts +++ b/packages/ui/src/utils/encodeAccounts.ts @@ -1,26 +1,34 @@ import { encodesubstrateAddress } from './encodeSubstrateAddress' import { InjectedPolkadotAccount } from 'polkadot-api/pjs-signer' -export const encodeAccounts = ( - accounts: InjectedPolkadotAccount[] | string[], +export function encodeAccounts(accounts: string[], ss58Format: number): string[] +export function encodeAccounts( + accounts: InjectedPolkadotAccount[], ss58Format: number -) => { - return accounts +): InjectedPolkadotAccount[] +export function encodeAccounts(accounts: unknown[], ss58Format: number): unknown[] { + if (!accounts || accounts.length === 0) return [] + + if (typeof accounts[0] === 'string') { + return (accounts as string[]) + .map((account) => encodesubstrateAddress(account, ss58Format)) + .filter(Boolean) as string[] + } + + return (accounts as InjectedPolkadotAccount[]) .map((account) => { - const addressToEncode = typeof account === 'string' ? account : account.address + const addressToEncode = account.address const encodedAddress = encodesubstrateAddress(addressToEncode, ss58Format) - if (typeof account === 'string') { - return encodedAddress + if (!encodedAddress) { + return null } - return encodedAddress - ? { - ...account, - address: encodedAddress - } - : null + return { + ...account, + address: encodedAddress + } as InjectedPolkadotAccount }) - .filter((acc) => !!acc) as InjectedPolkadotAccount[] + .filter(Boolean) as InjectedPolkadotAccount[] }