Skip to content

Commit 4707f8f

Browse files
committed
Translate spend errors from lib to InsufficientFundsError
1 parent 26b40d2 commit 4707f8f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# edge-currency-monero
22

3+
# Unreleased
4+
5+
- fixed: Handle insufficient funds errors from native library into `InsufficientFundsError`.
6+
37
## 1.5.0 (2025-04-21)
48

59
- added: Support for multiple spend targets.

src/MoneroEngine.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,12 +629,20 @@ export class MoneroEngine implements EdgeCurrencyEngine {
629629
},
630630
options
631631
)
632-
} catch (e: any) {
632+
} catch (error: unknown) {
633+
if (!(error instanceof Error)) {
634+
throw new Error(String(error))
635+
}
636+
if (error.message === 'Not enough spendables') {
637+
throw new InsufficientFundsError({
638+
tokenId: PRIMARY_CURRENCY_TOKEN_ID
639+
})
640+
}
633641
// This error is specific to mymonero-core-js: github.com/mymonero/mymonero-core-cpp/blob/a53e57f2a376b05bb0f4d851713321c749e5d8d9/src/monero_transfer_utils.hpp#L112-L162
634-
this.log.error(e.message)
642+
this.log.error(error.message)
635643
const regex = / Have (\d*\.?\d+) XMR; need (\d*\.?\d+) XMR./gm
636644
const subst = `\nHave: $1 XMR.\nNeed: $2 XMR.`
637-
const msgFormatted = e.message.replace(regex, subst)
645+
const msgFormatted = error.message.replace(regex, subst)
638646
throw new Error(msgFormatted)
639647
}
640648
}

0 commit comments

Comments
 (0)