Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion tracking for Banxa and Simplex #5368

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ const strings = {
transaction_details_fee_warning: 'High Network Fees',
transaction_details_swap: 'Swap Funds',
transaction_details_swap_network_fee: 'Swap Network Fee',
transaction_details_swap_order_cancel: 'Swap Order Canceled',
transaction_details_swap_order_cancel: 'Swap Order Cancelled',
transaction_details_swap_order_post: 'Swap Order Opened',
transaction_details_swap_order_fill: 'Swap Order Filled',
transaction_details_claim: 'Claim Staked Funds',
Expand Down Expand Up @@ -1464,11 +1464,13 @@ const strings = {
fiat_plugin_fetching_assets: 'Fetching supported assets',
fiat_plugin_sell_cancelled: 'Sell order cancelled',
fiat_plugin_finalizing_quote: 'Finalizing your exchange quote. Please wait as this may take up to a minute',
fiat_plugin_buy_cancelled: 'Buy order cancelled',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Common misspelling. In American English, it's actually "canceled."

Recommend changing all these here and in the respective jsons. See transaction_details_swap_order_cancel

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, change transaction_details_swap_order_cancel to use two L's, since Americans don't really follow American spelling for this, anyway.

Either way, just make sure we're consistent.

fiat_plugin_buy_complete_title: 'Buy Order Complete',
fiat_plugin_buy_complete_message_s: 'Your buy order of %1$s %2$s with %3$s %4$s has been completed.',
fiat_plugin_buy_complete_message_2_hour_s: 'Please allow up to %1$s hour for the funds to appear in your wallet.',
fiat_plugin_buy_complete_message_2_hours_s: 'Please allow up to %1$s hours for the funds to appear in your wallet.',
fiat_plugin_buy_failed_try_again: 'Buy order failed. Please try again',
fiat_plugin_buy_unknown_status: 'Unknown order status upon completion. Please contact support for assistence.',
fiat_plugin_sell_complete_title: 'Sell Order Complete',
fiat_plugin_sell_complete_message_s: 'Your sell order of %1$s %2$s for %3$s %4$s has been completed.',
fiat_plugin_sell_complete_message_2_hour_s: 'Please allow up to %1$s hour for the funds to appear in your account.',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/strings/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@
"transaction_details_fee_warning": "Hohe Netzwerkgebühren",
"transaction_details_swap": "Swap Funds",
"transaction_details_swap_network_fee": "Swap Network Fee",
"transaction_details_swap_order_cancel": "Swap Order Canceled",
"transaction_details_swap_order_cancel": "Swap Order Cancelled",
"transaction_details_swap_order_post": "Swap Order Opened",
"transaction_details_swap_order_fill": "Swap Order Filled",
"transaction_details_claim": "Claim Staked Funds",
Expand Down
4 changes: 3 additions & 1 deletion src/locales/strings/enUS.json
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@
"transaction_details_fee_warning": "High Network Fees",
"transaction_details_swap": "Swap Funds",
"transaction_details_swap_network_fee": "Swap Network Fee",
"transaction_details_swap_order_cancel": "Swap Order Canceled",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other languages?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to replace this string in other languages that are untranslated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "replace the string"?

"transaction_details_swap_order_cancel": "Swap Order Cancelled",
"transaction_details_swap_order_post": "Swap Order Opened",
"transaction_details_swap_order_fill": "Swap Order Filled",
"transaction_details_claim": "Claim Staked Funds",
Expand Down Expand Up @@ -1295,11 +1295,13 @@
"fiat_plugin_fetching_assets": "Fetching supported assets",
"fiat_plugin_sell_cancelled": "Sell order cancelled",
"fiat_plugin_finalizing_quote": "Finalizing your exchange quote. Please wait as this may take up to a minute",
"fiat_plugin_buy_cancelled": "Buy order cancelled",
"fiat_plugin_buy_complete_title": "Buy Order Complete",
"fiat_plugin_buy_complete_message_s": "Your buy order of %1$s %2$s with %3$s %4$s has been completed.",
"fiat_plugin_buy_complete_message_2_hour_s": "Please allow up to %1$s hour for the funds to appear in your wallet.",
"fiat_plugin_buy_complete_message_2_hours_s": "Please allow up to %1$s hours for the funds to appear in your wallet.",
"fiat_plugin_buy_failed_try_again": "Buy order failed. Please try again",
"fiat_plugin_buy_unknown_status": "Unknown order status upon completion. Please contact support for assistence.",
"fiat_plugin_sell_complete_title": "Sell Order Complete",
"fiat_plugin_sell_complete_message_s": "Your sell order of %1$s %2$s for %3$s %4$s has been completed.",
"fiat_plugin_sell_complete_message_2_hour_s": "Please allow up to %1$s hour for the funds to appear in your account.",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/strings/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@
"transaction_details_fee_warning": "Tarifas de red altas",
"transaction_details_swap": "Swap Funds",
"transaction_details_swap_network_fee": "Swap Network Fee",
"transaction_details_swap_order_cancel": "Swap Order Canceled",
"transaction_details_swap_order_cancel": "Swap Order Cancelled",
"transaction_details_swap_order_post": "Swap Order Opened",
"transaction_details_swap_order_fill": "Swap Order Filled",
"transaction_details_claim": "Claim Staked Funds",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/strings/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@
"transaction_details_fee_warning": "High Network Fees",
"transaction_details_swap": "Swap Funds",
"transaction_details_swap_network_fee": "Swap Network Fee",
"transaction_details_swap_order_cancel": "Swap Order Canceled",
"transaction_details_swap_order_cancel": "Swap Order Cancelled",
"transaction_details_swap_order_post": "Swap Order Opened",
"transaction_details_swap_order_fill": "Swap Order Filled",
"transaction_details_claim": "Claim Staked Funds",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/strings/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@
"transaction_details_fee_warning": "高いネットワーク手数料",
"transaction_details_swap": "Swap Funds",
"transaction_details_swap_network_fee": "Swap Network Fee",
"transaction_details_swap_order_cancel": "Swap Order Canceled",
"transaction_details_swap_order_cancel": "Swap Order Cancelled",
"transaction_details_swap_order_post": "Swap Order Opened",
"transaction_details_swap_order_fill": "Swap Order Filled",
"transaction_details_claim": "Claim Staked Funds",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/strings/kaa.json
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@
"transaction_details_fee_warning": "High Network Fees",
"transaction_details_swap": "Swap Funds",
"transaction_details_swap_network_fee": "Swap Network Fee",
"transaction_details_swap_order_cancel": "Swap Order Canceled",
"transaction_details_swap_order_cancel": "Swap Order Cancelled",
"transaction_details_swap_order_post": "Swap Order Opened",
"transaction_details_swap_order_fill": "Swap Order Filled",
"transaction_details_claim": "Claim Staked Funds",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/strings/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@
"transaction_details_fee_warning": "High Network Fees",
"transaction_details_swap": "Swap Funds",
"transaction_details_swap_network_fee": "Swap Network Fee",
"transaction_details_swap_order_cancel": "Swap Order Canceled",
"transaction_details_swap_order_cancel": "Swap Order Cancelled",
"transaction_details_swap_order_post": "Swap Order Opened",
"transaction_details_swap_order_fill": "Swap Order Filled",
"transaction_details_claim": "Claim Staked Funds",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/strings/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@
"transaction_details_fee_warning": "Altas taxas de rede",
"transaction_details_swap": "Swap Funds",
"transaction_details_swap_network_fee": "Swap Network Fee",
"transaction_details_swap_order_cancel": "Swap Order Canceled",
"transaction_details_swap_order_cancel": "Swap Order Cancelled",
"transaction_details_swap_order_post": "Swap Order Opened",
"transaction_details_swap_order_fill": "Swap Order Filled",
"transaction_details_claim": "Claim Staked Funds",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/strings/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@
"transaction_details_fee_warning": "High Network Fees",
"transaction_details_swap": "Swap Funds",
"transaction_details_swap_network_fee": "Swap Network Fee",
"transaction_details_swap_order_cancel": "Swap Order Canceled",
"transaction_details_swap_order_cancel": "Swap Order Cancelled",
"transaction_details_swap_order_post": "Swap Order Opened",
"transaction_details_swap_order_fill": "Swap Order Filled",
"transaction_details_claim": "Claim Staked Funds",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/strings/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@
"transaction_details_fee_warning": "High Network Fees",
"transaction_details_swap": "Swap Funds",
"transaction_details_swap_network_fee": "Swap Network Fee",
"transaction_details_swap_order_cancel": "Swap Order Canceled",
"transaction_details_swap_order_cancel": "Swap Order Cancelled",
"transaction_details_swap_order_post": "Swap Order Opened",
"transaction_details_swap_order_fill": "Swap Order Filled",
"transaction_details_claim": "Claim Staked Funds",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/strings/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@
"transaction_details_fee_warning": "High Network Fees",
"transaction_details_swap": "Swap Funds",
"transaction_details_swap_network_fee": "Swap Network Fee",
"transaction_details_swap_order_cancel": "Swap Order Canceled",
"transaction_details_swap_order_cancel": "Swap Order Cancelled",
"transaction_details_swap_order_post": "Swap Order Opened",
"transaction_details_swap_order_fill": "Swap Order Filled",
"transaction_details_claim": "Claim Staked Funds",
Expand Down
54 changes: 50 additions & 4 deletions src/plugins/gui/providers/banxaProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,9 @@ export const banxaProvider: FiatProviderFactory = {
source: queryParams.source,
target: queryParams.target,
blockchain: banxaChain,
return_url_on_success: RETURN_URL_SUCCESS,
return_url_on_cancelled: RETURN_URL_CANCEL,
return_url_on_failure: RETURN_URL_FAIL
return_url_on_success: direction === 'buy' ? `https://deep.edge.app/fiatprovider/buy/banxa?status=success` : RETURN_URL_SUCCESS,
return_url_on_cancelled: direction === 'buy' ? `https://deep.edge.app/fiatprovider/buy/banxa?status=cancelled` : RETURN_URL_CANCEL,
return_url_on_failure: direction === 'buy' ? `https://deep.edge.app/fiatprovider/buy/banxa?status=failure` : RETURN_URL_FAIL
}
if (direction === 'buy') {
if (testnet && banxaChain === 'BTC') {
Expand Down Expand Up @@ -594,7 +594,53 @@ export const banxaProvider: FiatProviderFactory = {
let insideInterval = false

if (direction === 'buy') {
await showUi.openExternalWebView({ url: banxaQuote.data.order.checkout_url })
await showUi.openExternalWebView({
providerId,
url: banxaQuote.data.order.checkout_url,
deeplinkHandler: async link => {
if (link.direction !== 'buy') return

const orderResponse = await banxaFetch({ method: 'GET', url, hmacUser, path: `api/orders/${banxaQuote.data.order.id}`, apiKey })
const order = asBanxaOrderResponse(orderResponse)

switch (link.query.status) {
case 'success': {
await showUi.trackConversion('Buy_Success', {
conversionValues: {
conversionType: 'buy',
sourceFiatCurrencyCode: fiatCurrencyCode,
sourceFiatAmount: priceQuote.fiat_amount,
destAmount: new CryptoAmount({
currencyConfig: coreWallet.currencyConfig,
currencyCode: displayCurrencyCode,
exchangeAmount: order.data.order.coin_amount
}),
fiatProviderId: providerId,
orderId: banxaQuote.data.order.id
}
})
await showUi.exitScene()
break
}
case 'cancelled': {
console.log('Banxa WebView launch buy cancelled: ' + link.uri)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you decided to correct the "canceled" string spelling, change it here too for searchability.

await showUi.showToast(lstrings.fiat_plugin_buy_cancelled, NOT_SUCCESS_TOAST_HIDE_MS)
await showUi.exitScene()
break
}
case 'failure': {
console.log('Banxa WebView launch buy failure: ' + link.uri)
await showUi.showToast(lstrings.fiat_plugin_buy_failed_try_again, NOT_SUCCESS_TOAST_HIDE_MS)
await showUi.exitScene()
break
}
default: {
await showUi.showToast(lstrings.fiat_plugin_buy_unknown_status, NOT_SUCCESS_TOAST_HIDE_MS)
await showUi.exitScene()
}
}
}
})
} else {
const { checkout_url: checkoutUrl, id } = banxaQuote.data.order
const banxaUrl = new URL(checkoutUrl)
Expand Down
51 changes: 47 additions & 4 deletions src/plugins/gui/providers/simplexProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { gt, lt } from 'biggystring'
import { asArray, asEither, asNumber, asObject, asString } from 'cleaners'

import { lstrings } from '../../../locales/strings'
import { CryptoAmount } from '../../../util/CryptoAmount'
import { fetchInfo } from '../../../util/network'
import { asFiatPaymentType, FiatPaymentType } from '../fiatPluginTypes'
import {
Expand All @@ -16,7 +18,7 @@ import {
FiatProviderQuote
} from '../fiatProviderTypes'
import { addTokenToArray } from '../util/providerUtils'
import { addExactRegion, isDailyCheckDue, validateExactRegion } from './common'
import { addExactRegion, isDailyCheckDue, NOT_SUCCESS_TOAST_HIDE_MS, validateExactRegion } from './common'
const providerId = 'simplex'
const storeId = 'co.edgesecure.simplex'
const partnerIcon = 'simplex-logo-sm-square.png'
Expand Down Expand Up @@ -313,6 +315,8 @@ export const simplexProvider: FiatProviderFactory = {
throw new Error('Simplex unknown error')
}
const goodQuote = asSimplexQuoteSuccess(quote)
const quoteFiatAmount = goodQuote.fiat_money.amount.toString()
const quoteCryptAmount = goodQuote.digital_money.amount.toString()

const paymentQuote: FiatProviderQuote = {
providerId,
Expand All @@ -323,8 +327,8 @@ export const simplexProvider: FiatProviderFactory = {
displayCurrencyCode: params.displayCurrencyCode,
isEstimate: false,
fiatCurrencyCode: params.fiatCurrencyCode,
fiatAmount: goodQuote.fiat_money.amount.toString(),
cryptoAmount: goodQuote.digital_money.amount.toString(),
fiatAmount: quoteFiatAmount,
cryptoAmount: quoteCryptAmount,
direction: params.direction,
expirationDate: new Date(Date.now() + 8000),
approveQuote: async (approveParams: FiatProviderApproveQuoteParams): Promise<void> => {
Expand Down Expand Up @@ -355,7 +359,46 @@ export const simplexProvider: FiatProviderFactory = {
const url = `https://partners.simplex.com/?partner=${partner}&t=${token}`

console.log('Approving simplex quote url=' + url)
await showUi.openExternalWebView({ url })
await showUi.openExternalWebView({
url,
providerId,
deeplinkHandler: async link => {
if (link.direction !== 'buy') return

const orderId = link.query.orderId ?? 'unknown'

switch (link.query.status) {
case 'success': {
await showUi.trackConversion('Buy_Success', {
conversionValues: {
conversionType: 'buy',
sourceFiatCurrencyCode: params.fiatCurrencyCode,
sourceFiatAmount: quoteFiatAmount,
destAmount: new CryptoAmount({
currencyConfig: coreWallet.currencyConfig,
currencyCode: displayCurrencyCode,
exchangeAmount: quoteCryptAmount
}),
fiatProviderId: providerId,
orderId
}
})
await showUi.exitScene()
break
}
case 'failure': {
console.log('Simplex WebView launch buy failure: ' + link.uri)
await showUi.showToast(lstrings.fiat_plugin_buy_failed_try_again, NOT_SUCCESS_TOAST_HIDE_MS)
await showUi.exitScene()
break
}
default: {
await showUi.showToast(lstrings.fiat_plugin_buy_unknown_status, NOT_SUCCESS_TOAST_HIDE_MS)
await showUi.exitScene()
}
}
}
})
},
closeQuote: async (): Promise<void> => {}
}
Expand Down
Loading