diff --git a/commands/account/create.js b/commands/account/create.js index 66a51999..a69f3691 100644 --- a/commands/account/create.js +++ b/commands/account/create.js @@ -117,11 +117,14 @@ async function create(options) { try { // Handle response const response = await promise; + if (keyPair) { storeCredentials(newAccountId, options.networkId, options.keyStore, keyPair, true); - } else { - console.log(chalk`{bold.white ${newAccountId}} created successfully, please add its credentials manually.`); } + + // The faucet does not throw on error, so we force it here + if (options.useFaucet) { await response.state(); } + inspectResponse.prettyPrintResponse(response, options); } catch (error) { // Handle errors @@ -144,6 +147,11 @@ async function create(options) { console.error(chalk`\nYou cannot create Top Level Accounts.`); process.exit(1); break; + case 'AccountDoesNotExist': + if (!options.useFaucet) throw error; + console.error(chalk`\nThe faucet reported {bold.white no errors}, but we {bold.red cannot} find ${options.newAccountId}. Check if it exists with "near state ${options.newAccountId} --networkId ${options.networkId}".\n`); + process.exit(1); + break; default: throw error; } diff --git a/commands/account/delete.js b/commands/account/delete.js index 945fb07a..a08d7fe4 100644 --- a/commands/account/delete.js +++ b/commands/account/delete.js @@ -46,13 +46,30 @@ async function deleteAccount(options) { } } - if (options.force || await confirmDelete(options.accountId, options.beneficiaryId)) { - const account = await near.account(options.accountId); - console.log(`Deleting account ${options.accountId}, beneficiary: ${options.beneficiaryId}`); + if (!options.force && !(await confirmDelete(options.accountId, options.beneficiaryId))) { + return console.log(chalk`{bold.white Deletion of account {bold.blue ${options.accountId}} was {bold.red cancelled}}`); + } + + const account = await near.account(options.accountId); + console.log(`Deleting account ${options.accountId}, beneficiary: ${options.beneficiaryId}`); + + try { const result = await account.deleteAccount(options.beneficiaryId); console.log(`Account ${options.accountId} for network "${options.networkId}" was deleted.`); inspectResponse.prettyPrintResponse(result, options); - } else { - console.log(chalk`{bold.white Deletion of account {bold.blue ${options.accountId}} was {bold.red cancelled}}`); + } catch (error) { + switch (error.type) { + case 'KeyNotFound': + console.log(chalk`\n{bold.white ${options.accountId}} was not found in the network ${options.networkId}\n`); + process.exit(1); + break; + case 'SignerDoesNotExist': + // On re-sending a transaction, the signer might have been deleted already + console.log('RPC returned an error, please check if the account is deleted and try again'); + process.exit(0); + break; + default: + throw error; + } } } \ No newline at end of file