From 6ae8babc1d7ff49fc40592d0ed393ff70d3175ea Mon Sep 17 00:00:00 2001 From: Yosif Hamed Date: Mon, 24 Jun 2024 19:02:11 +0300 Subject: [PATCH] add tm restrictions to signMessage screen --- src/components/SignMessage/SignMessage.js | 15 ++++++++++++--- src/consts/specialAddresses.js | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/components/SignMessage/SignMessage.js b/src/components/SignMessage/SignMessage.js index 76dd15e010..1c50eac8b0 100644 --- a/src/components/SignMessage/SignMessage.js +++ b/src/components/SignMessage/SignMessage.js @@ -1,8 +1,8 @@ import { useState, useEffect, useRef } from 'react' 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 { @@ -68,9 +68,18 @@ export default function SignMessage({ onConfirmationCodeRequired, useStorage }) + + const isSnapshot = (_dappName, _txn) => _dappName && _dappName.toLowerCase().includes('snapshot') && _txn.domain && _txn.domain.name === 'snapshot' + const isOkPermit2 = (_txn, _chainId) => + _txn.primaryType && + _txn.primaryType.toLowerCase().includes('permit') && + _txn.message && _txn.message.spender && + _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 || (dApp && dataV4 && isSnapshot(dApp.url, dataV4)) || isOkPermit2(dataV4, requestedChainId) || (dApp && isSigTool(dApp.url)) const onScroll = (textArea) => { if (textArea.scrollHeight - textArea.scrollTop - textArea.clientHeight < 1) { diff --git a/src/consts/specialAddresses.js b/src/consts/specialAddresses.js index e1118cef0e..94267b5189 100644 --- a/src/consts/specialAddresses.js +++ b/src/consts/specialAddresses.js @@ -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' + \ No newline at end of file