Skip to content

Commit

Permalink
fix(connext): not enough balance for closechannel (#1963)
Browse files Browse the repository at this point in the history
This introduces better error handling for Connext when using
`closeChannel` to remove funds from a Connext channel and specifying an
amount to remove that is greater than the available balance.
  • Loading branch information
sangaman authored Oct 28, 2020
1 parent 8483e1e commit 6599d88
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/connextclient/ConnextClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,12 @@ class ConnextClient extends SwapClient {
if (!currency) {
throw errors.CURRENCY_MISSING;
}
const amount = units || (await this.getBalance(currency)).freeBalanceOffChain;
const { freeBalanceOffChain } = await this.getBalance(currency);
const availableUnits = Number(freeBalanceOffChain);
if (units && availableUnits < units) {
throw errors.INSUFFICIENT_BALANCE;
}
const amount = units || freeBalanceOffChain;

const withdrawResponse = await this.sendRequest('/withdraw', 'POST', {
recipient: destination,
Expand Down

0 comments on commit 6599d88

Please sign in to comment.