Skip to content
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: holistic custom recipient address part 2 #6072

Merged
merged 48 commits into from
Feb 5, 2024

Conversation

gomesalexandre
Copy link
Contributor

@gomesalexandre gomesalexandre commented Jan 24, 2024

Description

Adds custom recipient address support holistically, regardless of whether or not the currently connected wallet does/not support the receive chain

TODO:
- [x] add form context instead of handrolled logic and move me to a dedicated component
- [x] dispatch on save only, but still validate on form value change
- [x] ensure smart contract checks are honored
- [x] custom/recipient states
- [ ] styling
- [x] If the user hovers over the tag they will see a tooltip that says, "This is your custom recipient address"
- [ ] We should absolutely not do this. This is by design, and we *need* to refetch quotes ~~loosen receive address reactivity so that we don't get rugged infinitely refreshing on valid recipient~~

Pull Request Type

  • 🐛 Bug fix (Non-breaking Change: Fixes an issue)
  • 🛠️ Chore (Non-breaking Change: Doc updates, pkg upgrades, typos, etc..)
  • 💅 New Feature (Breaking/Non-breaking Change)

Issue (if applicable)

Risk

High Risk PRs Require 2 approvals

High. While this is theoretically still under flag and there may be another PR to improve things visually, and another to turn the flag on which will give us another chance to test this, eng. and ops should assume this is going directly to production with no flag.

Testing

⚠️ Test all the below both with a wallet supporting the chain you're swapping to, and one which does not
⚠️ Test this both this feature with the flag on, and regression test it with the flag off as enabling it is going to go in as a separate follow-up PR

  • Custom recipient address is honored fow all swaps. EVM swappers, THOR, streaming/long-tail, you name it.
  • Validation is working - entering an address for a wrong chain or something that's not a valid address doesn't let you continue
  • Ensure going back and forth from custom to default wallet address brings no regressions
  • While this was not introduced by this PR, this will now expose this in a much bigger area: we're leveraging the address validation we have for sends, meaning it is possible to input an ENS name. Ensure this doesn't result in lost user funds, in particular with THORCHain.

^Note WRT the above: this shouldn't be an issue as the custom recipient will be used to get a quote, so instead of producing bugs, this will simply limit the amount of available swappers when using an ENS address (because the missing swappers do not support it, hence do not yield a quote)

  • Ensure THORChain custom recipients do not result in loss funds. While this should not be an issue for regular swaps (only long-tail swaps to EVM chains -which we do not support yet - with a smart contract address as destination are affected by the smart contract restriction), it may.
  • Ensure account selection does not rug custom recipient

Engineering

Operations

Screenshots (if applicable)

Invalid address

Screenshot 2024-01-24 at 23 09 19

Default wallet address

Screenshot 2024-01-24 at 23 09 29

Custom recipient valid address input

Screenshot 2024-01-24 at 23 09 45

Set custom recipient

<img width="787" alt="Screenshot 2024-01-24 at 23 34 27" src="https://github.com/shapeshift/web/assets/17035424/3db140d9-8153-4ef7-83ff-c897d22c0ddd"

Setting an ENS as custom recipient works and restricts the available swappers on swappers supporting it

Screen.Recording.2024-01-24.at.23.41.02.mov

1inch account 0 sell address, ETH account 1 as custom recipient

Screenshot 2024-01-24 at 23 34 27 Screenshot 2024-01-24 at 23 35 48 Screenshot 2024-01-24 at 23 36 26

Li.Fi account 0 sell address, ETH account 1 as custom recipient

Screenshot 2024-01-24 at 23 37 17 image image

Random DOGE address with no balance as custom recipient

Screenshot 2024-01-24 at 23 45 13 image image image image

Wallet not supporting the receive asset

  • Notice how the new custom recipient kicks in instead of the old receive address component as soon as we get an active quote, meaning we were able to using a custom recipient
Screen.Recording.2024-01-25.at.00.07.50.mov

Flag off

Screen.Recording.2024-01-25.at.00.07.50.mov

Copy link
Contributor Author

gomesalexandre commented Jan 24, 2024

@gomesalexandre gomesalexandre changed the title feat: manual receive address part 2 feat: holistic custom recipient address part 2 Jan 24, 2024
@@ -64,7 +64,7 @@ export const ManualAddressEntry: FC = memo((): JSX.Element | null => {
// If we have a valid manual receive address, set it in the form
useEffect(() => {
manualReceiveAddress && setFormValue(SendFormFields.Input, manualReceiveAddress)
}, [dispatch, manualReceiveAddress, setFormValue])
}, [manualReceiveAddress, setFormValue])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was not needed but somehow not caught by the linter

const isYatSupported = isYatFeatureEnabled && isYatSupportedByReceiveChain
const {
formState: { isValidating, isValid },
// trigger: formTrigger, // TODO(gomes): do we need this?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Question for @0xApotheosis since this bit was taken from the previous custom receive address component

Copy link
Contributor

@0xApotheosis 0xApotheosis Feb 2, 2024

Choose a reason for hiding this comment

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

I'm going to go with "No" - I don't remember this guy's story, but I suspect it can go.

@gomesalexandre gomesalexandre marked this pull request as ready for review January 24, 2024 23:25
@gomesalexandre gomesalexandre requested a review from a team as a code owner January 24, 2024 23:25
tradeQuoteStep?.source === THORCHAIN_LONGTAIL_STREAMING_SWAP_SOURCE &&
_isSmartContractReceiveAddress !== false
)
return true
Copy link
Member

Choose a reason for hiding this comment

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

might also need to update
src/state/apis/swapper/helpers/validateTradeQuote.ts -> disableSmartContractSwap

Copy link
Contributor Author

@gomesalexandre gomesalexandre Jan 25, 2024

Choose a reason for hiding this comment

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

Nice catch, will tackle 🙏🏽 also noticed we've apparently broken the smart contract checks in https://github.com/shapeshift/web/pull/5971/files#diff-b6f4d6672824399e71740531e3b09efe3ad3fabeb3ad6c4ce0763969f9d39ab7R210, will author a hotfix in the meantime (see receiveAddress vs. senderAddress)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -351,77 +290,7 @@ export const ReceiveSummary: FC<ReceiveSummaryProps> = memo(
</Row>
</>
)}

{/* TODO(gomes): This should probably be made its own component and <ManualAddressEntry /> removed */}
{/* TODO(gomes): we can safely remove this condition when this feature goes live */}
Copy link
Member

Choose a reason for hiding this comment

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

🐐

Copy link
Member

@woodenfurniture woodenfurniture left a comment

Choose a reason for hiding this comment

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

Code wise looks good apart from 1 blocking comment. Will need to test thoroughly when back online

@gomesalexandre gomesalexandre changed the base branch from develop to fix_smart_contract_validateQuote_regression January 25, 2024 10:30
@gomesalexandre gomesalexandre marked this pull request as draft January 25, 2024 10:31
@gomesalexandre gomesalexandre marked this pull request as ready for review January 25, 2024 10:40
@gomesalexandre
Copy link
Contributor Author

Cross-account issue captured in #6121

@gomesalexandre
Copy link
Contributor Author

More functional testing:

I was consistently able to get into a sad state by:

  1. Setting a custom address
  2. Removing it
  3. Typing a custom address, deleting it, and pressing "Preview Trade" (some combination of this, I'm not sure exactly - see video)

We should disable the check button (and possibly "Preview Trade") when no input is provided, as it does nothing in this case.

@0xApotheosis while this is still in draft for the prod issue noted above, this has been fixed in 74b9250:

Screen.Recording.2024-02-02.at.12.18.33.mov

Also actioned the streaming swap longtail source comment in 7228126

This is ready to be retested, but can't be merged until the prod issue is tackled.

@gomesalexandre gomesalexandre marked this pull request as ready for review February 3, 2024 22:48
@gomesalexandre gomesalexandre changed the base branch from develop to fix_synchronize_accountids_mount February 3, 2024 22:49
Copy link
Contributor

@0xApotheosis 0xApotheosis left a comment

Choose a reason for hiding this comment

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

❌ THORSwap trades now seem broken (see comment inline)

✅ Check mark is now disabled when no valid address entered.

❌ "Preview Trade" button is not disabled when no address is present (e.g. when entering a custom receive address, before pressing the green check to save it). Pressing "Preview Trade" at this time throws an exception:

Screenshot 2024-02-05 at 9 33 09 am Screenshot 2024-02-05 at 9 31 53 am

Comment on lines 235 to 240
if (
[firstHop.source, secondHop.source].some(source =>
[THORCHAIN_LONGTAIL_SWAP_SOURCE, THORCHAIN_LONGTAIL_STREAMING_SWAP_SOURCE].includes(source),
) &&
_isSmartContractReceiveAddress !== false
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we've now broken quotes from THORChain. The network response returns correctly, but we get the below (with and without a custom receive address):

Screenshot 2024-02-05 at 9 26 30 am

Copy link
Contributor Author

@gomesalexandre gomesalexandre Feb 5, 2024

Choose a reason for hiding this comment

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

That one was actually quite the rabbit-hole!

tl;dr of what's up here is we had absolutely no type-safety on steps.length which could (according to types) be of any n-length, and in the specific case of THOR, secondHop was defined here.
Fixed this by bringing in the context of single and multi-hop trade quotes, the former consisting of 1 step, the latter consisting of 2 (for now, as we only have a max. of two hops here).
This now brings type errors which should've been present before e.g in here - 1bbd41a

Also fixed the something went very wrong error in 60b5672 - we got too safe here as there are always going to be at least two renders without a receive address as things are loading

After bringing in safety (and removing the wrong one for receiveAddress checks), THOR is now happy:

  • with regular swaps and default receive address
image image
  • with streaming swaps and vitalik.eth injected wallet
image image image image

Copy link
Contributor

@0xApotheosis 0xApotheosis left a comment

Choose a reason for hiding this comment

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

🤔 Probably not a blocker, as we no longer crash in this state, but we still don't ensure the "Preview Trade" button is disabled whilst manually editing the address

Screenshot 2024-02-06 at 9 19 36 am

✅ THORChain trades are great again

✅ Manual receive address works as expected when manually input

✅ Correct default (synced) address used as default

Copy link
Contributor

@0xApotheosis 0xApotheosis left a comment

Choose a reason for hiding this comment

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

Sorry gomes, that last commit made it much worse - I was able to get into a super stuck state where the "Preview Trade" button was never enabled.
Maybe we just revert and merge as-is.

Screenshot 2024-02-06 at 10 04 23 am Screenshot 2024-02-06 at 10 03 56 am

Copy link
Contributor

@0xApotheosis 0xApotheosis left a comment

Choose a reason for hiding this comment

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

Re-stamp after revert.

Base automatically changed from fix_synchronize_accountids_mount to develop February 5, 2024 23:13
@0xApotheosis 0xApotheosis merged commit ef60ea7 into develop Feb 5, 2024
4 checks passed
@0xApotheosis 0xApotheosis deleted the feat_manual_receive_address_p2 branch February 5, 2024 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants