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

Prevent users from selecting same asset in/out for a swap #861

Merged

Conversation

jessepinho
Copy link
Contributor

@jessepinho jessepinho commented Mar 30, 2024

Per #533, we want to prevent users from attempting a swap in which both the input and output asset types are the same.

This PR does that at two levels: in the extension's authorize RPC method, and in the UI. This ensures that the extension will prevent such swaps even if executed by a frontend other than minifront.

First, I disabled my changes to the UI so that I could still attempt a swap with the same asset in and out. Here's the error the extension gives:
image

Of course, no one on minfront will see this error, since we're now preventing the user from selecting the same asset in/out:

Screen.Recording.2024-03-30.at.3.54.27.PM.mov

Also in this PR, I added sorting to the asset in/out selectors, since the asset in selector was picking its default asset based on which balance happened to load first, and the asset out selector was using the sorting in the registry.

Closes #533

@jessepinho jessepinho changed the base branch from main to jessepinho/bsod-in-swaps-web-424 March 30, 2024 22:17
@jessepinho jessepinho force-pushed the jessepinho/asset-in-out-web-533 branch from 2a1d651 to 57b2837 Compare March 30, 2024 22:37
@jessepinho jessepinho force-pushed the jessepinho/asset-in-out-web-533 branch from 886aae1 to 8c997ee Compare March 30, 2024 22:51
@jessepinho jessepinho changed the title WIP: Should not be able to select same asset in/out Prevent users from selecting same asset in/out for a swap Mar 30, 2024
@jessepinho jessepinho marked this pull request as ready for review March 30, 2024 22:56
@jessepinho jessepinho marked this pull request as draft March 30, 2024 22:57
@jessepinho jessepinho marked this pull request as ready for review March 30, 2024 23:01
@jessepinho jessepinho requested review from grod220, Valentine1898, TalDerei and turbocrime and removed request for grod220 March 30, 2024 23:01
@jessepinho jessepinho requested a review from TalDerei April 1, 2024 16:45
@Valentine1898 Valentine1898 self-requested a review April 1, 2024 19:45
…ction-planner (#869)

* Move transaction validity assertions out of authorize and into transaction-planner

* Move security assertion back to authorize
@jessepinho jessepinho merged commit 64ecefb into jessepinho/bsod-in-swaps-web-424 Apr 2, 2024
6 checks passed
@jessepinho jessepinho deleted the jessepinho/asset-in-out-web-533 branch April 2, 2024 17:57
jessepinho added a commit that referenced this pull request Apr 2, 2024
* Sort assets

* Add filtering logic to AssetOutSelector; automatically switch assets if the selected one is filtered out

* Assert that trading pair is of different assets

* Sort by balance descending, rather than alphabetically

* Move transaction validity assertions out of authorize and into transaction-planner (#869)

* Move transaction validity assertions out of authorize and into transaction-planner

* Move security assertion back to authorize
jessepinho added a commit that referenced this pull request Apr 2, 2024
* Sort assets

* Add filtering logic to AssetOutSelector; automatically switch assets if the selected one is filtered out

* Assert that trading pair is of different assets

* Sort by balance descending, rather than alphabetically

* Move transaction validity assertions out of authorize and into transaction-planner (#869)

* Move transaction validity assertions out of authorize and into transaction-planner

* Move security assertion back to authorize
jessepinho added a commit that referenced this pull request Apr 2, 2024
* Add BSOD to TXP

* Start showing outputs

* Clean up code a little; change fn name

* Add some new helpers for swaps

* Add getters

* Make components for both one-way and two-way swaps

* Create more getters

* Extract a ValueWithAddress component

* Tighten up syntax

* Install dep in UI package

* More getters

* Clean up the Swap view

* Use <ActionDetails /> for fee and swap claim

* Simplify TransactionIdComponent; prettify swap claim view

* Add comment

* Move unfilled lower

* Fix test

* Fix linter complaint

* Include metadata in SwapView

* Create more getters

* Generate zero-value views on the fly; handle those in OneWaySwap

* Remove log

* Fix case of missing outputs

* Handle outputs with no amounts

* Tweak design when there are multiple claimed amounts

* Fix logic

* Prevent users from selecting same asset in/out for a swap (#861)

* Sort assets

* Add filtering logic to AssetOutSelector; automatically switch assets if the selected one is filtered out

* Assert that trading pair is of different assets

* Sort by balance descending, rather than alphabetically

* Move transaction validity assertions out of authorize and into transaction-planner (#869)

* Move transaction validity assertions out of authorize and into transaction-planner

* Move security assertion back to authorize

* Refactor per Gabe's suggestions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants