From 7aca5df1db1279ac924802b0fee8bd534832824f Mon Sep 17 00:00:00 2001 From: Walodja1987 Date: Thu, 27 Jul 2023 21:05:49 +0200 Subject: [PATCH] Enable multiple admin accounts + minor code refactoring of isAdmin function --- packages/diva-app/src/Util/utils.ts | 11 +++++++++++ .../src/component/CreatePool/DefineOfferAtributes.tsx | 7 +++---- .../src/component/CreatePool/DefinePoolAttributes.tsx | 8 ++++---- .../component/CreatePool/SelectDataFeedProvider.tsx | 7 +++---- packages/diva-app/src/constants.ts | 7 +++++-- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/packages/diva-app/src/Util/utils.ts b/packages/diva-app/src/Util/utils.ts index c2754270a..ec71a4f5b 100644 --- a/packages/diva-app/src/Util/utils.ts +++ b/packages/diva-app/src/Util/utils.ts @@ -12,3 +12,14 @@ export function toExponentialOrNumber( export function getFutureExpiryInSeconds(minutesFromNow: number): string { return Math.floor(Date.now() / 1000 + minutesFromNow * 60).toString() } + +export function isAdminUser(userAddress, chainId, config) { + if (!userAddress) { + return false + } + + const adminAddresses = config[chainId]?.adminAddresses || [] + return adminAddresses.some( + (adminAddress) => adminAddress.toLowerCase() === userAddress.toLowerCase() + ) +} diff --git a/packages/diva-app/src/component/CreatePool/DefineOfferAtributes.tsx b/packages/diva-app/src/component/CreatePool/DefineOfferAtributes.tsx index 4602c5736..dbe40e7cb 100644 --- a/packages/diva-app/src/component/CreatePool/DefineOfferAtributes.tsx +++ b/packages/diva-app/src/component/CreatePool/DefineOfferAtributes.tsx @@ -41,6 +41,7 @@ import KeyboardDoubleArrowUpOutlinedIcon from '@mui/icons-material/KeyboardDoubl import KeyboardDoubleArrowDownOutlinedIcon from '@mui/icons-material/KeyboardDoubleArrowDownOutlined' import KeyboardDoubleArrowRightOutlinedIcon from '@mui/icons-material/KeyboardDoubleArrowRightOutlined' import { config } from '../../constants' +import { isAdminUser } from '../../Util/utils' const MaxCollateral = styled.u` cursor: pointer; @@ -260,10 +261,8 @@ export function DefineOfferAttributes({ ) const isAdmin = useMemo( - () => - config[chainId]?.adminAddress?.toLowerCase() === - userAddress?.toLowerCase(), - [chainId, userAddress] + () => isAdminUser(userAddress, chainId, config), + [userAddress, chainId] ) useEffect(() => { diff --git a/packages/diva-app/src/component/CreatePool/DefinePoolAttributes.tsx b/packages/diva-app/src/component/CreatePool/DefinePoolAttributes.tsx index f2d834cb9..c2751dfeb 100644 --- a/packages/diva-app/src/component/CreatePool/DefinePoolAttributes.tsx +++ b/packages/diva-app/src/component/CreatePool/DefinePoolAttributes.tsx @@ -35,6 +35,7 @@ import { toExponentialOrNumber } from '../../Util/utils' import { config } from '../../constants' import { useAppSelector } from '../../Redux/hooks' import { selectChainId, selectUserAddress } from '../../Redux/appSlice' +import { isAdminUser } from '../../Util/utils' const MaxCollateral = styled.u` cursor: pointer; @@ -167,11 +168,10 @@ export function DefinePoolAttributes({ () => config[chainId].isCustomCollateralAssetAllowed, [chainId] ) + const isAdmin = useMemo( - () => - config[chainId]?.adminAddress?.toLowerCase() === - userAddress?.toLowerCase(), - [chainId, userAddress] + () => isAdminUser(userAddress, chainId, config), + [userAddress, chainId] ) return ( diff --git a/packages/diva-app/src/component/CreatePool/SelectDataFeedProvider.tsx b/packages/diva-app/src/component/CreatePool/SelectDataFeedProvider.tsx index 805050ba6..d36812ce4 100644 --- a/packages/diva-app/src/component/CreatePool/SelectDataFeedProvider.tsx +++ b/packages/diva-app/src/component/CreatePool/SelectDataFeedProvider.tsx @@ -20,6 +20,7 @@ import { getShortenedAddress } from '../../Util/getShortenedAddress' import React, { useEffect, useMemo, useState } from 'react' import { useAppSelector } from '../../Redux/hooks' import { selectChainId, selectUserAddress } from '../../Redux/appSlice' +import { isAdminUser } from '../../Util/utils' const linkSVG = ( - config[chainId]?.adminAddress?.toLowerCase() === - userAddress?.toLowerCase(), - [chainId, userAddress] + () => isAdminUser(userAddress, chainId, config), + [userAddress, chainId] ) return ( diff --git a/packages/diva-app/src/constants.ts b/packages/diva-app/src/constants.ts index ca0483557..ffa8478ee 100644 --- a/packages/diva-app/src/constants.ts +++ b/packages/diva-app/src/constants.ts @@ -77,7 +77,7 @@ type SingleConfig = { readonly isCustomCollateralAssetAllowed: boolean readonly isCustomDataProviderAllowed: boolean readonly referenceAssets: string[] - readonly adminAddress?: string + readonly adminAddresses?: string[] readonly collateralTokens?: WhitelistCollateralToken[] readonly dataProviders?: DataProviders[] } @@ -210,7 +210,10 @@ export const config: { [key: number]: SingleConfig } = { decimals: 18, }, ], - adminAddress: '0x3E50a9F4DC9CCF7aFaBb7337cf57D63dFa12acc0', + adminAddresses: [ + '0x3E50a9F4DC9CCF7aFaBb7337cf57D63dFa12acc0', + '0x1062CCC9F9a4bBcf565799683b6c00eA525ECb9F', + ], dataProviders: [ { id: '0x7950db13cc37774614b0aa406e42a4c4f0bf26a6',