Skip to content

Commit e9f1e5c

Browse files
Jon-edgesamholmes
authored andcommitted
Fix getFreshAddress after creating a wallet
Fix `getFreshAddress` to return a non-empty `publicAddress` when calling immediately after creating a wallet
1 parent 0c9d178 commit e9f1e5c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Unreleased
44

5+
- fixed: Fix `getFreshAddress` to return a non-empty `publicAddress` when calling immediately after creating a wallet.
56
- fixed: Handle insufficient funds errors from native library into `InsufficientFundsError`.
67

78
## 1.5.0 (2025-04-21)

src/MoneroEngine.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export class MoneroEngine implements EdgeCurrencyEngine {
8585
log: EdgeLog
8686
currencyTools: MoneroTools
8787
seenTxCheckpoint: number | undefined
88+
loginPromise: Promise<void> | null = null
8889

8990
constructor(
9091
env: EdgeCorePluginOptions,
@@ -174,6 +175,20 @@ export class MoneroEngine implements EdgeCurrencyEngine {
174175
// Login to mymonero.com server
175176
// **********************************************
176177
async loginIfNewAddress(privateKeys: PrivateKeys): Promise<void> {
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+
private async performLogin(privateKeys: PrivateKeys): Promise<void> {
177192
try {
178193
const result = await this.myMoneroApi.login({
179194
address: this.walletInfo.keys.moneroAddress,
@@ -578,8 +593,18 @@ export class MoneroEngine implements EdgeCurrencyEngine {
578593
async getFreshAddress(
579594
options: EdgeGetReceiveAddressOptions
580595
): Promise<EdgeFreshAddress> {
596+
// Wait for login to complete if it's in progress
597+
if (this.loginPromise != null) {
598+
await this.loginPromise
599+
}
600+
581601
// 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+
}
583608
return { publicAddress: this.walletInfo.keys.moneroAddress }
584609
}
585610

0 commit comments

Comments
 (0)