Skip to content

Commit

Permalink
Merge pull request #1644 from AmbireTech/add/snapshot-box-supported-e…
Browse files Browse the repository at this point in the history
…ip712

Snapshot voting: add snapshot.box as allowed dapp
  • Loading branch information
Ivshti authored Nov 3, 2024
2 parents 33f58b4 + 01705eb commit 8a52716
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/components/SignMessage/SignMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +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 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 @@ -72,19 +72,30 @@ export default function SignMessage({
onConfirmationCodeRequired,
useStorage
})

const isSnapshot = (_dappName, _txn) => _dappName && _dappName.startsWith('https://snapshot.org') && _txn.domain && _txn.domain.name === 'snapshot'

const isSnapshot = (_dappName, _txn) =>
_dappName &&
['https://snapshot.org', 'https://snapshot.box'].includes(_dappName) &&
_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 &&
_txn.message.spender &&
UNISWAP_UNIVERSAL_ROUTERS[_chainId] &&
_txn.message.spender.toLowerCase() === UNISWAP_UNIVERSAL_ROUTERS[_chainId].toLowerCase() &&
_txn.domain && _txn.domain.verifyingContract &&
_txn.domain &&
_txn.domain.verifyingContract &&
_txn.domain.verifyingContract.toLowerCase() === PERMIT_2_ADDRESS.toLowerCase()
const isSigTool = (_dappUrl) => _dappUrl === 'https://sigtool.ambire.com/'

const isDAppSupported = !isTypedData || isTomek==='true' || (dApp && dataV4 && isSnapshot(dApp.url, dataV4)) || isOkPermit2(dataV4, requestedChainId) || (dApp && isSigTool(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 @@ -276,7 +287,7 @@ export default function SignMessage({
variant="primaryGradient"
className={styles.button}
loading={isLoading}
disabled={ !isDAppSupported || !hasScrolledToBottom || typeDataErr}
disabled={!isDAppSupported || !hasScrolledToBottom || typeDataErr}
loadingText="Signing..."
>
Sign
Expand Down

0 comments on commit 8a52716

Please sign in to comment.