22import { gt , lt } from 'biggystring'
33import { asArray , asEither , asNumber , asObject , asString } from 'cleaners'
44
5+ import { lstrings } from '../../../locales/strings'
6+ import { CryptoAmount } from '../../../util/CryptoAmount'
57import { fetchInfo } from '../../../util/network'
68import { asFiatPaymentType , FiatPaymentType } from '../fiatPluginTypes'
79import {
@@ -16,7 +18,7 @@ import {
1618 FiatProviderQuote
1719} from '../fiatProviderTypes'
1820import { addTokenToArray } from '../util/providerUtils'
19- import { addExactRegion , isDailyCheckDue , validateExactRegion } from './common'
21+ import { addExactRegion , isDailyCheckDue , NOT_SUCCESS_TOAST_HIDE_MS , validateExactRegion } from './common'
2022const providerId = 'simplex'
2123const storeId = 'co.edgesecure.simplex'
2224const partnerIcon = 'simplex-logo-sm-square.png'
@@ -313,6 +315,8 @@ export const simplexProvider: FiatProviderFactory = {
313315 throw new Error ( 'Simplex unknown error' )
314316 }
315317 const goodQuote = asSimplexQuoteSuccess ( quote )
318+ const quoteFiatAmount = goodQuote . fiat_money . amount . toString ( )
319+ const quoteCryptAmount = goodQuote . digital_money . amount . toString ( )
316320
317321 const paymentQuote : FiatProviderQuote = {
318322 providerId,
@@ -323,8 +327,8 @@ export const simplexProvider: FiatProviderFactory = {
323327 displayCurrencyCode : params . displayCurrencyCode ,
324328 isEstimate : false ,
325329 fiatCurrencyCode : params . fiatCurrencyCode ,
326- fiatAmount : goodQuote . fiat_money . amount . toString ( ) ,
327- cryptoAmount : goodQuote . digital_money . amount . toString ( ) ,
330+ fiatAmount : quoteFiatAmount ,
331+ cryptoAmount : quoteCryptAmount ,
328332 direction : params . direction ,
329333 expirationDate : new Date ( Date . now ( ) + 8000 ) ,
330334 approveQuote : async ( approveParams : FiatProviderApproveQuoteParams ) : Promise < void > => {
@@ -355,9 +359,48 @@ export const simplexProvider: FiatProviderFactory = {
355359 const url = `https://partners.simplex.com/?partner=${ partner } &t=${ token } `
356360
357361 console . log ( 'Approving simplex quote url=' + url )
358- await showUi . openExternalWebView ( { url } )
362+ await showUi . openExternalWebView ( {
363+ url,
364+ providerId,
365+ deeplinkHandler : async link => {
366+ if ( link . direction !== 'buy' ) return
367+
368+ const orderId = link . query . orderId ?? 'unknown'
369+
370+ switch ( link . query . status ) {
371+ case 'success' : {
372+ await showUi . trackConversion ( 'Buy_Success' , {
373+ conversionValues : {
374+ conversionType : 'buy' ,
375+ sourceFiatCurrencyCode : params . fiatCurrencyCode ,
376+ sourceFiatAmount : quoteFiatAmount ,
377+ destAmount : new CryptoAmount ( {
378+ currencyConfig : coreWallet . currencyConfig ,
379+ currencyCode : displayCurrencyCode ,
380+ exchangeAmount : quoteCryptAmount
381+ } ) ,
382+ fiatProviderId : providerId ,
383+ orderId
384+ }
385+ } )
386+ await showUi . exitScene ( )
387+ break
388+ }
389+ case 'failure' : {
390+ console . log ( 'Simplex WebView launch buy failure: ' + link . uri )
391+ await showUi . showToast ( lstrings . fiat_plugin_buy_failed_try_again , NOT_SUCCESS_TOAST_HIDE_MS )
392+ await showUi . exitScene ( )
393+ break
394+ }
395+ default : {
396+ await showUi . showToast ( lstrings . fiat_plugin_buy_unknown_status , NOT_SUCCESS_TOAST_HIDE_MS )
397+ await showUi . exitScene ( )
398+ }
399+ }
400+ }
401+ } )
359402 } ,
360- closeQuote : async ( ) : Promise < void > => { }
403+ closeQuote : async ( ) : Promise < void > => { }
361404 }
362405 return paymentQuote
363406 } ,
0 commit comments