Skip to content

Commit

Permalink
[frontend] put the whitelist back (#210)
Browse files Browse the repository at this point in the history
This reverts commit 2f20a50.
  • Loading branch information
0xChqrles authored Mar 13, 2024
1 parent 2f20a50 commit 53a3873
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
31 changes: 26 additions & 5 deletions frontend/src/components/TransactionModal/index.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -32,6 +32,7 @@ export function TransactionModal() {

// starknet
const { writeAsync } = useContractWrite({})
const { address } = useAccount()

// calls
const [invokeTransactionDetails, resetTransaction] = useTransaction()
Expand Down Expand Up @@ -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) {
Expand All @@ -121,7 +142,7 @@ export function TransactionModal() {

// execute transaction
useEffect(() => {
if (!currentInvokeTransactionDetails) return
if (!currentInvokeTransactionDetails || !isWhiteListed) return

writeAsync({ calls: currentInvokeTransactionDetails.calls })
.then((res) => {
Expand All @@ -134,7 +155,7 @@ export function TransactionModal() {
})

resetTransaction()
}, [resetTransaction, currentInvokeTransactionDetails, writeAsync])
}, [resetTransaction, currentInvokeTransactionDetails, writeAsync, isWhiteListed])

// updating current invoke transaction details
useEffect(() => {
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/constants/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]

0 comments on commit 53a3873

Please sign in to comment.