-
Notifications
You must be signed in to change notification settings - Fork 75
Show the transaction id on an expanded wallet activity #3509
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
Merged
Merged
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { getTransactionExplorerUrl, resolveTrxId } from './transactionExplorer'; | ||
|
|
||
| describe('resolveTrxId', () => { | ||
| it('accepts a broadcast transaction id', () => { | ||
| expect(resolveTrxId('aa82751091f8eaf6977f9a634e9eff6c4ee4208d')).toBe( | ||
| 'aa82751091f8eaf6977f9a634e9eff6c4ee4208d', | ||
| ); | ||
| }); | ||
|
|
||
| // A virtual operation is emitted by the chain rather than broadcast, so | ||
| // get_account_history gives it a zeroed id. author_reward, curation_reward and | ||
| // fill_order are the common ones and they are the majority of rows on some tabs. | ||
| it('rejects the zeroed id a virtual operation carries', () => { | ||
| expect(resolveTrxId('0000000000000000000000000000000000000000')).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('rejects a missing id', () => { | ||
| expect(resolveTrxId(undefined)).toBeUndefined(); | ||
| expect(resolveTrxId(null)).toBeUndefined(); | ||
| expect(resolveTrxId('')).toBeUndefined(); | ||
| }); | ||
|
|
||
| // Hive Engine suffixes the operation's index within the transaction. | ||
| it('strips the Hive Engine operation index', () => { | ||
| expect(resolveTrxId('98c14ebb580b350d6f1538c2810be987cb0003db-0')).toBe( | ||
| '98c14ebb580b350d6f1538c2810be987cb0003db', | ||
| ); | ||
| expect(resolveTrxId('7f333bb6e0e3dc8173ea78a857134508db70955b-9')).toBe( | ||
| '7f333bb6e0e3dc8173ea78a857134508db70955b', | ||
| ); | ||
| }); | ||
|
|
||
| // A contract-generated Hive Engine row is `<block>-<index>` with no Hive transaction | ||
| // behind it at all. 184 of 500 rows on the account this was written against. | ||
| it('rejects a Hive Engine row with no Hive transaction', () => { | ||
| expect(resolveTrxId('109092570-0')).toBeUndefined(); | ||
| expect(resolveTrxId('109087215-4')).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('rejects anything that is not a transaction id', () => { | ||
| expect(resolveTrxId('not-a-transaction')).toBeUndefined(); | ||
| expect(resolveTrxId('aa82751091')).toBeUndefined(); | ||
| expect(resolveTrxId(`${'a'.repeat(41)}`)).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('normalises case and surrounding whitespace', () => { | ||
| expect(resolveTrxId(' AA82751091F8EAF6977F9A634E9EFF6C4EE4208D ')).toBe( | ||
| 'aa82751091f8eaf6977f9a634e9eff6c4ee4208d', | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getTransactionExplorerUrl', () => { | ||
| it('builds the explorer link', () => { | ||
| expect(getTransactionExplorerUrl('aa82751091f8eaf6977f9a634e9eff6c4ee4208d')).toBe( | ||
| 'https://hivexplorer.com/tx/aa82751091f8eaf6977f9a634e9eff6c4ee4208d', | ||
| ); | ||
| }); | ||
|
|
||
| it('offers no link where there is no transaction', () => { | ||
| expect(getTransactionExplorerUrl('0000000000000000000000000000000000000000')).toBeUndefined(); | ||
|
Comment on lines
+60
to
+61
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. 2. Lines exceed 100 characters New test lines exceed the 100 character limit, reducing readability and violating the line-length policy. Wrap these expectations across multiple lines to keep each non-comment line within 100 characters. Agent Prompt
|
||
| expect(getTransactionExplorerUrl('109092570-0')).toBeUndefined(); | ||
| expect(getTransactionExplorerUrl(undefined)).toBeUndefined(); | ||
| }); | ||
| }); | ||
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,46 @@ | ||
| /** | ||
| * Turning a wallet activity into a link someone else can verify. | ||
| * | ||
| * Not every row has a transaction behind it, and the ones that do not are the majority on | ||
| * some tabs, so the caller has to be able to tell them apart rather than build a link that | ||
| * resolves to nothing: | ||
| * | ||
| * - A virtual operation (`author_reward`, `curation_reward`, `fill_order`, ...) is emitted | ||
| * by the chain instead of broadcast, and `condenser_api.get_account_history` gives it a | ||
| * `trx_id` of 40 zeroes. | ||
| * - A Hive Engine row carries `<hive-trx-id>-<op index>` when it rode in on a custom_json, | ||
| * and `<block>-<index>` when a contract generated it with no Hive transaction at all. | ||
| * Both shapes appear in the same account's history (184 of 500 rows on the account this | ||
| * was written against). | ||
| */ | ||
|
|
||
| const EXPLORER_BASE = 'https://hivexplorer.com'; | ||
|
|
||
| /** A Hive transaction id is 40 hex characters. All zeroes is the "no transaction" marker. */ | ||
| const TRX_ID_PATTERN = /^[0-9a-f]{40}$/i; | ||
|
|
||
| /** Hive Engine appends the operation's index within the transaction. */ | ||
| const OP_INDEX_SUFFIX = /-\d+$/; | ||
|
|
||
| /** | ||
| * The Hive transaction id behind an activity, or undefined when it has none. | ||
| */ | ||
| export const resolveTrxId = (rawId?: string | null): string | undefined => { | ||
| const candidate = String(rawId ?? '') | ||
| .trim() | ||
| .replace(OP_INDEX_SUFFIX, ''); | ||
|
|
||
| if (!TRX_ID_PATTERN.test(candidate) || /^0+$/.test(candidate)) { | ||
| return undefined; | ||
| } | ||
|
|
||
| return candidate.toLowerCase(); | ||
| }; | ||
|
|
||
| /** | ||
| * The explorer link for an already-resolved transaction id. | ||
| */ | ||
| export const getTransactionExplorerUrl = (trxId?: string | null): string | undefined => { | ||
| const resolved = resolveTrxId(trxId); | ||
| return resolved ? `${EXPLORER_BASE}/tx/${resolved}` : undefined; | ||
| }; |
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.
Uh oh!
There was an error while loading. Please reload this page.