Skip to content

Commit

Permalink
admin panel - allow configure confirms count
Browse files Browse the repository at this point in the history
  • Loading branch information
shendel committed Sep 18, 2023
1 parent ec731fe commit 6bbac8a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
20 changes: 17 additions & 3 deletions src/pages/Settings/Contracts.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import React, { useState, useEffect, useCallback, useRef } from 'react'
import { useTranslation } from 'react-i18next'
import styled from 'styled-components'
Expand Down Expand Up @@ -316,11 +317,15 @@ export default function Contracts() {

const [routerChainId, setRouterChainId] = useState('')
const [routerAddress, setRouterAddress] = useState('')
const [routerConfirmCount, setRouterConfirmCount] = useState(3)

useEffect(() => {
if (chainId !== undefined && stateRouterAddress[chainId]) {
setRouterChainId(String(chainId))
setRouterAddress(stateRouterAddress[chainId])
if (stateAppSettings?.routerConfigs[`${chainId}:${stateRouterAddress[chainId]}`]) {
setRouterConfirmCount(stateAppSettings.routerConfigs[`${chainId}:${stateRouterAddress[chainId]}`].confirmations)
}
} else {
setRouterChainId('')
setRouterAddress('')
Expand Down Expand Up @@ -354,14 +359,14 @@ export default function Contracts() {
const tx = await routerConfigSigner.setChainConfig(routerChainId, {
BlockChain: name,
RouterContract: routerAddress,
Confirmations: 3,
Confirmations: routerConfirmCount,
InitialHeight: 0
})

const receipt = await tx.wait()

if (receipt.status) {
dispatch(updateRouterData({ chainId: Number(routerChainId), routerAddress: routerAddress }))
dispatch(updateRouterData({ chainId: Number(routerChainId), routerAddress: routerAddress, routerConfirmCount: routerConfirmCount }))
addTransaction(
{ hash: receipt.transactionHash },
{
Expand Down Expand Up @@ -476,13 +481,16 @@ export default function Contracts() {
if (selectedContract !== `-`) {
const {
chainId,
address
address,
confirmations
} = appSettings.routerConfigs[selectedContract]
setRouterChainId(`${chainId}`)
setRouterAddress(address)
setRouterConfirmCount(confirmations)
} else {
setRouterChainId(``)
setRouterAddress(``)
setRouterConfirmCount(3)
}
}

Expand Down Expand Up @@ -771,6 +779,12 @@ export default function Contracts() {
value={routerAddress}
onChange={event => setRouterAddress(event.target.value)}
/>
{t('routerConfirmCount')}
<Input
type="text"
value={routerConfirmCount}
onChange={event => setRouterConfirmCount(event.target.value)}
/>
</OptionLabel>
{onConfigNetwork ? (
<ButtonPrimary onClick={setChainConfig} disabled={!canSaveChainConfig}>
Expand Down
6 changes: 5 additions & 1 deletion src/pages/Settings/FetchMainConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import React, { useState, useEffect, useRef } from 'react'
import { useTranslation } from 'react-i18next'
import { ERC20_ABI } from '../../constants/abis/erc20'
Expand Down Expand Up @@ -105,6 +106,7 @@ export default function FetchMainConfig({
// @ts-ignore
const crosschainTokens: any = {}
const chainRouters: any = {}
const chainRoutersConfirmsCount: any = {}

useMulticall(mainConfigChainId, multicallDataTokenConfigs)
.then((contractTokenConfigs) => {
Expand All @@ -117,6 +119,7 @@ export default function FetchMainConfig({
switch (method) {
case `getChainConfig`:
chainRouters[callData.tokenChainId] = aData.RouterContract
chainRoutersConfirmsCount[callData.tokenChainId] = aData.Confirmations.toNumber()
break;
case `getTokenConfig`:
const {
Expand Down Expand Up @@ -262,7 +265,8 @@ export default function FetchMainConfig({
const chainRouterAddress = chainRouters[chainId]
updatedRouterConfigs[`${chainId}:${chainRouterAddress}`] = {
address: chainRouterAddress,
chainId
chainId,
confirmations: chainRoutersConfirmsCount[chainId]
}
})

Expand Down
2 changes: 1 addition & 1 deletion src/state/application/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export type AppData = {

export type AppDataKeys = keyof AppData

export const updateRouterData = createAction<{ chainId: number; routerAddress: string }>('application/updateRouterData')
export const updateRouterData = createAction<{ chainId: number; routerAddress: string, routerConfirmCount: number }>('application/updateRouterData')
export const setAppManagement = createAction<{ status: boolean }>('application/setAppManagement')
export const retrieveAppData = createAction<null | AppData>('application/retrieveAppData')
export const updateAppOptions = createAction<{ key: AppDataKeys; value: AppData[AppDataKeys] }[]>(
Expand Down
7 changes: 4 additions & 3 deletions src/state/application/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@ export default function Updater(): null {
const fetch = async () => {
if (!routerConfig || !chainId) return

const { RouterContract } = await routerConfig.methods.getChainConfig(chainId).call()
const routerData = await routerConfig.methods.getChainConfig(chainId).call()
const { RouterContract } = routerData

dispatch(updateRouterData({ chainId, routerAddress: RouterContract === ZERO_ADDRESS ? '' : RouterContract }))
dispatch(updateRouterData({ chainId, routerAddress: RouterContract === ZERO_ADDRESS ? '' : RouterContract, routerConfirmCount: 3 }))
}

if (routerConfig && chainId) {
fetch()
} else {
dispatch(updateRouterData({ chainId: chainId || 0, routerAddress: '' }))
dispatch(updateRouterData({ chainId: chainId || 0, routerAddress: '', routerConfirmCount: 3 }))
}
}, [chainId, mainConfigAddress, mainConfigChainId, routerConfig])

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"strict": false,
"alwaysStrict": false,
"strictNullChecks": true,
"noUnusedLocals": true,
"noUnusedLocals": false,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitThis": true,
Expand Down

0 comments on commit 6bbac8a

Please sign in to comment.