-
Notifications
You must be signed in to change notification settings - Fork 5
dropdown asset selection #35
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
This file contains hidden or 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,82 @@ | ||
| # Token URL System | ||
|
|
||
| ## Overview | ||
|
|
||
| The application now uses token symbols in URLs instead of asset IDs, making URLs more user-friendly and readable. For tokens with duplicate symbols (like different USDC types), unique identifiers are generated. | ||
|
|
||
| ## URL Format | ||
|
|
||
| ### Before (using asset IDs) | ||
| ``` | ||
| https://localhost:3000/?from=22222052&to=12345678 | ||
| ``` | ||
|
|
||
| ### After (using token symbols) | ||
| ``` | ||
| https://localhost:3000/?from=DOT&to=USDC | ||
| ``` | ||
|
|
||
| For tokens with duplicate symbols: | ||
| ``` | ||
| https://localhost:3000/?from=USDC-0002&to=USDC-0003 | ||
| ``` | ||
|
|
||
| ## How It Works | ||
|
|
||
| ### 1. Token Identifier Generation | ||
|
|
||
| - **Unique symbols**: Use the symbol directly (e.g., `DOT`, `USDT`) | ||
| - **Duplicate symbols**: Append asset ID suffix (e.g., `USDC-0002`, `USDC-0003`) | ||
|
|
||
| ### 2. Internal Mapping | ||
|
|
||
| The system maintains two mappings: | ||
| - `tokenIdentifierMap`: Maps token identifiers to asset IDs | ||
| - `assetIdToIdentifierMap`: Maps asset IDs to token identifiers | ||
|
|
||
| ### 3. URL Parameter Handling | ||
|
|
||
| - URLs use token identifiers (symbols) | ||
| - Internal operations use asset IDs | ||
| - Automatic conversion between the two formats | ||
|
|
||
| ## Key Functions | ||
|
|
||
| ### `createTokenIdentifierMap(assets)` | ||
| Creates a mapping from token identifiers to asset IDs, handling duplicate symbols. | ||
|
|
||
| ### `findAssetByIdentifier(assets, identifier)` | ||
| Finds an asset by its identifier (symbol or symbol-hash). | ||
|
|
||
| ### `getAssetIdentifier(assets, assetId)` | ||
| Gets the identifier for a given asset ID. | ||
|
|
||
| ## Backward Compatibility | ||
|
|
||
| The system maintains backward compatibility by: | ||
| - Supporting both symbol and asset ID lookups | ||
| - Case-insensitive symbol matching | ||
| - Graceful fallback to symbol matching if identifier lookup fails | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```typescript | ||
| // URL shows: https://localhost:3000/?from=DOT&to=USDC-0002 | ||
| // Internal mapping: DOT -> asset_id_1, USDC-0002 -> asset_id_2 | ||
|
|
||
| // When user selects a token | ||
| setInputToken(token); // token.id = "asset_id_1" | ||
| // URL updates to: ?from=DOT | ||
|
|
||
| // When URL changes | ||
| // fromTokenIdentifier = "DOT" | ||
| // findAssetByIdentifier() returns asset with id "asset_id_1" | ||
| ``` | ||
|
|
||
| ## Benefits | ||
|
|
||
| 1. **User-friendly URLs**: Easy to read and understand | ||
| 2. **Shareable links**: Users can easily share specific token pairs | ||
| 3. **SEO friendly**: URLs contain meaningful token names | ||
| 4. **Backward compatible**: Old URLs still work | ||
| 5. **Handles duplicates**: Unique identifiers for tokens with same symbol |
This file contains hidden or 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
This file contains hidden or 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.
logic: the condition
!fromTokenIdentifier || !toTokenIdentifierwill trigger default selection even when empty strings are set in URL params, which may override user's explicit empty selections