Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit 93ce180

Browse files
authored
Enable apps for non-owners; fix app URL redirect (#2676)
* Enable apps for non-owners; fix app URL redirect * Add a non-owner warning text * Hide the gas estimation text for non-owners * Fix error not being displayed
1 parent 48af4bb commit 93ce180

5 files changed

Lines changed: 35 additions & 41 deletions

File tree

src/components/TransactionFailText/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import InfoIcon from 'src/assets/icons/info_red.svg'
88
import React from 'react'
99
import { useSelector } from 'react-redux'
1010
import { currentSafeThreshold } from 'src/logic/safe/store/selectors'
11+
import { grantedSelector } from 'src/routes/safe/container/selector'
1112

1213
const styles = createStyles({
1314
executionWarningRow: {
@@ -32,8 +33,9 @@ export const TransactionFailText = ({
3233
}: TransactionFailTextProps): React.ReactElement | null => {
3334
const classes = useStyles()
3435
const threshold = useSelector(currentSafeThreshold)
36+
const isOwner = useSelector(grantedSelector)
3537

36-
if (txEstimationExecutionStatus !== EstimationStatus.FAILURE) {
38+
if (txEstimationExecutionStatus !== EstimationStatus.FAILURE && isOwner) {
3739
return null
3840
}
3941

@@ -49,7 +51,12 @@ export const TransactionFailText = ({
4951
<Row align="center">
5052
<Paragraph color="error" className={classes.executionWarningRow}>
5153
<Img alt="Info Tooltip" height={16} src={InfoIcon} className={classes.warningIcon} />
52-
This transaction will most likely fail. {errorMessage}
54+
55+
{isOwner ? (
56+
<>This transaction will most likely fail. {errorMessage}</>
57+
) : (
58+
<>You are currently not an owner of this Safe and won&apos;t be able to submit this tx.</>
59+
)}
5360
</Paragraph>
5461
</Row>
5562
)

src/components/TransactionsFees/index.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Text } from '@gnosis.pm/safe-react-components'
77

88
type TransactionFailTextProps = {
99
txEstimationExecutionStatus: EstimationStatus
10-
gasCostFormatted: string
10+
gasCostFormatted?: string
1111
isExecution: boolean
1212
isCreation: boolean
1313
isOffChainSignature: boolean
@@ -35,19 +35,21 @@ export const TransactionFees = ({
3535

3636
return (
3737
<>
38-
<Paragraph size="lg" align="center">
39-
You&apos;re about to {transactionAction} a transaction and will have to confirm it with your currently connected
40-
wallet.{' '}
41-
{!isOffChainSignature && (
42-
<>
43-
Make sure you have{' '}
44-
<Text size="lg" as="span" color="text" strong>
45-
{gasCostFormatted}
46-
</Text>{' '}
47-
(fee price) {nativeCoin.name} in this wallet to fund this confirmation.
48-
</>
49-
)}
50-
</Paragraph>
38+
{gasCostFormatted != null && (
39+
<Paragraph size="lg" align="center">
40+
You&apos;re about to {transactionAction} a transaction and will have to confirm it with your currently
41+
connected wallet.{' '}
42+
{!isOffChainSignature && (
43+
<>
44+
Make sure you have{' '}
45+
<Text size="lg" as="span" color="text" strong>
46+
{gasCostFormatted}
47+
</Text>{' '}
48+
(fee price) {nativeCoin.name} in this wallet to fund this confirmation.
49+
</>
50+
)}
51+
</Paragraph>
52+
)}
5153
<TransactionFailText txEstimationExecutionStatus={txEstimationExecutionStatus} isExecution={isExecution} />
5254
</>
5355
)

src/routes/safe/components/Apps/components/AppFrame.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { ReactElement, useState, useRef, useCallback, useEffect } from 'react'
22
import styled from 'styled-components'
3-
import { FixedIcon, Loader, Title, Card } from '@gnosis.pm/safe-react-components'
3+
import { Loader, Title, Card } from '@gnosis.pm/safe-react-components'
44
import {
55
GetBalanceParams,
66
GetTxBySafeTxHashParams,
@@ -14,7 +14,6 @@ import { INTERFACE_MESSAGES, Transaction, RequestId, LowercaseNetworks } from '@
1414
import Web3 from 'web3'
1515

1616
import { currentSafe } from 'src/logic/safe/store/selectors'
17-
import { grantedSelector } from 'src/routes/safe/container/selector'
1817
import { getNetworkId, getNetworkName, getSafeAppsRpcServiceUrl, getTxServiceUrl } from 'src/config'
1918
import { SAFE_ROUTES } from 'src/routes/routes'
2019
import { isSameURL } from 'src/utils/url'
@@ -34,14 +33,6 @@ import { fetchSafeTransaction } from 'src/logic/safe/transactions/api/fetchSafeT
3433
import { logError, Errors } from 'src/logic/exceptions/CodedException'
3534
import { addressBookEntryName } from 'src/logic/addressBook/store/selectors'
3635

37-
const OwnerDisclaimer = styled.div`
38-
display: flex;
39-
align-items: center;
40-
justify-content: center;
41-
flex-direction: column;
42-
height: 476px;
43-
`
44-
4536
const AppWrapper = styled.div`
4637
display: flex;
4738
flex-direction: column;
@@ -93,7 +84,6 @@ const safeAppWeb3Provider = new Web3.providers.HttpProvider(getSafeAppsRpcServic
9384
})
9485

9586
const AppFrame = ({ appUrl }: Props): ReactElement => {
96-
const granted = useSelector(grantedSelector)
9787
const { address: safeAddress, ethBalance, owners, threshold } = useSelector(currentSafe)
9888
const safeName = useSelector((state) => addressBookEntryName(state, { address: safeAddress }))
9989
const { trackEvent } = useAnalytics()
@@ -291,15 +281,6 @@ const AppFrame = ({ appUrl }: Props): ReactElement => {
291281
return <LegalDisclaimer onCancel={redirectToBalance} onConfirm={onConsentReceipt} />
292282
}
293283

294-
if (NETWORK_NAME === 'UNKNOWN' || !granted) {
295-
return (
296-
<OwnerDisclaimer>
297-
<FixedIcon type="notOwner" />
298-
<Title size="xs">To use apps, you must be an owner of this Safe</Title>
299-
</OwnerDisclaimer>
300-
)
301-
}
302-
303284
return (
304285
<AppWrapper>
305286
<StyledCard>

src/routes/safe/components/Apps/components/ConfirmTxModal/ReviewConfirm.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Operation } from '@gnosis.pm/safe-react-gateway-sdk'
22
import { EthHashInfo, Text } from '@gnosis.pm/safe-react-components'
33
import React, { ReactElement, useEffect, useMemo, useState } from 'react'
4-
import { useDispatch } from 'react-redux'
4+
import { useDispatch, useSelector } from 'react-redux'
55
import styled from 'styled-components'
66

77
import ModalTitle from 'src/components/ModalTitle'
@@ -28,6 +28,7 @@ import Divider from 'src/components/Divider'
2828
import { ConfirmTxModalProps, DecodedTxDetail } from '.'
2929
import Hairline from 'src/components/layout/Hairline'
3030
import { ButtonStatus, Modal } from 'src/components/Modal'
31+
import { grantedSelector } from 'src/routes/safe/container/selector'
3132

3233
const { nativeCoin } = getNetworkInfo()
3334

@@ -86,6 +87,7 @@ export const ReviewConfirm = ({
8687
const [decodedData, setDecodedData] = useState<DecodedData | null>(null)
8788
const dispatch = useDispatch()
8889
const explorerUrl = getExplorerInfo(safeAddress)
90+
const isOwner = useSelector(grantedSelector)
8991

9092
const txRecipient: string | undefined = useMemo(
9193
() => (isMultiSend ? getMultisendContractAddress() : txs[0]?.to),
@@ -240,7 +242,7 @@ export const ReviewConfirm = ({
240242
{txEstimationExecutionStatus === EstimationStatus.LOADING ? null : (
241243
<TransactionFeesWrapper>
242244
<TransactionFees
243-
gasCostFormatted={gasCostFormatted}
245+
gasCostFormatted={isOwner ? gasCostFormatted : undefined}
244246
isExecution={isExecution}
245247
isCreation={isCreation}
246248
isOffChainSignature={isOffChainSignature}
@@ -255,7 +257,7 @@ export const ReviewConfirm = ({
255257
cancelButtonProps={{ onClick: handleTxRejection }}
256258
confirmButtonProps={{
257259
onClick: () => confirmTransactions(txParameters),
258-
disabled: areTxsMalformed,
260+
disabled: !isOwner || areTxsMalformed,
259261
status: buttonStatus,
260262
text: txEstimationExecutionStatus === EstimationStatus.LOADING ? 'Estimating' : undefined,
261263
}}

src/routes/safe/container/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { useState } from 'react'
33
import { useSelector } from 'react-redux'
44
import { generatePath, Redirect, Route, Switch } from 'react-router-dom'
55

6-
import { currentSafeFeaturesEnabled, safeAddressFromUrl } from 'src/logic/safe/store/selectors'
6+
import { currentSafeFeaturesEnabled, currentSafeOwners, safeAddressFromUrl } from 'src/logic/safe/store/selectors'
77
import { wrapInSuspense } from 'src/utils/wrapInSuspense'
88
import { SAFE_ROUTES } from 'src/routes/routes'
99
import { FEATURES } from 'src/config/networks/network.d'
@@ -26,6 +26,8 @@ const AddressBookTable = React.lazy(() => import('src/routes/safe/components/Add
2626
const Container = (): React.ReactElement => {
2727
const safeAddress = useSelector(safeAddressFromUrl)
2828
const featuresEnabled = useSelector(currentSafeFeaturesEnabled)
29+
const owners = useSelector(currentSafeOwners)
30+
const isSafeLoaded = owners.length > 0
2931
const balancesBaseRoute = generatePath(SAFE_ROUTES.ASSETS_BASE_ROUTE, {
3032
safeAddress,
3133
})
@@ -40,7 +42,7 @@ const Container = (): React.ReactElement => {
4042
onClose: () => {},
4143
})
4244

43-
if (!featuresEnabled) {
45+
if (!isSafeLoaded) {
4446
return (
4547
<LoadingContainer>
4648
<Loader size="md" />

0 commit comments

Comments
 (0)