Skip to content
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
1 change: 1 addition & 0 deletions src/components/transactions/Bridge/BridgeModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ export const BridgeModalContent = () => {
</Box>

<ChangeNetworkWarning
autoSwitchOnMount={true}
networkName={getNetworkConfig(sourceNetworkObj.chainId).name}
chainId={sourceNetworkObj.chainId}
event={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ export const ClaimRewardsModalContent = ({ user, reserves }: ClaimRewardsModalCo
<>
<TxModalTitle title="Claim rewards" />
{isWrongNetwork && !readOnlyModeAddress && (
<ChangeNetworkWarning networkName={networkConfig.name} chainId={currentChainId} />
<ChangeNetworkWarning
autoSwitchOnMount={true}
networkName={networkConfig.name}
chainId={currentChainId}
/>
)}

{blockingError !== undefined && (
Expand Down
6 changes: 5 additions & 1 deletion src/components/transactions/Emode/EmodeModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ export const EmodeModalContent = ({ user }: { user: ExtendedFormattedUser }) =>
<>
<TxModalTitle title={<Trans>Manage E-Mode</Trans>} />
{isWrongNetwork && !readOnlyModeAddress && (
<ChangeNetworkWarning networkName={networkConfig.name} chainId={currentChainId} />
<ChangeNetworkWarning
autoSwitchOnMount={true}
networkName={networkConfig.name}
chainId={currentChainId}
/>
)}

<Typography variant="caption">
Expand Down
1 change: 1 addition & 0 deletions src/components/transactions/FlowCommons/ModalWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const ModalWrapper: React.FC<{
)}
{isWrongNetwork && !readOnlyModeAddress && (
<ChangeNetworkWarning
autoSwitchOnMount={true}
networkName={getNetworkConfig(requiredChainId).name}
chainId={requiredChainId}
event={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ export const GovDelegationModalContent: React.FC<GovDelegationModalContentProps>
<>
<TxModalTitle title={isRevokeModal ? 'Revoke power' : 'Set up delegation'} />
{isWrongNetwork && !readOnlyModeAddress && (
<ChangeNetworkWarning networkName={networkConfig.name} chainId={govChain} />
<ChangeNetworkWarning
autoSwitchOnMount={true}
networkName={networkConfig.name}
chainId={govChain}
/>
)}
{(isRevokeModal &&
!!powers &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ export const GovRepresentativesContent = ({
<TxModalTitle title="Edit address" />
</Box>
{isWrongNetwork && !readOnlyModeAddress && (
<ChangeNetworkWarning networkName={networkConfig.name} chainId={govChain} />
<ChangeNetworkWarning
autoSwitchOnMount={true}
networkName={networkConfig.name}
chainId={govChain}
/>
)}
<Stack direction="column" gap={2}>
{reps.map((r, i) => (
Expand Down
6 changes: 5 additions & 1 deletion src/components/transactions/GovVote/GovVoteModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ export const GovVoteModalContent = ({
<>
<TxModalTitle title="Governance vote" />
{isWrongNetwork && !readOnlyModeAddress && (
<ChangeNetworkWarning networkName={networkConfig.name} chainId={proposalVotingChain} />
<ChangeNetworkWarning
autoSwitchOnMount={true}
networkName={networkConfig.name}
chainId={proposalVotingChain}
/>
)}
{blockingError !== undefined && (
<Typography variant="helperText" color="red">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ export const MigrateV3ModalContent = ({
<>
<TxModalTitle title="Migrate to V3" />
{isWrongNetwork && !readOnlyModeAddress && (
<ChangeNetworkWarning networkName={networkConfig.name} chainId={currentChainId} />
<ChangeNetworkWarning
autoSwitchOnMount={true}
networkName={networkConfig.name}
chainId={currentChainId}
/>
)}

<TxModalDetails gasLimit={gasLimit}>
Expand Down
1 change: 1 addition & 0 deletions src/components/transactions/Stake/StakeModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const StakeModalContent = ({ stakeAssetName, icon }: StakeProps) => {
networkName={networkConfig.name}
chainId={stakingChain}
funnel={'Stake Modal'}
autoSwitchOnMount={true}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ export const StakeCooldownModalContent = ({ stakeAssetName, icon }: StakeCooldow
<>
<TxModalTitle title="Cooldown to unstake" />
{isWrongNetwork && !readOnlyModeAddress && (
<ChangeNetworkWarning networkName={networkConfig.name} chainId={stakingChain} />
<ChangeNetworkWarning
autoSwitchOnMount={true}
networkName={networkConfig.name}
chainId={stakingChain}
/>
)}
<Typography variant="description" sx={{ mb: 6 }}>
<Trans>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ export const StakeRewardClaimModalContent = ({ stakeAssetName, icon }: StakeRewa
<>
<TxModalTitle title="Claim" symbol={rewardsSymbol} />
{isWrongNetwork && !readOnlyModeAddress && (
<ChangeNetworkWarning networkName={networkConfig.name} chainId={stakingChain} />
<ChangeNetworkWarning
autoSwitchOnMount={true}
networkName={networkConfig.name}
chainId={stakingChain}
/>
)}
{blockingError !== undefined && (
<Typography variant="helperText" color="red">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ export const StakeRewardClaimRestakeModalContent = ({
<>
<TxModalTitle title="Restake AAVE rewards" />
{isWrongNetwork && !readOnlyModeAddress && (
<ChangeNetworkWarning networkName={networkConfig.name} chainId={stakingChain} />
<ChangeNetworkWarning
autoSwitchOnMount={true}
networkName={networkConfig.name}
chainId={stakingChain}
/>
)}
<CooldownWarning />
<AssetInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ export const BaseSwitchModalContent = ({
)}
{showChangeNetworkWarning && isWrongNetwork.isWrongNetwork && !readOnlyModeAddress && (
<ChangeNetworkWarning
autoSwitchOnMount={true}
networkName={selectedNetworkConfig.name}
chainId={selectedChainId}
event={{
Expand Down
6 changes: 5 additions & 1 deletion src/components/transactions/UnStake/UnStakeModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ export const UnStakeModalContent = ({ stakeAssetName, icon }: UnStakeProps) => {
<>
<TxModalTitle title="Unstake" symbol={nameFormatted} />
{isWrongNetwork && !readOnlyModeAddress && (
<ChangeNetworkWarning networkName={networkConfig.name} chainId={stakingChain} />
<ChangeNetworkWarning
autoSwitchOnMount={true}
networkName={networkConfig.name}
chainId={stakingChain}
/>
)}
<AssetInput
value={amount}
Expand Down
65 changes: 57 additions & 8 deletions src/components/transactions/Warnings/ChangeNetworkWarning.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ChainId } from '@aave/contract-helpers';
import { Trans } from '@lingui/macro';
import { AlertProps, Button, Typography } from '@mui/material';
import { AlertProps, Button, CircularProgress, Typography } from '@mui/material';
import { useEffect, useState } from 'react';
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
import { TrackEventProps } from 'src/store/analyticsSlice';
import { useRootStore } from 'src/store/root';
Expand All @@ -14,6 +15,7 @@ export type ChangeNetworkWarningProps = AlertProps & {
chainId: ChainId;
event?: TrackEventProps;
askManualSwitch?: boolean;
autoSwitchOnMount?: boolean;
};

export const ChangeNetworkWarning = ({
Expand All @@ -22,32 +24,79 @@ export const ChangeNetworkWarning = ({
event,
funnel,
askManualSwitch = false,
autoSwitchOnMount = true,
...rest
}: ChangeNetworkWarningProps) => {
const { switchNetwork, switchNetworkError } = useWeb3Context();
const trackEvent = useRootStore((store) => store.trackEvent);

const handleSwitchNetwork = () => {
trackEvent(GENERAL.SWITCH_NETWORK, { funnel, ...event?.eventParams, network: networkName });
const [isAutoSwitching, setIsAutoSwitching] = useState(false);
const [hasAttemptedAutoSwitch, setHasAttemptedAutoSwitch] = useState(false);

useEffect(() => {
if (autoSwitchOnMount && !hasAttemptedAutoSwitch && !isAutoSwitching) {
setHasAttemptedAutoSwitch(true);
setIsAutoSwitching(true);

trackEvent(GENERAL.SWITCH_NETWORK, {
funnel,
...event?.eventParams,
network: networkName,
});

switchNetwork(chainId).finally(() => {
setIsAutoSwitching(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setIsAutoSwitching(false);
setIsAutoSwitching(false);
setHasAttemptedAutoSwitch(true);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added in fbd2729

setHasAttemptedAutoSwitch(true);
});
}
}, [
autoSwitchOnMount,
hasAttemptedAutoSwitch,
chainId,
switchNetwork,
trackEvent,
funnel,
event,
networkName,
]);

const handleManualSwitchNetwork = () => {
trackEvent(GENERAL.SWITCH_NETWORK, {
funnel,
...event?.eventParams,
network: networkName,
manual: false,
});
switchNetwork(chainId);
};
return (
<Warning severity="error" icon={false} {...rest}>
{switchNetworkError ? (
{isAutoSwitching ? (
<Typography variant="description" sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
<CircularProgress size={16} />
<Trans>Switching to {networkName}...</Trans>
</Typography>
) : switchNetworkError ? (
<Typography>
<Trans>
Seems like we can&apos;t switch the network automatically. Please check if you can
change it from the wallet.
{hasAttemptedAutoSwitch
? "We couldn't switch the network automatically. Please check if you can change it from the wallet."
: "Seems like we can't switch the network automatically. Please check if you can change it from the wallet."}
</Trans>
</Typography>
) : (
// Show manual switch option
<Typography variant="description">
<Trans>Please switch to {networkName}.</Trans>{' '}
<Trans>
{hasAttemptedAutoSwitch
? `Auto-switch failed. Please manually switch to ${networkName}.`
: `Please switch to ${networkName}.`}
</Trans>{' '}
{!askManualSwitch && (
<Button
variant="text"
sx={{ ml: '2px', verticalAlign: 'top' }}
onClick={handleSwitchNetwork}
onClick={handleManualSwitchNetwork}
disableRipple
>
<Typography variant="description">
Expand Down
2 changes: 1 addition & 1 deletion src/locales/el/messages.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/locales/en/messages.js

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ msgstr "Participating in this {symbol} reserve gives annualized rewards."
msgid "Use your AAVE, stkAAVE, or aAave balance to delegate your voting and proposition powers. You will not be sending any tokens, only the rights to vote and propose changes to the protocol. You can re-delegate or revoke power to self at any time."
msgstr "Use your AAVE, stkAAVE, or aAave balance to delegate your voting and proposition powers. You will not be sending any tokens, only the rights to vote and propose changes to the protocol. You can re-delegate or revoke power to self at any time."

#: src/components/transactions/Warnings/ChangeNetworkWarning.tsx
msgid "Seems like we can't switch the network automatically. Please check if you can change it from the wallet."
msgstr "Seems like we can't switch the network automatically. Please check if you can change it from the wallet."

#: src/modules/reserve-overview/BorrowInfo.tsx
msgid "Borrow cap"
msgstr "Borrow cap"
Expand Down Expand Up @@ -1193,6 +1189,8 @@ msgstr "deposited"
#: src/components/transactions/StakeCooldown/StakeCooldownModalContent.tsx
#: src/components/transactions/StakeCooldown/StakeCooldownModalContent.tsx
#: src/components/transactions/Switch/SwitchAssetInput.tsx
#: src/components/transactions/Warnings/ChangeNetworkWarning.tsx
#: src/components/transactions/Warnings/ChangeNetworkWarning.tsx
#: src/layouts/TopBarNotify.tsx
#: src/layouts/TopBarNotify.tsx
#: src/layouts/TopBarNotify.tsx
Expand Down Expand Up @@ -2979,10 +2977,6 @@ msgstr "Can be executed"
msgid "Assets with zero LTV ({0}) must be withdrawn or disabled as collateral to perform this action"
msgstr "Assets with zero LTV ({0}) must be withdrawn or disabled as collateral to perform this action"

#: src/components/transactions/Warnings/ChangeNetworkWarning.tsx
msgid "Please switch to {networkName}."
msgstr "Please switch to {networkName}."

#: src/components/transactions/GovDelegation/DelegationTypeSelector.tsx
msgid "Both"
msgstr "Both"
Expand Down Expand Up @@ -3127,6 +3121,10 @@ msgstr "The underlying balance needs to be greater than 0"
msgid "Not enough staked balance"
msgstr "Not enough staked balance"

#: src/components/transactions/Warnings/ChangeNetworkWarning.tsx
msgid "Switching to {networkName}..."
msgstr "Switching to {networkName}..."

#: src/components/transactions/Warnings/SNXWarning.tsx
msgid "please check that the amount you want to supply is not currently being used for staking. If it is being used for staking, your transaction might fail."
msgstr "please check that the amount you want to supply is not currently being used for staking. If it is being used for staking, your transaction might fail."
Expand Down
2 changes: 1 addition & 1 deletion src/locales/es/messages.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/locales/fr/messages.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/modules/umbrella/StakeCooldownModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ export const StakeCooldownModalContent = ({ stakeData }: { stakeData: MergedStak
<>
<TxModalTitle title="Cooldown to unstake" />
{isWrongNetwork && !readOnlyModeAddress && (
<ChangeNetworkWarning networkName={currentNetworkConfig.name} chainId={currentChainId} />
<ChangeNetworkWarning
autoSwitchOnMount={true}
networkName={currentNetworkConfig.name}
chainId={currentChainId}
/>
)}
<Typography variant="description" sx={{ mb: 6 }}>
<Trans>
Expand Down
12 changes: 10 additions & 2 deletions src/modules/umbrella/UmbrellaClaimModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ export const UmbrellaClaimAllModalContent = ({ stakeData }: UmbrellaClaimAllModa
<>
<TxModalTitle title="Claim rewards" />
{isWrongNetwork && !readOnlyModeAddress && (
<ChangeNetworkWarning networkName={networkConfig.name} chainId={requiredChainId} />
<ChangeNetworkWarning
autoSwitchOnMount={true}
networkName={networkConfig.name}
chainId={requiredChainId}
/>
)}

<TxModalDetails gasLimit={gasLimit}>
Expand Down Expand Up @@ -198,7 +202,11 @@ export const UmbrellaClaimModalContent = ({ stakeData }: UmbrellaClaimModalConte
<>
<TxModalTitle title="Claim rewards" />
{isWrongNetwork && !readOnlyModeAddress && (
<ChangeNetworkWarning networkName={networkConfig.name} chainId={requiredChainId} />
<ChangeNetworkWarning
autoSwitchOnMount={true}
networkName={networkConfig.name}
chainId={requiredChainId}
/>
)}

{isMultiReward && (
Expand Down
Loading