Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into pay-now-pay-later
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan committed Feb 9, 2024
2 parents 884bc27 + 88c5b56 commit 99cb71d
Show file tree
Hide file tree
Showing 15 changed files with 391 additions and 67 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "safe-wallet-web",
"homepage": "https://github.com/safe-global/safe-wallet-web",
"license": "GPL-3.0",
"version": "1.29.0",
"version": "1.29.1",
"type": "module",
"scripts": {
"dev": "next dev",
Expand Down Expand Up @@ -57,7 +57,7 @@
"@safe-global/safe-core-sdk-utils": "^1.7.4",
"@safe-global/safe-deployments": "1.32.0",
"@safe-global/safe-ethers-lib": "^1.9.4",
"@safe-global/safe-gateway-typescript-sdk": "^3.14.0",
"@safe-global/safe-gateway-typescript-sdk": "^3.15.0",
"@safe-global/safe-modules-deployments": "^1.2.0",
"@sentry/react": "^7.91.0",
"@spindl-xyz/attribution-lite": "^1.4.0",
Expand Down
7 changes: 1 addition & 6 deletions src/components/common/NetworkSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ const MenuWithTooltip = forwardRef<HTMLUListElement>(function MenuWithTooltip(pr
)
})

const testNets = ['gor', 'base-gor', 'sep']
const isTestnet = (shortName: string) => {
return testNets.includes(shortName)
}

const NetworkSelector = (props: { onChainSelect?: () => void }): ReactElement => {
const wallet = useWallet()
const isDarkMode = useDarkMode()
Expand All @@ -44,7 +39,7 @@ const NetworkSelector = (props: { onChainSelect?: () => void }): ReactElement =>
const chainId = useChainId()
const router = useRouter()

const [testNets, prodNets] = useMemo(() => partition(configs, (config) => isTestnet(config.shortName)), [configs])
const [testNets, prodNets] = useMemo(() => partition(configs, (config) => config.isTestnet), [configs])

const getNetworkLink = useCallback(
(shortName: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ReviewStep, { NetworkFee } from '@/components/new-safe/create/steps/Revie
import * as useWallet from '@/hooks/wallets/useWallet'
import { type ConnectedWallet } from '@/hooks/wallets/useOnboard'
import { ONBOARD_MPC_MODULE_LABEL } from '@/services/mpc/SocialLoginModule'
import { act, fireEvent, waitFor } from '@testing-library/react'
import { act, fireEvent } from '@testing-library/react'

const mockChainInfo = {
chainId: '100',
Expand Down
88 changes: 51 additions & 37 deletions src/components/new-safe/create/steps/ReviewStep/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import ChainIndicator from '@/components/common/ChainIndicator'
import type { NamedAddress } from '@/components/new-safe/create/types'
import EthHashInfo from '@/components/common/EthHashInfo'
import { getTotalFeeFormatted } from '@/hooks/useGasPrice'
import type { StepRenderProps } from '@/components/new-safe/CardStepper/useCardStepper'
import type { NewSafeFormData } from '@/components/new-safe/create'
import { computeNewSafeAddress } from '@/components/new-safe/create/logic'
Expand All @@ -18,7 +20,7 @@ import { LATEST_SAFE_VERSION } from '@/config/constants'
import PayNowPayLater, { PayMethod } from '@/features/counterfactual/PayNowPayLater'
import { createCounterfactualSafe } from '@/features/counterfactual/utils'
import { useCurrentChain, useHasFeature } from '@/hooks/useChains'
import useGasPrice, { getTotalFee } from '@/hooks/useGasPrice'
import useGasPrice from '@/hooks/useGasPrice'
import useIsWrongChain from '@/hooks/useIsWrongChain'
import { MAX_HOUR_RELAYS, useLeastRemainingRelays } from '@/hooks/useRemainingRelays'
import useWalletCanPay from '@/hooks/useWalletCanPay'
Expand All @@ -28,7 +30,6 @@ import { getReadOnlyFallbackHandlerContract } from '@/services/contracts/safeCon
import { isSocialLoginWallet } from '@/services/mpc/SocialLoginModule'
import { useAppDispatch } from '@/store'
import { FEATURES } from '@/utils/chains'
import { formatVisualAmount } from '@/utils/formatters'
import { hasRemainingRelays } from '@/utils/relaying'
import ArrowBackIcon from '@mui/icons-material/ArrowBack'
import { Alert, Box, Button, Divider, Grid, Typography } from '@mui/material'
Expand Down Expand Up @@ -101,6 +102,52 @@ export const NetworkFee = ({
)
}

export const SafeSetupOverview = ({
name,
owners,
threshold,
}: {
name?: string
owners: NamedAddress[]
threshold: number
}) => {
const chain = useCurrentChain()

return (
<Grid container spacing={3}>
<ReviewRow name="Network" value={<ChainIndicator chainId={chain?.chainId} inline />} />
{name && <ReviewRow name="Name" value={<Typography>{name}</Typography>} />}
<ReviewRow
name="Owners"
value={
<Box data-testid="review-step-owner-info" className={css.ownersArray}>
{owners.map((owner, index) => (
<EthHashInfo
address={owner.address}
name={owner.name || owner.ens}
shortAddress={false}
showPrefix={false}
showName
hasExplorer
showCopyButton
key={index}
/>
))}
</Box>
}
/>
<ReviewRow
name="Threshold"
value={
<Typography>
{threshold} out of {owners.length} owner(s)
</Typography>
}
/>
</Grid>
)
}

const ReviewStep = ({ data, onSubmit, onBack, setStep }: StepRenderProps<NewSafeFormData>) => {
const isWrongChain = useIsWrongChain()
useSyncSafeCreationStep(setStep)
Expand Down Expand Up @@ -138,10 +185,7 @@ const ReviewStep = ({ data, onSubmit, onBack, setStep }: StepRenderProps<NewSafe

const walletCanPay = useWalletCanPay({ gasLimit, maxFeePerGas, maxPriorityFeePerGas })

const totalFee =
gasLimit && maxFeePerGas
? formatVisualAmount(getTotalFee(maxFeePerGas, maxPriorityFeePerGas, gasLimit), chain?.nativeCurrency.decimals)
: '> 0.001'
const totalFee = getTotalFeeFormatted(maxFeePerGas, maxPriorityFeePerGas, gasLimit, chain)

// Only 1 out of 1 safe setups are supported for now
const isCounterfactual = data.threshold === 1 && data.owners.length === 1 && isCounterfactualEnabled
Expand Down Expand Up @@ -195,37 +239,7 @@ const ReviewStep = ({ data, onSubmit, onBack, setStep }: StepRenderProps<NewSafe
return (
<>
<Box className={layoutCss.row}>
<Grid container spacing={3}>
<ReviewRow name="Network" value={<ChainIndicator chainId={chain?.chainId} inline />} />
{data.name && <ReviewRow name="Name" value={<Typography>{data.name}</Typography>} />}
<ReviewRow
name="Owners"
value={
<Box data-testid="review-step-owner-info" className={css.ownersArray}>
{data.owners.map((owner, index) => (
<EthHashInfo
address={owner.address}
name={owner.name || owner.ens}
shortAddress={false}
showPrefix={false}
showName
hasExplorer
showCopyButton
key={index}
/>
))}
</Box>
}
/>
<ReviewRow
name="Threshold"
value={
<Typography>
{data.threshold} out of {data.owners.length} owner(s)
</Typography>
}
/>
</Grid>
<SafeSetupOverview name={data.name} owners={data.owners} threshold={data.threshold} />
</Box>

{isCounterfactual && (
Expand Down
10 changes: 7 additions & 3 deletions src/components/tx-flow/flows/AddOwner/ReviewOwner.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useCurrentChain } from '@/hooks/useChains'
import { useContext, useEffect } from 'react'
import { Typography, Divider, Box, SvgIcon, Paper } from '@mui/material'

Expand All @@ -20,21 +21,24 @@ export const ReviewOwner = ({ params }: { params: AddOwnerFlowProps | ReplaceOwn
const { setSafeTx, setSafeTxError } = useContext(SafeTxContext)
const { safe } = useSafeInfo()
const { chainId } = safe
const chain = useCurrentChain()
const { newOwner, removedOwner, threshold } = params

useEffect(() => {
if (!chain) return

const promise = removedOwner
? createSwapOwnerTx({
? createSwapOwnerTx(chain, safe.deployed, {
newOwnerAddress: newOwner.address,
oldOwnerAddress: removedOwner.address,
})
: createAddOwnerTx({
: createAddOwnerTx(chain, safe.deployed, {
ownerAddress: newOwner.address,
threshold,
})

promise.then(setSafeTx).catch(setSafeTxError)
}, [removedOwner, newOwner, threshold, setSafeTx, setSafeTxError])
}, [removedOwner, newOwner, threshold, setSafeTx, setSafeTxError, chain, safe.deployed])

const addAddressBookEntryAndSubmit = () => {
if (typeof newOwner.name !== 'undefined') {
Expand Down
Loading

0 comments on commit 99cb71d

Please sign in to comment.