Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable multiple admin accounts #817

Merged
merged 1 commit into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/diva-app/src/Util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
<svg
width="16"
Expand Down Expand Up @@ -102,10 +103,8 @@ export function SelectDataFeedProvider({
)

const isAdmin = useMemo(
() =>
config[chainId]?.adminAddress?.toLowerCase() ===
userAddress?.toLowerCase(),
[chainId, userAddress]
() => isAdminUser(userAddress, chainId, config),
[userAddress, chainId]
)

return (
Expand Down
7 changes: 5 additions & 2 deletions packages/diva-app/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
}
Expand Down Expand Up @@ -210,7 +210,10 @@ export const config: { [key: number]: SingleConfig } = {
decimals: 18,
},
],
adminAddress: '0x3E50a9F4DC9CCF7aFaBb7337cf57D63dFa12acc0',
adminAddresses: [
'0x3E50a9F4DC9CCF7aFaBb7337cf57D63dFa12acc0',
'0x1062CCC9F9a4bBcf565799683b6c00eA525ECb9F',
],
dataProviders: [
{
id: '0x7950db13cc37774614b0aa406e42a4c4f0bf26a6',
Expand Down