From 4f5dbcb1b3ac16c896e1076dcda0bf4c4ecd753a Mon Sep 17 00:00:00 2001 From: Angelo CG Date: Tue, 26 Sep 2023 12:10:17 -0600 Subject: [PATCH] feat(webapp): test mm mobile --- webapp/src/components/Vmpxswap/index.js | 61 +++++++++++++++++-------- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/webapp/src/components/Vmpxswap/index.js b/webapp/src/components/Vmpxswap/index.js index 74b03b0..0a3644c 100644 --- a/webapp/src/components/Vmpxswap/index.js +++ b/webapp/src/components/Vmpxswap/index.js @@ -47,20 +47,31 @@ const Vmpxswap = () => { try { const ethereum = window.ethereum || window.web3.currentProvider - if (!ethereum) { + // Verificar si es un dispositivo móvil y MetaMask no está detectado + const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) + if (isMobile && !ethereum) { showMessage({ type: 'warning', content: 'Make sure you have MetaMask installed!' }) - return } - // Detecta si el usuario está en un dispositivo móvil - const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) - - if (isMobile) window.location.href = 'metamask:' + if (!ethereum) { + // Intentar usar MetaMask URI en dispositivos móviles + if (isMobile) { + window.location.href = 'metamask:' + return + } else { + showMessage({ + type: 'warning', + content: 'Make sure you have MetaMask installed!' + }) + return + } + } + // Continuar con la conexión si ethereum está disponible await setSpecificChainMetaMask(ethereum) const accounts = await ethereum.request({ @@ -87,24 +98,36 @@ const Vmpxswap = () => { try { const ethereum = window.ethereum || window.web3.currentProvider - if (ethereum) { - // Detecta si el usuario está en un dispositivo móvil - const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) - - if (isMobile) window.location.href = 'metamask:' - - await setSpecificChainMetaMask(ethereum) - - const accounts = await ethereum.enable() - const account = accounts[0] - - setState({ param: 'ethAccountAddress', ethAccountAddress: account }) - } else { + // Verificar si es un dispositivo móvil y MetaMask no está detectado + const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) + if (isMobile && !ethereum) { showMessage({ type: 'warning', content: 'Make sure you have MetaMask installed!' }) + return + } + + if (!ethereum) { + // Intentar usar MetaMask URI en dispositivos móviles + if (isMobile) { + window.location.href = 'metamask:' + return + } else { + showMessage({ + type: 'warning', + content: 'Make sure you have MetaMask installed!' + }) + return + } } + + await setSpecificChainMetaMask(ethereum) + + const accounts = await ethereum.enable() + const account = accounts[0] + + setState({ param: 'ethAccountAddress', ethAccountAddress: account }) } catch (error) { if (error.message.includes('User rejected the request')) { console.log(