Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
yknl committed Dec 2, 2020
1 parent 60454f2 commit 427f3a7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 45 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/argparse.ts
Expand Up @@ -551,7 +551,7 @@ export const CLI_ARGS = {
type: 'string',
realtype: 'address',
pattern: `${ADDRESS_PATTERN}|${STACKS_ADDRESS_PATTERN}`,
}
},
],
minItems: 1,
maxItems: 1,
Expand Down
86 changes: 49 additions & 37 deletions packages/cli/src/cli.ts
Expand Up @@ -1482,24 +1482,27 @@ async function stackingStatus(network: CLINetworkAdapter, args: string[]): Promi
const txNetwork = network.isMainnet() ? new StacksMainnet() : new StacksTestnet();
const stacker = new StackingClient(stxAddress, txNetwork);

return stacker.getStatus().then((status: StackerInfo) => {
if (status.stacked) {
return {
amount_microstx: status.details!.amount_microstx,
first_reward_cycle: status.details!.first_reward_cycle,
lock_period: status.details!.lock_period,
unlock_height: status.details!.unlock_height,
pox_address: {
version: status.details!.pox_address.version.toString('hex'),
hashbytes: status.details!.pox_address.hashbytes.toString('hex')
}
};
} else {
return 'Account not actively participating in Stacking';
}
}).catch((error: any) => {
return error.toString();
});
return stacker
.getStatus()
.then((status: StackerInfo) => {
if (status.stacked) {
return {
amount_microstx: status.details!.amount_microstx,
first_reward_cycle: status.details!.first_reward_cycle,
lock_period: status.details!.lock_period,
unlock_height: status.details!.unlock_height,
pox_address: {
version: status.details!.pox_address.version.toString('hex'),
hashbytes: status.details!.pox_address.hashbytes.toString('hex'),
},
};
} else {
return 'Account not actively participating in Stacking';
}
})
.catch((error: any) => {
return error.toString();
});
}

async function canStack(network: CLINetworkAdapter, args: string[]): Promise<string> {
Expand All @@ -1524,19 +1527,23 @@ async function canStack(network: CLINetworkAdapter, args: string[]): Promise<str

const poxInfoPromise = stacker.getPoxInfo();

const stackingEligiblePromise = stacker.canStack({poxAddress, cycles});
const stackingEligiblePromise = stacker.canStack({ poxAddress, cycles });

return Promise.all([balancePromise, poxInfoPromise, stackingEligiblePromise])
.then(([balance, poxInfo, stackingEligible]) => {
const minAmount = new BN(poxInfo.min_amount_ustx);
const balanceBN = new BN(balance.stx.balance);

if (minAmount.gt(amount)) {
throw new Error(`Stacking amount less than required minimum of ${minAmount.toString()} microstacks`);
throw new Error(
`Stacking amount less than required minimum of ${minAmount.toString()} microstacks`
);
}

if (amount.gt(balanceBN)) {
throw new Error(`Stacking amount greater than account balance of ${balanceBN.toString()} microstacks`);
throw new Error(
`Stacking amount greater than account balance of ${balanceBN.toString()} microstacks`
);
}

if (!stackingEligible.eligible) {
Expand All @@ -1545,9 +1552,9 @@ async function canStack(network: CLINetworkAdapter, args: string[]): Promise<str

return stackingEligible;
})
.catch((error) => {
.catch(error => {
return error;
})
});
}

async function stack(network: CLINetworkAdapter, args: string[]): Promise<string> {
Expand Down Expand Up @@ -1588,7 +1595,7 @@ async function stack(network: CLINetworkAdapter, args: string[]): Promise<string

const coreInfoPromise = stacker.getCoreInfo();

const stackingEligiblePromise = stacker.canStack({poxAddress, cycles});
const stackingEligiblePromise = stacker.canStack({ poxAddress, cycles });

return Promise.all([balancePromise, poxInfoPromise, coreInfoPromise, stackingEligiblePromise])
.then(([balance, poxInfo, coreInfo, stackingEligible]) => {
Expand All @@ -1598,11 +1605,15 @@ async function stack(network: CLINetworkAdapter, args: string[]): Promise<string
const startBurnBlock = burnChainBlockHeight + 3;

if (minAmount.gt(amount)) {
throw new Error(`Stacking amount less than required minimum of ${minAmount.toString()} microstacks`);
throw new Error(
`Stacking amount less than required minimum of ${minAmount.toString()} microstacks`
);
}

if (amount.gt(balanceBN)) {
throw new Error(`Stacking amount greater than account balance of ${balanceBN.toString()} microstacks`);
throw new Error(
`Stacking amount greater than account balance of ${balanceBN.toString()} microstacks`
);
}

if (!stackingEligible.eligible) {
Expand All @@ -1626,9 +1637,9 @@ async function stack(network: CLINetworkAdapter, args: string[]): Promise<string
transaction: generateExplorerTxPageUrl(response as string, txNetwork),
};
})
.catch((error) => {
.catch(error => {
return error;
})
});
}

function faucetCall(_: CLINetworkAdapter, args: string[]): Promise<string> {
Expand All @@ -1642,15 +1653,16 @@ function faucetCall(_: CLINetworkAdapter, args: string[]): Promise<string> {

const faucets = new FaucetsApi(apiConfig);

return faucets.runFaucetStx({ address })
.then((faucetTx: any) => {
return JSONStringify({
txid: faucetTx.txId!,
transaction: generateExplorerTxPageUrl(faucetTx.txId!, new StacksTestnet()),
});
})
.catch((error: any) => error.toString());
}
return faucets
.runFaucetStx({ address })
.then((faucetTx: any) => {
return JSONStringify({
txid: faucetTx.txId!,
transaction: generateExplorerTxPageUrl(faucetTx.txId!, new StacksTestnet()),
});
})
.catch((error: any) => error.toString());
}

/* Print out all documentation on usage in JSON
*/
Expand Down
13 changes: 6 additions & 7 deletions packages/stacking/src/index.ts
Expand Up @@ -153,13 +153,12 @@ export class StackingClient {
* @returns {Promise<BN>} that resolves to a BigNum if the operation succeeds
*/
async getAccountBalance(): Promise<BN> {
return this.getAccountStatus()
.then((res) => {
let balanceHex = res.balance;
if (res.balance.startsWith('0x')) {
balanceHex = res.balance.substr(2);
}
return new BN(balanceHex, 'hex')
return this.getAccountStatus().then(res => {
let balanceHex = res.balance;
if (res.balance.startsWith('0x')) {
balanceHex = res.balance.substr(2);
}
return new BN(balanceHex, 'hex');
});
}

Expand Down

0 comments on commit 427f3a7

Please sign in to comment.