From 962677e86aa1e689ba85310f9ba078983996449e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren?= Date: Mon, 7 Aug 2023 14:40:56 +0200 Subject: [PATCH] Handle USDC request links with query params (such as amount) --- src/components/modals/UsdcSendModal.vue | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/modals/UsdcSendModal.vue b/src/components/modals/UsdcSendModal.vue index 3086c4b83..f3606d1fd 100644 --- a/src/components/modals/UsdcSendModal.vue +++ b/src/components/modals/UsdcSendModal.vue @@ -495,16 +495,19 @@ export default defineComponent({ // For now only plain USDC/Polygon/ETH addresses are supported. // TODO support Polygon-USDC request links and even consider removing scanning of plain addresses // due to the risk of USDC being sent on the wrong chain. - uri = uri.replace(`${window.location.origin}/`, '') - .replace('polygon:', ''); + const url = new URL(uri); const { ethers } = await getPolygonClient(); - if (ethers.utils.isAddress(uri)) { + if (ethers.utils.isAddress(url.pathname)) { if (event) { // Prevent paste event being applied to the recipient label field, that now became focussed. event.preventDefault(); } - onAddressEntered(uri); + await onAddressEntered(url.pathname); + + if (url.searchParams.has('amount')) { + amount.value = parseFloat(url.searchParams.get('amount')!) * 1e6; + } } }