mirror of
https://github.com/pezkuwichain/pezkuwi-ui.git
synced 2026-06-14 02:11:01 +00:00
Use objectSpread as applicable (#538)
* Use objectSpread as applicable * Updates * Add objectSpread import
This commit is contained in:
@@ -10,7 +10,7 @@ import type { CreateResult, KeyringAddress, KeyringAddressType, KeyringItemType,
|
||||
|
||||
import { createPair } from '@polkadot/keyring';
|
||||
import { chains } from '@polkadot/ui-settings';
|
||||
import { bnToBn, hexToU8a, isHex, isString, stringToU8a, u8aSorted, u8aToString } from '@polkadot/util';
|
||||
import { bnToBn, hexToU8a, isHex, isString, objectSpread, stringToU8a, u8aSorted, u8aToString } from '@polkadot/util';
|
||||
import { base64Decode, createKeyMulti, jsonDecrypt, jsonEncrypt } from '@polkadot/util-crypto';
|
||||
|
||||
import { env } from './observable/env';
|
||||
@@ -33,7 +33,7 @@ export class Keyring extends Base implements KeyringStruct {
|
||||
};
|
||||
|
||||
public addExternal (address: string | Uint8Array, meta: KeyringPair$Meta = {}): CreateResult {
|
||||
const pair = this.keyring.addFromAddress(address, { ...meta, isExternal: true }, null);
|
||||
const pair = this.keyring.addFromAddress(address, objectSpread<KeyringJson$Meta>({}, meta, { isExternal: true }), null);
|
||||
|
||||
return {
|
||||
json: this.saveAccount(pair),
|
||||
@@ -42,7 +42,7 @@ export class Keyring extends Base implements KeyringStruct {
|
||||
}
|
||||
|
||||
public addHardware (address: string | Uint8Array, hardwareType: string, meta: KeyringPair$Meta = {}): CreateResult {
|
||||
return this.addExternal(address, { ...meta, hardwareType, isHardware: true });
|
||||
return this.addExternal(address, objectSpread<KeyringPair$Meta>({}, meta, { hardwareType, isHardware: true }));
|
||||
}
|
||||
|
||||
public addMultisig (addresses: (string | Uint8Array)[], threshold: bigint | BN | number, meta: KeyringPair$Meta = {}): CreateResult {
|
||||
@@ -51,7 +51,7 @@ export class Keyring extends Base implements KeyringStruct {
|
||||
// we could use `sortAddresses`, but rather use internal encode/decode so we are 100%
|
||||
const who = u8aSorted(addresses.map((who) => this.decodeAddress(who))).map((who) => this.encodeAddress(who));
|
||||
|
||||
return this.addExternal(address, { ...meta, isMultisig: true, threshold: bnToBn(threshold).toNumber(), who });
|
||||
return this.addExternal(address, objectSpread<KeyringPair$Meta>({}, meta, { isMultisig: true, threshold: bnToBn(threshold).toNumber(), who }));
|
||||
}
|
||||
|
||||
public addPair (pair: KeyringPair, password: string): CreateResult {
|
||||
@@ -91,17 +91,20 @@ export class Keyring extends Base implements KeyringStruct {
|
||||
|
||||
const accounts = await Promise.all(accountPromises);
|
||||
|
||||
return {
|
||||
...jsonEncrypt(stringToU8a(JSON.stringify(accounts)), ['batch-pkcs8'], password),
|
||||
return objectSpread({}, jsonEncrypt(stringToU8a(JSON.stringify(accounts)), ['batch-pkcs8'], password), {
|
||||
accounts: accounts.map((account) => ({
|
||||
address: account.address,
|
||||
meta: account.meta
|
||||
}))
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
public createFromJson (json: KeyringPair$Json, meta: KeyringPair$Meta = {}): KeyringPair {
|
||||
return this.keyring.createFromJson({ ...json, meta: { ...(json.meta || {}), meta } });
|
||||
return this.keyring.createFromJson(
|
||||
objectSpread({}, json, {
|
||||
meta: objectSpread({}, json.meta, meta)
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public createFromUri (suri: string, meta: KeyringPair$Meta = {}, type?: KeypairType): KeyringPair {
|
||||
@@ -249,10 +252,7 @@ export class Keyring extends Base implements KeyringStruct {
|
||||
private loadInjected (address: string, meta: KeyringJson$Meta, type?: KeypairType): void {
|
||||
const json = {
|
||||
address,
|
||||
meta: {
|
||||
...meta,
|
||||
isInjected: true
|
||||
}
|
||||
meta: objectSpread<KeyringJson$Meta>({}, meta, { isInjected: true })
|
||||
};
|
||||
const pair = this.keyring.addFromAddress(address, json.meta, null, type);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user