Skip to content
This repository has been archived by the owner on Nov 24, 2020. It is now read-only.

Commit

Permalink
Better error handling(#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiero authored Apr 28, 2020
1 parent 70a9ac7 commit f1633b7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/components/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export default class Wallet implements WalletInterface {
inputAsset: string,
outputAsset: string
): string {
if (inputs.length === 0) throw new Error('Swap: No utxos available');

let psbt: Psbt;
try {
psbt = Psbt.fromBase64(psbtBase64);
Expand Down Expand Up @@ -116,6 +118,8 @@ export default class Wallet implements WalletInterface {
}

payFees(psbtBase64: string, utxos: any[]): string {
if (utxos.length === 0) throw new Error('Fees: No utxos available');

const psbt = Psbt.fromBase64(psbtBase64);
const tx = Transaction.fromBuffer(psbt.data.getTransaction());
const { fees } = calculateFees(tx.ins.length + 1, tx.outs.length + 2);
Expand Down
3 changes: 2 additions & 1 deletion src/utils/coinselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export function coinselect(utxos, amount) {
if (availableSat >= amount) break;
}

if (availableSat < amount) throw 'You do not have enough in your wallet';
if (availableSat < amount)
throw new Error('You do not have enough in your wallet');

change = availableSat - amount;

Expand Down

0 comments on commit f1633b7

Please sign in to comment.