From c5c8a20ca4d63b10e4911a094a8d51f92a4259c0 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 18 Jan 2019 11:21:44 +0100 Subject: [PATCH] Small fixes & tweaks (#614) * Small fixes & tweaks * lintin fix (extra import) * ui-params inputs AccountIndex as number --- packages/app-accounts/src/Creator.tsx | 24 +++++++++++-------- packages/app-transfer/src/Transfer.tsx | 2 -- packages/ui-params/src/Param/findComponent.ts | 2 +- packages/ui-params/src/initValue.ts | 2 +- packages/ui-signer/src/Modal.tsx | 12 ++++++---- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/packages/app-accounts/src/Creator.tsx b/packages/app-accounts/src/Creator.tsx index 245eccccc5..556e572644 100644 --- a/packages/app-accounts/src/Creator.tsx +++ b/packages/app-accounts/src/Creator.tsx @@ -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 { 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 { 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' }); diff --git a/packages/app-transfer/src/Transfer.tsx b/packages/app-transfer/src/Transfer.tsx index d938dce8ee..161d02b56c 100644 --- a/packages/app-transfer/src/Transfer.tsx +++ b/packages/app-transfer/src/Transfer.tsx @@ -139,8 +139,6 @@ class Transfer extends React.PureComponent { ? apiPromise.tx.balances.transfer(recipientId, amount) : null; - console.log('extrinsic', extrinsic); - return { accountId, amount, diff --git a/packages/ui-params/src/Param/findComponent.ts b/packages/ui-params/src/Param/findComponent.ts index 7636ded768..39270fe624 100644 --- a/packages/ui-params/src/Param/findComponent.ts +++ b/packages/ui-params/src/Param/findComponent.ts @@ -25,7 +25,7 @@ import VoteThreshold from './VoteThreshold'; const components: ComponentMap = { 'AccountId': Account, - 'AccountIndex': Account, + 'AccountIndex': Amount, 'Address': Account, 'Balance': Balance, 'BlockNumber': Amount, diff --git a/packages/ui-params/src/initValue.ts b/packages/ui-params/src/initValue.ts index 4a4f27c5f8..7ea4f55062 100644 --- a/packages/ui-params/src/initValue.ts +++ b/packages/ui-params/src/initValue.ts @@ -24,6 +24,7 @@ export default function getInitValue (def: TypeDef): RawParam$Value | Array { 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 { 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);