-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
23 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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[] | ||
} |