Small fixes & tweaks (#614)
* Small fixes & tweaks * lintin fix (extra import) * ui-params inputs AccountIndex as number
This commit is contained in:
parent
cc875402d6
commit
c5c8a20ca4
@ -40,17 +40,25 @@ type State = {
|
||||
showWarning: boolean
|
||||
};
|
||||
|
||||
function formatSeed (seed: string): Uint8Array {
|
||||
return isHex(seed)
|
||||
function isHexSeed (seed: string): boolean {
|
||||
return isHex(seed) && seed.length === 66;
|
||||
}
|
||||
|
||||
function rawValidate (seed: string): boolean {
|
||||
return seed.length <= 32 || isHexSeed(seed);
|
||||
}
|
||||
|
||||
function rawToSeed (seed: string): Uint8Array {
|
||||
return isHexSeed(seed)
|
||||
? hexToU8a(seed)
|
||||
: stringToU8a((seed as string).padEnd(32, ' '));
|
||||
: stringToU8a(seed.padEnd(32, ' '));
|
||||
}
|
||||
|
||||
function addressFromSeed (seed: string, seedType: SeedType): string {
|
||||
const keypair = naclKeypairFromSeed(
|
||||
seedType === 'bip'
|
||||
? mnemonicToSeed(seed)
|
||||
: formatSeed(seed)
|
||||
: rawToSeed(seed)
|
||||
);
|
||||
|
||||
return keyring.encodeAddress(
|
||||
@ -306,11 +314,7 @@ class Creator extends React.PureComponent<Props, State> {
|
||||
const isNameValid = !!name;
|
||||
const isSeedValid = seedType === 'bip'
|
||||
? mnemonicValidate(seed)
|
||||
: (
|
||||
isHex(seed)
|
||||
? seed.length === 66
|
||||
: (seed as string).length <= 32
|
||||
);
|
||||
: rawValidate(seed);
|
||||
const isPassValid = keyring.isPassValid(password);
|
||||
|
||||
if (isSeedValid && seed !== prevState.seed) {
|
||||
@ -366,7 +370,7 @@ class Creator extends React.PureComponent<Props, State> {
|
||||
try {
|
||||
const pair = seedType === 'bip'
|
||||
? keyring.createAccountMnemonic(seed, password, { name })
|
||||
: keyring.createAccount(formatSeed(seed), password, { name });
|
||||
: keyring.createAccount(rawToSeed(seed), password, { name });
|
||||
|
||||
const json = pair.toJson(password);
|
||||
const blob = new Blob([JSON.stringify(json)], { type: 'application/json; charset=utf-8' });
|
||||
|
||||
@ -139,8 +139,6 @@ class Transfer extends React.PureComponent<Props, State> {
|
||||
? apiPromise.tx.balances.transfer(recipientId, amount)
|
||||
: null;
|
||||
|
||||
console.log('extrinsic', extrinsic);
|
||||
|
||||
return {
|
||||
accountId,
|
||||
amount,
|
||||
|
||||
@ -25,7 +25,7 @@ import VoteThreshold from './VoteThreshold';
|
||||
|
||||
const components: ComponentMap = {
|
||||
'AccountId': Account,
|
||||
'AccountIndex': Account,
|
||||
'AccountIndex': Amount,
|
||||
'Address': Account,
|
||||
'Balance': Balance,
|
||||
'BlockNumber': Amount,
|
||||
|
||||
@ -24,6 +24,7 @@ export default function getInitValue (def: TypeDef): RawParam$Value | Array<RawP
|
||||
: def.type;
|
||||
|
||||
switch (type) {
|
||||
case 'AccountIndex':
|
||||
case 'Balance':
|
||||
case 'BlockNumber':
|
||||
case 'Compact':
|
||||
@ -55,7 +56,6 @@ export default function getInitValue (def: TypeDef): RawParam$Value | Array<RawP
|
||||
return 0;
|
||||
|
||||
case 'AccountId':
|
||||
case 'AccountIndex':
|
||||
case 'Address':
|
||||
case 'Bytes':
|
||||
case 'Call':
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { SubmittableSendResult } from '@polkadot/api/types';
|
||||
import { PromiseSubscription, SubmittableExtrinsic } from '@polkadot/api/promise/types';
|
||||
import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
|
||||
import { ApiProps } from '@polkadot/ui-api/types';
|
||||
import { I18nProps, BareProps } from '@polkadot/ui-app/types';
|
||||
import { RpcMethod } from '@polkadot/jsonrpc/types';
|
||||
@ -306,7 +306,11 @@ class Signer extends React.PureComponent<Props, State> {
|
||||
const { queueSetTxStatus } = this.props;
|
||||
|
||||
try {
|
||||
const subscription = await extrinsicCall.apply(extrinsic, [..._params, async (result: SubmittableSendResult) => {
|
||||
const unsubscribe = await extrinsicCall.apply(extrinsic, [..._params, async (result: SubmittableSendResult) => {
|
||||
if (!result || !result.type || !result.status) {
|
||||
return;
|
||||
}
|
||||
|
||||
const status = result.type.toLowerCase() as QueueTx$Status;
|
||||
|
||||
console.log('submitAndWatchExtrinsic: updated status ::', result);
|
||||
@ -314,11 +318,9 @@ class Signer extends React.PureComponent<Props, State> {
|
||||
queueSetTxStatus(id, status, result);
|
||||
|
||||
if (status === 'finalised') {
|
||||
const unsubscribe = await subscription;
|
||||
|
||||
unsubscribe();
|
||||
}
|
||||
}]) as PromiseSubscription;
|
||||
}]);
|
||||
} catch (error) {
|
||||
console.error('error.message', error.message);
|
||||
queueSetTxStatus(id, 'error', {}, error);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user