edge-currency-monero 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # edge-currency-monero
2
2
 
3
+ ## Unreleased
4
+
5
+ ## 1.5.1 (2025-07-03)
6
+
7
+ - fixed: Fix `getFreshAddress` to return a non-empty `publicAddress` when calling immediately after creating a wallet.
8
+ - fixed: Handle insufficient funds errors from native library into `InsufficientFundsError`.
9
+
3
10
  ## 1.5.0 (2025-04-21)
4
11
 
5
12
  - added: Support for multiple spend targets.
@@ -85,13 +85,14 @@ const PRIMARY_CURRENCY_TOKEN_ID = null
85
85
 
86
86
 
87
87
 
88
+ __init() {this.loginPromise = null}
88
89
 
89
90
  constructor(
90
91
  env,
91
92
  tools,
92
93
  walletInfo,
93
94
  opts
94
- ) {
95
+ ) {;MoneroEngine.prototype.__init.call(this);
95
96
  const { callbacks, userSettings = {}, walletLocalDisklet } = opts
96
97
  const initOptions = _moneroTypes.asMoneroInitOptions.call(void 0, _nullishCoalesce(env.initOptions, () => ( {})))
97
98
  const { networkInfo } = tools
@@ -174,6 +175,20 @@ const PRIMARY_CURRENCY_TOKEN_ID = null
174
175
  // Login to mymonero.com server
175
176
  // **********************************************
176
177
  async loginIfNewAddress(privateKeys) {
178
+ if (this.loginPromise != null) {
179
+ return await this.loginPromise
180
+ }
181
+ this.loginPromise = this.performLogin(privateKeys)
182
+
183
+ try {
184
+ await this.loginPromise
185
+ } finally {
186
+ // Clear the promise once completed (success OR failure)
187
+ this.loginPromise = null
188
+ }
189
+ }
190
+
191
+ async performLogin(privateKeys) {
177
192
  try {
178
193
  const result = await this.myMoneroApi.login({
179
194
  address: this.walletInfo.keys.moneroAddress,
@@ -578,8 +593,18 @@ const PRIMARY_CURRENCY_TOKEN_ID = null
578
593
  async getFreshAddress(
579
594
  options
580
595
  ) {
596
+ // Wait for login to complete if it's in progress
597
+ if (this.loginPromise != null) {
598
+ await this.loginPromise
599
+ }
600
+
581
601
  // Do not show the address before logging into my monero...
582
- if (!this.walletLocalData.hasLoggedIn) return { publicAddress: '' }
602
+ if (!this.walletLocalData.hasLoggedIn) {
603
+ this.log.warn(
604
+ 'Attempted to retrieve `publicAddress` before successfully logging in'
605
+ )
606
+ return { publicAddress: '' }
607
+ }
583
608
  return { publicAddress: this.walletInfo.keys.moneroAddress }
584
609
  }
585
610
 
@@ -629,12 +654,20 @@ const PRIMARY_CURRENCY_TOKEN_ID = null
629
654
  },
630
655
  options
631
656
  )
632
- } catch (e) {
657
+ } catch (error) {
658
+ if (!(error instanceof Error)) {
659
+ throw new Error(String(error))
660
+ }
661
+ if (error.message === 'Not enough spendables') {
662
+ throw new (0, _types.InsufficientFundsError)({
663
+ tokenId: PRIMARY_CURRENCY_TOKEN_ID
664
+ })
665
+ }
633
666
  // 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)
667
+ this.log.error(error.message)
635
668
  const regex = / Have (\d*\.?\d+) XMR; need (\d*\.?\d+) XMR./gm
636
669
  const subst = `\nHave: $1 XMR.\nNeed: $2 XMR.`
637
- const msgFormatted = e.message.replace(regex, subst)
670
+ const msgFormatted = error.message.replace(regex, subst)
638
671
  throw new Error(msgFormatted)
639
672
  }
640
673
  }