Skip to content

Commit

Permalink
refactor: More types clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
RabeeAbuBaker committed Oct 23, 2023
1 parent a891dc2 commit 59bf267
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import React, { Dispatch, useMemo } from "react"
import { SecurityReducerActions } from "../../utils/stateReducer"
import { BlockchainWhitelist } from "../../utils/utils"
import useModals from "~/hooks/useModals"
import { Blockchain, WhitelistContractsV2, WhitelistMethodsV2 } from "~/models/portal/sdk"
import { Blockchain, WhitelistContracts, WhitelistMethods } from "~/models/portal/sdk"
import AddSettingsButton from "~/routes/account.$accountId.$appId.security/components/AddSettingsButton"
import ChainWhitelistModal from "~/routes/account.$accountId.$appId.security/components/ChainWhitelistModal"
import ChainWhitelistTable from "~/routes/account.$accountId.$appId.security/components/ChainWhitelistTable"

type ChainWhitelistProps = {
dispatch: Dispatch<SecurityReducerActions>
whitelists: WhitelistContractsV2[] | WhitelistMethodsV2[]
whitelists: WhitelistContracts[] | WhitelistMethods[]
blockchains: Blockchain[]
type: "contracts" | "methods"
readOnly: boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Maybe } from "graphql/jsutils/Maybe"
import { BlockchainWhitelist } from "./utils"
import { Whitelists, WhitelistContractsV2, WhitelistMethodsV2 } from "~/models/portal/sdk"
import { Whitelists, WhitelistContracts, WhitelistMethods } from "~/models/portal/sdk"

export type SecurityReducerActions =
| { type: "origins-add"; payload: string[] }
Expand Down Expand Up @@ -59,13 +59,13 @@ export function securityReducer(state: Whitelists, action: SecurityReducerAction
action.payload,
"whitelistValue",
"contracts",
) as WhitelistContractsV2[]
) as WhitelistContracts[]

let combinedContracts = combineToType(
[...state.contracts, ...payloadContracts],
"contracts",
"contracts",
) as WhitelistContractsV2[]
) as WhitelistContracts[]

return {
...state,
Expand All @@ -86,7 +86,7 @@ export function securityReducer(state: Whitelists, action: SecurityReducerAction
if (contract?.blockchainID === changedContract?.blockchainID) {
return changedContract
} else return contract
}) as WhitelistContractsV2[]
}) as WhitelistContracts[]

return {
...state,
Expand All @@ -97,13 +97,13 @@ export function securityReducer(state: Whitelists, action: SecurityReducerAction
action.payload,
"whitelistValue",
"methods",
) as WhitelistMethodsV2[]
) as WhitelistMethods[]

let combinedMethods = combineToType(
[...state.methods, ...payloadMethods],
"methods",
"methods",
) as WhitelistMethodsV2[]
) as WhitelistMethods[]

return {
...state,
Expand All @@ -124,7 +124,7 @@ export function securityReducer(state: Whitelists, action: SecurityReducerAction
if (contract?.blockchainID === changedMethod?.blockchainID) {
return changedMethod
} else return contract
}) as WhitelistMethodsV2[]
}) as WhitelistMethods[]

return {
...state,
Expand All @@ -136,10 +136,7 @@ export function securityReducer(state: Whitelists, action: SecurityReducerAction
}

const combineToType = (
array:
| BlockchainWhitelist[]
| Maybe<WhitelistContractsV2>[]
| Maybe<WhitelistMethodsV2>[],
array: BlockchainWhitelist[] | Maybe<WhitelistContracts>[] | Maybe<WhitelistMethods>[],
fromType: string,
toType: string,
) => {
Expand Down
8 changes: 4 additions & 4 deletions app/routes/account.$accountId.$appId.security/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { type Blockchain, type RoleName } from "~/models/portal/sdk"
import {
BlockchainsQuery,
PortalApp,
WhitelistContractsV2,
WhitelistMethodsV2,
WhitelistContracts,
WhitelistMethods,
} from "~/models/portal/sdk"
import { AnalyticActions, AnalyticCategories, trackEvent } from "~/utils/analytics"

Expand Down Expand Up @@ -87,15 +87,15 @@ export const SecurityView = ({ app, blockchains, userRole }: SecurityViewProps)
dispatch={dispatch}
readOnly={isReadOnly}
type="contracts"
whitelists={state.contracts as WhitelistContractsV2[]}
whitelists={state.contracts as WhitelistContracts[]}
/>
<Divider />
<ChainWhitelist
blockchains={blockchains as Blockchain[]}
dispatch={dispatch}
readOnly={isReadOnly}
type="methods"
whitelists={state.methods as WhitelistMethodsV2[]}
whitelists={state.methods as WhitelistMethods[]}
/>
</Box>
)
Expand Down

0 comments on commit 59bf267

Please sign in to comment.