Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
fix: small errors on create and delete
Browse files Browse the repository at this point in the history
  • Loading branch information
gagdiez committed Feb 12, 2024
1 parent 42e9604 commit e59211c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
12 changes: 10 additions & 2 deletions commands/account/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
27 changes: 22 additions & 5 deletions commands/account/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

0 comments on commit e59211c

Please sign in to comment.