@@ -20,6 +20,7 @@ import type { StringMap } from '../../../types/types'
2020import { CryptoAmount } from '../../../util/CryptoAmount'
2121import { getCurrencyCodeMultiplier } from '../../../util/CurrencyInfoHelpers'
2222import { fetchInfo } from '../../../util/network'
23+ import { makePeriodicTask } from '../../../util/PeriodicTask'
2324import { consify , removeIsoPrefix } from '../../../util/utils'
2425import { SendErrorBackPressed , SendErrorNoTransaction } from '../fiatPlugin'
2526import type { FiatDirection , FiatPaymentType } from '../fiatPluginTypes'
@@ -757,7 +758,7 @@ export const banxaProvider: FiatProviderFactory = {
757758 throw new Error ( banxaQuote . errors . title )
758759 }
759760
760- let interval : ReturnType < typeof setInterval > | undefined
761+ let interval : ReturnType < typeof makePeriodicTask > | undefined
761762 let insideInterval = false
762763
763764 if ( direction === 'buy' ) {
@@ -845,18 +846,18 @@ export const banxaProvider: FiatProviderFactory = {
845846 ) : Promise < void > => {
846847 console . log ( `onUrlChange url=${ changeUrl } ` )
847848 if ( changeUrl === RETURN_URL_SUCCESS ) {
848- clearInterval ( interval )
849+ interval ?. stop ( )
849850
850851 await showUi . exitScene ( )
851852 } else if ( changeUrl === RETURN_URL_CANCEL ) {
852- clearInterval ( interval )
853+ interval ?. stop ( )
853854 await showUi . showToast (
854855 lstrings . fiat_plugin_sell_cancelled ,
855856 NOT_SUCCESS_TOAST_HIDE_MS
856857 )
857858 await showUi . exitScene ( )
858859 } else if ( changeUrl === RETURN_URL_FAIL ) {
859- clearInterval ( interval )
860+ interval ?. stop ( )
860861 await showUi . showToast (
861862 lstrings . fiat_plugin_sell_failed_try_again ,
862863 NOT_SUCCESS_TOAST_HIDE_MS
@@ -913,7 +914,7 @@ export const banxaProvider: FiatProviderFactory = {
913914 const edgeTx = await showUi . send ( sendParams )
914915
915916 // At this point we'll call it success
916- clearInterval ( interval )
917+ interval ?. stop ( )
917918 interval = undefined
918919
919920 await showUi . trackConversion ( 'Sell_Success' , {
@@ -971,17 +972,18 @@ export const banxaProvider: FiatProviderFactory = {
971972 insideInterval = false
972973 }
973974 }
974- interval ??= setInterval ( ( ) => {
975+ interval ??= makePeriodicTask ( ( ) => {
975976 statusUpdateAsync ( ) . catch ( ( error : unknown ) => {
976977 showError ( error )
977978 } )
978979 } , 3000 )
980+ interval . start ( { wait : true } )
979981 }
980982 }
981983 await showUi . openWebView ( {
982984 url : checkoutUrl ,
983985 onClose : ( ) => {
984- clearInterval ( interval )
986+ interval ?. stop ( )
985987 } ,
986988 onUrlChange : ( changeUrl : string ) => {
987989 onUrlChangeAsync ( changeUrl ) . catch ( ( error : unknown ) => {
0 commit comments