Skip to content

Commit

Permalink
Merge pull request #2 from edenia/feat/mm-mobile
Browse files Browse the repository at this point in the history
feat(webapp): test mm mobile
  • Loading branch information
AngeloCG97 committed Sep 26, 2023
2 parents 11ce2e6 + 9110f21 commit 05d3b85
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions webapp/src/components/Vmpxswap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const Vmpxswap = () => {

const connectMetaMask = async () => {
try {
const { ethereum } = window
const ethereum = window.ethereum || window.web3.currentProvider

if (!ethereum) {
showMessage({
Expand All @@ -59,23 +59,19 @@ const Vmpxswap = () => {
// Detecta si el usuario está en un dispositivo móvil
const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent)

if (isMobile) {
// Si el usuario está en un dispositivo móvil, abre la aplicación Metamask
window.location.href = 'metamask:'
} else {
// Si el usuario no está en un dispositivo móvil, procede como antes
await setSpecificChainMetaMask(ethereum)
if (isMobile) window.location.href = 'metamask:'

const accounts = await ethereum.request({
method: 'eth_requestAccounts'
})
await setSpecificChainMetaMask(ethereum)

showMessage({
type: 'success',
content: `Connected to address: ${accounts[0]}`
})
setState({ param: 'ethAccountAddress', ethAccountAddress: accounts[0] })
}
const accounts = await ethereum.request({
method: 'eth_requestAccounts'
})

showMessage({
type: 'success',
content: `Connected to address: ${accounts[0]}`
})
setState({ param: 'ethAccountAddress', ethAccountAddress: accounts[0] })
} catch (error) {
if (error.message.includes('User rejected the request')) {
console.log(
Expand All @@ -89,24 +85,20 @@ const Vmpxswap = () => {

const checkIfMetaMaskIsConnected = async () => {
try {
const ethereum = window.ethereum
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) {
// Si el usuario está en un dispositivo móvil, abre la aplicación Metamask
window.location.href = 'metamask:'
} else {
// Si el usuario no está en un dispositivo móvil, procede como antes
await setSpecificChainMetaMask(ethereum)
if (isMobile) window.location.href = 'metamask:'

const accounts = await ethereum.enable()
const account = accounts[0]
await setSpecificChainMetaMask(ethereum)

setState({ param: 'ethAccountAddress', ethAccountAddress: account })
}
const accounts = await ethereum.enable()
const account = accounts[0]

setState({ param: 'ethAccountAddress', ethAccountAddress: account })
} else {
showMessage({
type: 'warning',
Expand Down

0 comments on commit 05d3b85

Please sign in to comment.