Skip to content

Commit

Permalink
Merge pull request #1623 from AmbireTech/ux/restricted-tm
Browse files Browse the repository at this point in the history
ux disable typed messages
  • Loading branch information
Ivshti authored Jul 1, 2024
2 parents fdc2e66 + 2089dc6 commit d384639
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 60 deletions.
22 changes: 18 additions & 4 deletions src/components/SignMessage/SignMessage.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useState, useEffect, useRef } from 'react'
import { useLocation } from 'react-router-dom'
import * as blockies from 'blockies-ts'
import { toUtf8String, isHexString } from 'ethers/lib/utils'
import supportedDApps from 'ambire-common/src/constants/supportedDApps'
import cn from 'classnames'
import { UNISWAP_UNIVERSAL_ROUTERS, PERMIT_2_ADDRESS } from 'consts/specialAddresses'

import { useSignMessage } from 'hooks'
import {
Expand Down Expand Up @@ -35,6 +36,9 @@ export default function SignMessage({
const [promiseResolve, setPromiseResolve] = useState(null)
const inputSecretRef = useRef(null)
const textAreaRef = useRef(null)
const location = useLocation();
const queryParams = new URLSearchParams(location.search);
const isTomek = queryParams.get('isTomek');

const onConfirmationCodeRequired = async (confCodeRequired, approveQuickAcc) => {
const confCode = await new Promise((resolve) => {
Expand Down Expand Up @@ -68,9 +72,19 @@ export default function SignMessage({
onConfirmationCodeRequired,
useStorage
})

const isSnapshot = (_dappName, _txn) => _dappName && _dappName.startsWith('https://snapshot.org') && _txn.domain && _txn.domain.name === 'snapshot'
const isOkPermit2 = (_txn, _chainId) =>
_txn.primaryType &&
_txn.primaryType.toLowerCase().includes('permit') &&
_txn.message && _txn.message.spender &&
UNISWAP_UNIVERSAL_ROUTERS[_chainId] &&
_txn.message.spender.toLowerCase() === UNISWAP_UNIVERSAL_ROUTERS[_chainId].toLowerCase() &&
_txn.domain && _txn.domain.verifyingContract &&
_txn.domain.verifyingContract.toLowerCase() === PERMIT_2_ADDRESS.toLowerCase()
const isSigTool = (_dappUrl) => _dappUrl === 'https://sigtool.ambire.com/'

const isDAppSupported =
dApp && (supportedDApps.includes(dApp.url) || supportedDApps.includes(`${dApp.url}/`))
const isDAppSupported = !isTypedData || isTomek==='true' || (dApp && dataV4 && isSnapshot(dApp.url, dataV4)) || isOkPermit2(dataV4, requestedChainId) || (dApp && isSigTool(dApp.url))

const onScroll = (textArea) => {
if (textArea.scrollHeight - textArea.scrollTop - textArea.clientHeight < 1) {
Expand Down Expand Up @@ -262,7 +276,7 @@ export default function SignMessage({
variant="primaryGradient"
className={styles.button}
loading={isLoading}
disabled={!hasScrolledToBottom || typeDataErr}
disabled={ !isDAppSupported || !hasScrolledToBottom || typeDataErr}
loadingText="Signing..."
>
Sign
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styles from './DAppIncompatibilityWarningMsg.module.scss'

export default function DAppIncompatibilityWarningMsg({
title = 'Warning',
msg = 'If you have trouble validating this message with the dApp, most likely it does not support smart wallet signatures. Ambire Wallet has no control over those dApps and can not reach out to all of them, and we recommend you report this to the dApp in order to add such support and allow you to use it flawlessly.'
msg = 'If you have trouble validating this message with the dApp, most likely it does not support smart wallet signatures. Ambire Wallet has no control over those dApps and can not reach out to all of them. We recommend you to migrate to the Ambire Extension, which supports signing all types of messages: https://www.ambire.com.'
}) {
return (
<div className={styles.wrapper}>
Expand Down
18 changes: 18 additions & 0 deletions src/consts/specialAddresses.js
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
export const UNISWAP_UNIVERSAL_ROUTERS = {
1: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
11155111: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
8453: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
42161: '0x5E325eDA8064b456f4781070C0738d849c824258',
421614: '0x4A7b5Da61326A6379179b40d00F57E5bbDC962c2',
10: '0xCb1355ff08Ab38bBCE60111F1bb2B7845384bE25D7e8',
11155420: '0xD5bBa708b39537d33F2812E5Ea032622456F1A95',
137: '0xec7BE89e9d109e7e3Fec59c222CF297125FEFda2',
84532: '0x050E797f3625EC8785265e1d9BDd4799b97528A1',
56: '0x4Dae2f939ACf50408e13d58534Ff8c2776d45265',
43114: '0x4Dae2f939ACf50408e13d58534Ff8c2776d45265',
42220: '0x643770E279d5D0733F21d6DC03A8efbABf3255B4',
81457: '0x643770E279d5D0733F21d6DC03A8efbABf3255B4'
}

export const PERMIT_2_ADDRESS = '0x000000000022D473030F116dDEE9F6B43aC78BA3'

43 changes: 6 additions & 37 deletions src/hooks/walletConnect/walletConnectV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import { formatJsonRpcError, formatJsonRpcResult } from '@json-rpc-tools/utils'

import {
DEFAULT_EIP155_EVENTS,
WC2_SUPPORTED_METHODS,
PERMIT_2_ADDRESS,
UNISWAP_UNIVERSAL_ROUTERS
WC2_SUPPORTED_METHODS
} from 'hooks/walletConnect/wcConsts'
import networks from 'consts/networks'
import { ethers } from 'ethers'
Expand Down Expand Up @@ -341,8 +339,6 @@ export default function useWalletConnectV2({
const connection = getConnectionFromSessionTopic(topic)

if (connection) {
const dappName = connection.peer?.metadata.name || ''

if (method === 'personal_sign' || wcRequest.method === 'eth_sign') {
txn = wcRequest.params[wcRequest.method === 'personal_sign' ? 0 : 1]
requestAccount = wcRequest.params[wcRequest.method === 'personal_sign' ? 1 : 0]
Expand All @@ -368,33 +364,6 @@ export default function useWalletConnectV2({
} else if (method === 'eth_signTypedData_v4') {
requestAccount = wcRequest.params[0]
txn = JSON.parse(wcRequest.params[1])
const isSnapshot = (_dappName, _txn) => _dappName && _dappName.toLowerCase().includes('snapshot') && _txn.domain && _txn.domain.name === 'snapshot'
const isOkPermit2 = (_txn) =>
_txn.primaryType &&
_txn.primaryType.toLowerCase().includes('permit') &&
_txn.message && _txn.message.spender &&
_txn.message.spender.toLowerCase() === UNISWAP_UNIVERSAL_ROUTERS[requestChainId].toLowerCase() &&
_txn.domain && _txn.domain.verifyingContract &&
_txn.domain.verifyingContract.toLowerCase() === PERMIT_2_ADDRESS.toLowerCase()
const isSigTool = (_connection) => _connection && _connection.peer && _connection.peer.metadata && _connection.peer.metadata.url === 'https://sigtool.ambire.com/'

if (!isSigTool(connection) && !isSnapshot(dappName, txn) && !isOkPermit2(txn)) {
const response = formatJsonRpcError(id, {
message: `Signing this eip-712 message is disallowed as it does not contain the smart account address and therefore deemed unsafe: ${method}`,
code: -32003
})
web3wallet
.respondSessionRequest({ topic, response })
.catch((err) => {
addToast(err.message, { error: true })
})
addToast(
'We\'re not yet able to sign this message. Please use the Ambire Extension.',
{ warning: true }
)
return
}

} else if (
method === 'wallet_switchEthereumChain' ||
method === 'wallet_addEthereumChain'
Expand Down Expand Up @@ -445,11 +414,11 @@ export default function useWalletConnectV2({
notification: true,
dapp: connection.peer.metadata
? {
name: connection.peer.metadata.name,
description: connection.peer.metadata.description,
icons: connection.peer.metadata.icons,
url: connection.peer.metadata.url
}
name: connection.peer.metadata.name,
description: connection.peer.metadata.description,
icons: connection.peer.metadata.icons,
url: connection.peer.metadata.url
}
: null
}
setWalletRequests((prev) => [...prev, request])
Expand Down
18 changes: 0 additions & 18 deletions src/hooks/walletConnect/wcConsts.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
export const PERMIT_2_ADDRESS = '0x000000000022D473030F116dDEE9F6B43aC78BA3'

export const UNISWAP_UNIVERSAL_ROUTERS = {
1: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
11155111: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
8453: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
42161: '0x5E325eDA8064b456f4781070C0738d849c824258',
421614: '0x4A7b5Da61326A6379179b40d00F57E5bbDC962c2',
10: '0xCb1355ff08Ab38bBCE60111F1bb2B7845384bE25D7e8',
11155420: '0xD5bBa708b39537d33F2812E5Ea032622456F1A95',
137: '0xec7BE89e9d109e7e3Fec59c222CF297125FEFda2',
84532: '0x050E797f3625EC8785265e1d9BDd4799b97528A1',
56: '0x4Dae2f939ACf50408e13d58534Ff8c2776d45265',
43114: '0x4Dae2f939ACf50408e13d58534Ff8c2776d45265',
42220: '0x643770E279d5D0733F21d6DC03A8efbABf3255B4',
81457: '0x643770E279d5D0733F21d6DC03A8efbABf3255B4'
}

export const DEFAULT_EIP155_EVENTS = ['chainChanged', 'accountsChanged']

export const WC2_SUPPORTED_METHODS = [
Expand Down

0 comments on commit d384639

Please sign in to comment.