Skip to content
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
49 changes: 23 additions & 26 deletions assets/web_pages/checkout_status_redirect.html
Original file line number Diff line number Diff line change
@@ -1,48 +1,45 @@
<!DOCTYPE html>
<html>

<head>
<title>Komodo Payment Redirect</title>
</head>

<body>
<script>
// Extract URL parameters and put them into an object
function getParams() {
var params = {};
window.location.search.substring(1).split("&").forEach(function (part) {
var item = part.split("=");
params[item[0]] = decodeURIComponent(item[1]);
});
return params;
var params = {};
window.location.search.substring(1).split("&").forEach(function (part) {
var item = part.split("=");
params[item[0]] = decodeURIComponent(item[1]);
});
return params;
}

// Send the parameters to the opener window
var params = getParams();

var status = params['status'];

console.log('opener: ' + (window.opener?.location?.href ?? 'null'));

if (window.opener != null && !window.opener.closed) {

// Temporary work-around because of Banxa checkout bug. We are polling the status of the payment
// using the order ID in the main app, but this would be better if we could get the post message
// callback to work.
if (status == null) {
status = 'unknown';
}

// Send the parameters to the opener window
window.opener.postMessage({ type: 'PAYMENT-STATUS', status: status, params: params }, '*');

// Change back to the opener tab
window.opener.focus();
if (window.opener != null && !window.opener.closed) {
// Temporary work-around because of Banxa checkout bug. We are polling the status of the payment
// using the order ID in the main app, but this would be better if we could get the post message
// callback to work.
if (status == null) {
status = 'unknown';
}

// Close this tab
window.close();
} else {
// Navigate to the home page as a fallback
window.location.href = 'https://app.komodoplatform.com/';
// Send the parameters to the opener window
window.opener.postMessage({ type: 'PAYMENT-STATUS', status: status, params: params }, '*');
window.opener.focus();
}

// Both Ramp and Banxa checkout pages are either opened in a new tab or a popup dialog webview,
// so we need to close the current window rather than redirecting back to the website.
window.close();
</script>
</body>

</html>
218 changes: 119 additions & 99 deletions assets/web_pages/fiat_widget.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,109 +2,129 @@
<html style="height: 100%;">

<head>
<title>Fiat OnRamp</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body,
html {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
}

iframe {
position: relative;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: none;
}
</style>
<title>Fiat OnRamp</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body,
html {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
}

iframe {
position: relative;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: none;
}
</style>
</head>

<body>
<iframe id="fiat-onramp-iframe" sandbox="allow-same-origin allow-popups allow-scripts allow-forms" src="">
</iframe>
<script>
// Intercept console.log messages and route them through the onMessageHandler
// console.log = function (...args) {
// onMessageHandler({ data: JSON.stringify(args) });
// };

window.onmessage = onMessageHandler;

function getUrlParameter(name) {
const params = new URLSearchParams(window.location.search);
return params.get(name);
}

// Get the `url` parameter
const urlParam = getUrlParameter('fiatUrl');
let targetUrl = null;

if (urlParam) {
try {
targetUrl = atob(urlParam); // base64 decode the `url` parameter
} catch (error) {
console.error('Error decoding base64 url parameter', error);
}
}

if (targetUrl) {
// Set the iframe's src attribute
document.getElementById('fiat-onramp-iframe').src = targetUrl;
} else {
console.error('No URL parameter provided');
}

function onMessageHandler(messageEvent) {
let messageData;
try {
// Try parsing the data as JSON
messageData = JSON.parse(messageEvent.data);
} catch (parseError) {
// If parsing fails, just use it as a string
messageData = messageEvent.data;
}

try {
postMessageToParent(messageData);
} catch (postError) {
console.error('Error posting message', postError);
}
}

/**
* Post a message to the parent window
*
* @param {string|object} messageData
*/
function postMessageToParent(messageData) {
// Convert messageData to a string if it is an object
const messageString = (typeof messageData === 'object') ? JSON.stringify(messageData) : String(messageData);

// flutter_inappwebview
console.log(messageString);

// universal_url opener
if (window.opener) {
return window.opener.postMessage(messageString, "*");
}

if (window.parent && window.parent !== window) {
return window.parent.postMessage(messageString, "*");
}

// Windows WebView2 (desktop_webview_window) - https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/communicate-btwn-web-native
if (window.chrome && window.chrome.webview) {
return window.chrome.webview.postMessage(messageString);
}

console.error('No valid postMessage target found');
<iframe id="fiat-onramp-iframe" title="Fiat On-Ramp Widget"
sandbox="allow-forms allow-scripts allow-same-origin allow-popups allow-top-navigation allow-top-navigation-by-user-action"
src="">
<!-- Placeholder fallback message -->
<p>Your browser does not support iframes.</p>
<p>Please use a modern browser to view this content.</p>
<p>If you are using a mobile device, please try opening this page in a different app or browser.</p>
<p>If you are using a desktop, please try opening this page in a different browser.</p>
</iframe>
<script>
window.addEventListener('message', _komodoOnMessageHandler, false);
window.addEventListener('load', function () {
_komodoSetIframeUrlFromParams();
});

/**
* Initialize the iframe URL based on URL parameters
*
* @param {object} params - The URL parameters to use for initialization
*/
function _komodoSetIframeUrlFromParams() {
const urlParam = _komodoGetUrlParameter('fiatUrl');

let targetUrl = null;
if (urlParam) {
try {
targetUrl = atob(urlParam); // base64 decode the `url` parameter
Comment thread
takenagain marked this conversation as resolved.
} catch (error) {
console.error('Error decoding base64 url parameter', error);
}
</script>
}

if (targetUrl) {
document.getElementById('fiat-onramp-iframe').src = targetUrl;
} else {
console.error('No URL parameter provided');
}
}

/**
* Get URL parameter by name
*
* @param {string} name - The name of the URL parameter to retrieve
* @returns {string|null} - The value of the URL parameter or null if not found
*/
function _komodoGetUrlParameter(name) {
const params = new URLSearchParams(window.location.search);
return params.get(name);
}

/**
* Handle messages from the iframe
*
* @param {MessageEvent} messageEvent
*/
function _komodoOnMessageHandler(messageEvent) {
let messageData;
try {
messageData = typeof messageEvent.data === 'string' ? JSON.parse(messageEvent.data) : messageEvent.data;
} catch (parseError) {
messageData = messageEvent.data;
}

try {
_komodoPostMessageToParent(messageData);
} catch (postError) {
console.error('Error posting message', postError);
}
}

/**
* Post a message to the parent window
*
* @param {string|object} messageData
*/
function _komodoPostMessageToParent(messageData) {
const messageString = (typeof messageData === 'object') ? JSON.stringify(messageData) : String(messageData);

// flutter_inappwebview
console.log(messageString);

// universal_url opener
if (window.opener) {
return window.opener.postMessage(messageString, "*");
}

if (window.parent && window.parent !== window) {
return window.parent.postMessage(messageString, "*");
}

// Windows WebView2 (desktop_webview_window)
// https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/communicate-btwn-web-native
if (window.chrome && window.chrome.webview) {
return window.chrome.webview.postMessage(messageString);
}

console.error('No valid postMessage target found');
}
</script>
</body>

</html>
18 changes: 18 additions & 0 deletions lib/app_config/app_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ const List<String> excludedAssetListTrezor = [
'VAL',
];

/// Some coins returned by the Banxa API are returning errors when attempting
/// to create an order. This is a temporary workaround to filter out those coins
/// until the issue is resolved.
const banxaUnsupportedCoinsList = [
'APE', // chain not configured for APE
'AVAX', // avax & bep20 - invalid wallet address error
'DOT', // bep20 - invalid wallet address error
'FIL', // bep20 - invalid wallet address error
'ONE', // invalid wallet address error (one**** (native) format expected)
'TON', // erc20 - invalid wallet address error
'TRX', // bep20 - invalid wallet address error
'XML', // invalid wallet address error
];

const rampUnsupportedCoinsList = [
'ONE', // invalid wallet address error (one**** format expected)
];

// Assets in wallet-only mode on app level,
// global wallet-only assets are defined in coins config files.
const List<String> appWalletOnlyAssetList = [
Expand Down
Loading
Loading