@@ -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