Skip to content

Commit

Permalink
Merge pull request #5270 from EdgeApp/paul/paybisBuyTracking
Browse files Browse the repository at this point in the history
Paul/paybis buy tracking
  • Loading branch information
paullinator authored Sep 30, 2024
2 parents b60bdc5 + e489742 commit dfc7026
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
- added: Re-enable Piratechain on iOS
- added: Battery Saver warning message for Android
- added: Buy conversion tracking for Moonpay
- added: Buy conversion tracking for Paybis
- added: Support for return.edge.app deeplinks
- added: Error tracking for failure to report conversions to referral server
- changed: Remove whitespaces from custom token contract address input
- changed: Use unique ENV configs for thorchain and thorchainda swap plugins
- fixed: Correctly tag `tokenApproval` `actionType` in `getTxActionDisplayInfo`
- fixed: URI encoding in Paybis return URIs
- fixed: AddressTile2 touchable area states
- fixed: Cases where it was possible to create duplicate custom tokens
- fixed: Clear previous swap errors when new amounts are entered or swap assets are changed in `SwapCreateScene`
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<data android:scheme="https" />
<data android:host="deep.edge.app" />
<data android:host="dl.edge.app" />
<data android:host="return.edge.app" />
</intent-filter>
<intent-filter android:label="Edge Deep Links">
<action android:name="android.intent.action.VIEW" />
Expand Down
1 change: 1 addition & 0 deletions ios/edge/edge.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:dl.edge.app</string>
<string>applinks:return.edge.app</string>
<string>applinks:deep.edge.app</string>
</array>
</dict>
Expand Down
24 changes: 24 additions & 0 deletions src/__tests__/DeepLink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ describe('parseDeepLink', function () {
'https://deep.edge.app/edge/1234567890a': {
type: 'edgeLogin',
lobbyId: '1234567890a'
},
'https://return.edge.app/edge/1234567890a': {
type: 'edgeLogin',
lobbyId: '1234567890a'
}
})

Expand Down Expand Up @@ -226,6 +230,26 @@ describe('parseDeepLink', function () {
}
})
})
describe('fiatProvider', function () {
makeLinkTests({
'https://deep.edge.app/fiatprovider/buy/moonpay?param=alice': {
type: 'fiatProvider',
providerId: 'moonpay',
direction: 'buy',
path: '',
query: { param: 'alice' },
uri: 'edge://fiatprovider/buy/moonpay?param=alice'
},
'https://return.edge.app/fiatprovider/buy/moonpay?param=alice': {
type: 'fiatProvider',
providerId: 'moonpay',
direction: 'buy',
path: '',
query: { param: 'alice' },
uri: 'edge://fiatprovider/buy/moonpay?param=alice'
}
})
})

describe('promotion', function () {
makeLinkTests({
Expand Down
1 change: 1 addition & 0 deletions src/locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,7 @@ const strings = {
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_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
1 change: 1 addition & 0 deletions src/locales/strings/enUS.json
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,7 @@
"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_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
56 changes: 49 additions & 7 deletions src/plugins/gui/providers/paybisProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { eq, lte, mul, round } from 'biggystring'
import { asArray, asBoolean, asDate, asMaybe, asObject, asOptional, asString, asValue } from 'cleaners'
import { EdgeAssetAction, EdgeFetchOptions, EdgeSpendInfo, EdgeTxActionFiat, JsonObject } from 'edge-core-js'
import { sprintf } from 'sprintf-js'
import URL from 'url-parse'

import { SendScene2Params } from '../../../components/scenes/SendScene2'
Expand Down Expand Up @@ -195,7 +196,7 @@ const asQuote = asObject({

const asPaymentDetails = asObject({
assetId: asString,
invoice: asString,
// invoice: asString,
blockchain: asString,
network: asString,
depositAddress: asString,
Expand Down Expand Up @@ -584,14 +585,55 @@ export const paybisProvider: FiatProviderFactory = {
const promoCodeParam = promoCode != null ? `&promoCode=${promoCode}` : ''

if (direction === 'buy') {
const successReturnURL = encodeURIComponent('https://return.edge.app/fiatprovider/buy/paybis?transactionStatus=success')
const failureReturnURL = encodeURIComponent('https://return.edge.app/fiatprovider/buy/paybis?transactionStatus=fail')
await showUi.openExternalWebView({
url: `${widgetUrl}?requestId=${requestId}${ott}${promoCodeParam}`
url: `${widgetUrl}?requestId=${requestId}${ott}${promoCodeParam}&successReturnURL=${successReturnURL}&failureReturnURL=${failureReturnURL}`,
providerId,
deeplinkHandler: async link => {
const { query, uri } = link
console.log('Paybis WebView launch buy success: ' + uri)
const { transactionStatus } = query
if (transactionStatus === 'success') {
await showUi.trackConversion('Buy_Success', {
conversionValues: {
conversionType: 'buy',
sourceFiatCurrencyCode: fiatCurrencyCode,
sourceFiatAmount: fiatAmount,
destAmount: new CryptoAmount({
currencyConfig: coreWallet.currencyConfig,
currencyCode: displayCurrencyCode,
exchangeAmount: cryptoAmount
}),
fiatProviderId: providerId,
orderId: requestId
}
})
const message =
sprintf(lstrings.fiat_plugin_buy_complete_message_s, cryptoAmount, displayCurrencyCode, fiatAmount, fiat, '1') +
'\n\n' +
sprintf(lstrings.fiat_plugin_buy_complete_message_2_hour_s, '1') +
'\n\n' +
lstrings.fiat_plugin_sell_complete_message_3
await showUi.buttonModal({
buttons: {
ok: { label: lstrings.string_ok, type: 'primary' }
},
title: lstrings.fiat_plugin_buy_complete_title,
message
})
} else if (transactionStatus === 'failure') {
await showUi.showToast(lstrings.fiat_plugin_buy_failed_try_again, NOT_SUCCESS_TOAST_HIDE_MS)
} else {
await showUi.showError(new Error(`Paybis: Invalid transactionStatus "${transactionStatus}".`))
}
}
})
return
}

const successReturnURL = encodeURI(RETURN_URL_SUCCESS)
const failureReturnURL = encodeURI(RETURN_URL_FAIL)
const successReturnURL = encodeURIComponent(RETURN_URL_SUCCESS)
const failureReturnURL = encodeURIComponent(RETURN_URL_FAIL)
const webviewUrl = `${widgetUrl}?requestId=${requestId}&successReturnURL=${successReturnURL}&failureReturnURL=${failureReturnURL}${ott}${promoCodeParam}`
console.log(`webviewUrl: ${webviewUrl}`)
let inPayment = false
Expand All @@ -609,7 +651,7 @@ export const paybisProvider: FiatProviderFactory = {
inPayment = true
try {
const payDetails = await paybisFetch({ method: 'GET', url, path: `v2/request/${requestId}/payment-details`, apiKey, promoCode })
const { assetId, amount, currencyCode: pbCurrencyCode, invoice, network, depositAddress, destinationTag } = asPaymentDetails(payDetails)
const { assetId, amount, currencyCode: pbCurrencyCode, network, depositAddress, destinationTag } = asPaymentDetails(payDetails)
const { pluginId, tokenId } = PAYBIS_TO_EDGE_CURRENCY_MAP[assetId]

console.log(`Creating Paybis payment`)
Expand All @@ -626,7 +668,7 @@ export const paybisProvider: FiatProviderFactory = {
}
const savedAction: EdgeTxActionFiat = {
actionType: 'fiat',
orderId: invoice,
orderId: requestId,
orderUri: `${widgetUrl}?requestId=${requestId}`,
isEstimate: true,
fiatPlugin: {
Expand Down Expand Up @@ -694,7 +736,7 @@ export const paybisProvider: FiatProviderFactory = {
exchangeAmount: amount
}),
fiatProviderId: providerId,
orderId: invoice
orderId: requestId
}
})

Expand Down
1 change: 1 addition & 0 deletions src/types/DeepLinkTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* - edge://<type>/...
* - airbitz://<type>/...
* - https://deep.edge.app/<type>/...
* - https://dp.edge.app/<type>/...
*
* The `edge://` protocol supports the following link types:
*
Expand Down
1 change: 1 addition & 0 deletions src/util/DeepLinkParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ const prefixes: Array<[string, string]> = [

// Alternative schemes:
['https://deep.edge.app/', 'edge://'],
['https://return.edge.app/', 'edge://'],
['airbitz://', 'edge://'],
['reqaddr://', 'edge://reqaddr']
]

0 comments on commit dfc7026

Please sign in to comment.