diff --git a/frontend/src/components/TransactionModal/index.tsx b/frontend/src/components/TransactionModal/index.tsx index 10b6f103..d17a66a1 100644 --- a/frontend/src/components/TransactionModal/index.tsx +++ b/frontend/src/components/TransactionModal/index.tsx @@ -1,13 +1,13 @@ -import { useContractWrite, useWaitForTransaction } from '@starknet-react/core' +import { useAccount, useContractWrite, useWaitForTransaction } from '@starknet-react/core' import { useEffect, useMemo, useState } from 'react' -import { STARKNET_POLLING } from 'src/constants/misc' +import { STARKNET_POLLING, WHITELISTED_ADDRESSES } from 'src/constants/misc' import { useCloseModal, useTransactionModal } from 'src/hooks/useModal' import { useTransaction } from 'src/hooks/useTransactions' import { InvokeTransactionDetails } from 'src/state/transaction' import { Column, Row } from 'src/theme/components/Flex' import * as Icons from 'src/theme/components/Icons' import * as Text from 'src/theme/components/Text' -import { encode, TransactionStatus } from 'starknet' +import { encode, getChecksumAddress, TransactionStatus } from 'starknet' import Portal from '../common/Portal' import Content from '../Modal/Content' @@ -32,6 +32,7 @@ export function TransactionModal() { // starknet const { writeAsync } = useContractWrite({}) + const { address } = useAccount() // calls const [invokeTransactionDetails, resetTransaction] = useTransaction() @@ -102,6 +103,26 @@ export function TransactionModal() { // eslint-disable-next-line react-hooks/exhaustive-deps }, [accepted, data?.finality_status, currentInvokeTransactionDetails?.onSuccess]) + // whitelist + const isWhiteListed = useMemo(() => { + if (!address) return false + + for (const whitelistedAddress of WHITELISTED_ADDRESSES) { + if (getChecksumAddress(whitelistedAddress) === getChecksumAddress(address)) { + return true + } + } + + return false + }, [address]) + + // whitelist error + useEffect(() => { + if (!isWhiteListed) { + setError("Sorry, you're not allowed to perform this action yet. Wait for the official unruggable launch") + } + }, [isWhiteListed, isOpen]) + // error component const errorComponent = useMemo(() => { if (error) { @@ -121,7 +142,7 @@ export function TransactionModal() { // execute transaction useEffect(() => { - if (!currentInvokeTransactionDetails) return + if (!currentInvokeTransactionDetails || !isWhiteListed) return writeAsync({ calls: currentInvokeTransactionDetails.calls }) .then((res) => { @@ -134,7 +155,7 @@ export function TransactionModal() { }) resetTransaction() - }, [resetTransaction, currentInvokeTransactionDetails, writeAsync]) + }, [resetTransaction, currentInvokeTransactionDetails, writeAsync, isWhiteListed]) // updating current invoke transaction details useEffect(() => { diff --git a/frontend/src/constants/misc.ts b/frontend/src/constants/misc.ts index 74a8fed1..7327bf3e 100644 --- a/frontend/src/constants/misc.ts +++ b/frontend/src/constants/misc.ts @@ -80,3 +80,10 @@ export const EKUBO_TICK_SPACING = 5982 // log(1 + 0.6%) / log(1.000001) => 0.6% export const EKUBO_TICK_SIZE_LOG = Math.log(EKUBO_TICK_SIZE) export const EKUBO_FEES_MULTIPLICATOR = EKUBO_MAX_PRICE export const EKUBO_BOUND = getStartingTick(+EKUBO_MAX_PRICE) + +// Whitelist + +export const WHITELISTED_ADDRESSES = [ + '0x0171eaf72B36Dd904509297A51c4744Dcaf2E20E327dd1e7b08808DC0283f0A3', + '0x067efd64D87F476EAD4c5F55b68E6E82E33bEceeB4715F1F154c4986E005Ce82', +]