-
Notifications
You must be signed in to change notification settings - Fork 209
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
feat: check destination address for SC wallets #2105
Open
dewanshparashar
wants to merge
15
commits into
master
Choose a base branch
from
fs-1035/custom-dest-address-check
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1c4e2a3
dev: custom destination address checjk
dewanshparashar c594e2e
dev: update custom destination checj
dewanshparashar 38109c4
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
dewanshparashar 6fb0418
dev: update content
dewanshparashar 30eba0a
dev updated content
dewanshparashar 9136a66
dev: update popup order
dewanshparashar fad79dd
dev: added check for usdc too
dewanshparashar e55267a
Merge branch 'master' into fs-1035/custom-dest-address-check
dewanshparashar d9ecf3a
dev: review comments
dewanshparashar b5dda7e
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
dewanshparashar bf1cb2c
Merge branch 'fs-1035/custom-dest-address-check' of github.com:Offcha…
dewanshparashar 3550d62
dev: add spacing
dewanshparashar dca029a
Merge branch 'master' into fs-1035/custom-dest-address-check
dewanshparashar 56a58dd
Merge branch 'master' into fs-1035/custom-dest-address-check
fionnachan d19b26b
Merge branch 'master' into fs-1035/custom-dest-address-check
dewanshparashar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
...ken-bridge-ui/src/components/TransferPanel/CustomDestinationAddressConfirmationDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { useState } from 'react' | ||
|
||
import { Dialog, UseDialogProps } from '../common/Dialog' | ||
import { ExternalLink } from '../common/ExternalLink' | ||
import { useNetworks } from '../../hooks/useNetworks' | ||
import { getNetworkName } from '../../util/networks' | ||
import { shortenAddress } from '../../util/CommonUtils' | ||
import { useArbQueryParams } from '../../hooks/useArbQueryParams' | ||
import { Checkbox } from '../common/Checkbox' | ||
|
||
export function CustomDestinationAddressConfirmationDialog( | ||
props: UseDialogProps | ||
) { | ||
const [{ destinationAddress = '' }] = useArbQueryParams() | ||
|
||
const [networks] = useNetworks() | ||
|
||
const networkName = getNetworkName(networks.destinationChain.id) | ||
|
||
const [checkboxChecked, setCheckboxChecked] = useState(false) | ||
|
||
function closeWithReset(confirmed: boolean) { | ||
props.onClose(confirmed) | ||
setCheckboxChecked(false) | ||
} | ||
|
||
return ( | ||
<Dialog | ||
{...props} | ||
title="Confirm Destination Address" | ||
className="flex flex-col gap-4" | ||
onClose={closeWithReset} | ||
actionButtonProps={{ | ||
disabled: !checkboxChecked | ||
}} | ||
> | ||
<div className="mb-4"> | ||
<p className="pb-2"> | ||
You are attempting to deposit funds to the same address{' '} | ||
{shortenAddress(destinationAddress)} on {networkName}. | ||
</p> | ||
<p className="pb-2"> | ||
This is an uncommon action because your smart contract wallet is only | ||
deployed on the currently connected chain. | ||
</p> | ||
</div> | ||
|
||
<p className="mb-8 rounded-md bg-orange/10 p-4"> | ||
<Checkbox | ||
label={ | ||
<span className="font-light"> | ||
I confirm that I have full control over the entered destination | ||
address on {networkName} and understand that proceeding without | ||
control may result in an{' '} | ||
<span className="font-bold">irrecoverable loss of funds</span>. | ||
</span> | ||
} | ||
checked={checkboxChecked} | ||
onChange={setCheckboxChecked} | ||
/> | ||
</p> | ||
|
||
<p> | ||
If not sure, please reach out to us on our{' '} | ||
<ExternalLink | ||
className="arb-hover underline" | ||
href="https://discord.gg/ZpZuw7p" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
<span className="font-medium">support channel</span> | ||
</ExternalLink>{' '} | ||
for assistance. | ||
</p> | ||
</Dialog> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import { useArbQueryParams } from '../../hooks/useArbQueryParams' | |
import { useDialog } from '../common/Dialog' | ||
import { TokenApprovalDialog } from './TokenApprovalDialog' | ||
import { WithdrawalConfirmationDialog } from './WithdrawalConfirmationDialog' | ||
import { CustomDestinationAddressConfirmationDialog } from './CustomDestinationAddressConfirmationDialog' | ||
import { TransferPanelSummary } from './TransferPanelSummary' | ||
import { useAppContextActions } from '../App/AppContext' | ||
import { trackEvent } from '../../util/AnalyticsUtils' | ||
|
@@ -173,6 +174,11 @@ export function TransferPanel() { | |
openUSDCDepositConfirmationDialog | ||
] = useDialog() | ||
|
||
const [ | ||
customDestinationAddressConfirmationDialogProps, | ||
openCustomDestinationAddressConfirmationDialog | ||
] = useDialog() | ||
|
||
const isCustomDestinationTransfer = !!latestDestinationAddress.current | ||
|
||
const { | ||
|
@@ -218,6 +224,13 @@ export function TransferPanel() { | |
return isDepositMode && isUnbridgedToken | ||
}, [isDepositMode, selectedToken]) | ||
|
||
const areSenderAndCustomDestinationAddressesEqual = useMemo(() => { | ||
return ( | ||
destinationAddress?.trim()?.toLowerCase() === | ||
walletAddress?.trim().toLowerCase() | ||
) | ||
}, [destinationAddress, walletAddress]) | ||
|
||
async function depositToken() { | ||
if (!selectedToken) { | ||
throw new Error('Invalid app state: no selected token') | ||
|
@@ -335,6 +348,12 @@ export function TransferPanel() { | |
setShowSmartContractWalletTooltip(true) | ||
}, 3000) | ||
|
||
const confirmCustomDestinationAddressForSCWallets = async () => { | ||
const waitForInput = openCustomDestinationAddressConfirmationDialog() | ||
const [confirmed] = await waitForInput() | ||
return confirmed | ||
} | ||
|
||
const transferCctp = async () => { | ||
if (!selectedToken) { | ||
return | ||
|
@@ -371,6 +390,16 @@ export function TransferPanel() { | |
if (!withdrawalConfirmation) return | ||
} | ||
|
||
// confirm if the user is certain about the custom destination address, especially if it matches the connected SCW address. | ||
// this ensures that user funds do not end up in the destination chain’s address that matches their source-chain wallet address, which they may not control. | ||
if ( | ||
isSmartContractWallet && | ||
isDepositMode && | ||
areSenderAndCustomDestinationAddressesEqual | ||
) { | ||
await confirmCustomDestinationAddressForSCWallets() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same on L626. Currently if user click on cancel or close, we proceed as if user click on confirm. We should check for the returned value here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
} | ||
|
||
const cctpTransferStarter = new CctpTransferStarter({ | ||
sourceChainProvider, | ||
destinationChainProvider | ||
|
@@ -560,12 +589,11 @@ export function TransferPanel() { | |
destinationChainErc20Address | ||
}) | ||
|
||
const { isNativeCurrencyTransfer, isWithdrawal } = | ||
getBridgeTransferProperties({ | ||
sourceChainId, | ||
sourceChainErc20Address, | ||
destinationChainId | ||
}) | ||
const { isWithdrawal } = getBridgeTransferProperties({ | ||
sourceChainId, | ||
sourceChainErc20Address, | ||
destinationChainId | ||
}) | ||
|
||
if (isWithdrawal && selectedToken && !sourceChainErc20Address) { | ||
/* | ||
|
@@ -588,6 +616,16 @@ export function TransferPanel() { | |
|
||
const destinationAddress = latestDestinationAddress.current | ||
|
||
// confirm if the user is certain about the custom destination address, especially if it matches the connected SCW address. | ||
// this ensures that user funds do not end up in the destination chain’s address that matches their source-chain wallet address, which they may not control. | ||
if ( | ||
isSmartContractWallet && | ||
isDepositMode && | ||
areSenderAndCustomDestinationAddressesEqual | ||
) { | ||
await confirmCustomDestinationAddressForSCWallets() | ||
} | ||
|
||
const isCustomNativeTokenAmount2 = | ||
nativeCurrency.isCustom && | ||
isBatchTransferSupported && | ||
|
@@ -971,6 +1009,10 @@ export function TransferPanel() { | |
amount={amount} | ||
/> | ||
|
||
<CustomDestinationAddressConfirmationDialog | ||
{...customDestinationAddressConfirmationDialogProps} | ||
/> | ||
|
||
<div | ||
className={twMerge( | ||
'mb-7 flex flex-col border-y border-white/30 bg-gray-1 p-4 shadow-[0px_4px_20px_rgba(0,0,0,0.2)]', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have a link to the address on the explorer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated