Skip to content

Commit 6599d88

Browse files
authored
fix(connext): not enough balance for closechannel (#1963)
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.
1 parent 8483e1e commit 6599d88

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: lib/connextclient/ConnextClient.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,12 @@ class ConnextClient extends SwapClient {
768768
if (!currency) {
769769
throw errors.CURRENCY_MISSING;
770770
}
771-
const amount = units || (await this.getBalance(currency)).freeBalanceOffChain;
771+
const { freeBalanceOffChain } = await this.getBalance(currency);
772+
const availableUnits = Number(freeBalanceOffChain);
773+
if (units && availableUnits < units) {
774+
throw errors.INSUFFICIENT_BALANCE;
775+
}
776+
const amount = units || freeBalanceOffChain;
772777

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

0 commit comments

Comments
 (0)