mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-07-27 06:35:41 +00:00
c71ddb6e0d
- Clone Polkadot.js Apps repository - Update package.json with Pezkuwi branding - Add Pezkuwi endpoint to production chains (wss://pezkuwichain.app:9944) - Create comprehensive README for SDK UI - Set up project structure with all packages Next steps: - Apply Kurdistan colors (Kesk, Sor, Zer, Spi + Black) to UI theme - Replace logos with Pezkuwi branding - Test build and deployment
33 lines
1008 B
TypeScript
33 lines
1008 B
TypeScript
// Copyright 2017-2025 @polkadot/react-components authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import { keyring } from '@polkadot/ui-keyring';
|
|
import { hexToU8a, isHex } from '@polkadot/util';
|
|
import { ethereumEncode } from '@polkadot/util-crypto';
|
|
|
|
export function toAddress (value?: string | Uint8Array | null, allowIndices = false, bytesLength?: 20 | 32): string | undefined {
|
|
if (value) {
|
|
try {
|
|
const u8a = isHex(value)
|
|
? hexToU8a(value)
|
|
: keyring.decodeAddress(value);
|
|
|
|
if (!allowIndices && u8a.length !== 32 && u8a.length !== 20) {
|
|
throw new Error('AccountIndex values not allowed');
|
|
} else if (bytesLength && u8a.length !== bytesLength) {
|
|
throw new Error('Invalid key length');
|
|
}
|
|
|
|
if (u8a.length === 20) {
|
|
return ethereumEncode(u8a);
|
|
} else {
|
|
return keyring.encodeAddress(u8a);
|
|
}
|
|
} catch {
|
|
// undefined return below indicates invalid/transient
|
|
}
|
|
}
|
|
|
|
return undefined;
|
|
}
|