-
-
Notifications
You must be signed in to change notification settings - Fork 12
Fix/transaction query #51
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 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
97de3ac
fix: transform transaction query objects before making request
martiliones b30cea5
chore: bump a version
martiliones 508e9fb
fix(typescript): represent transaction id as a string (#52)
martiliones dcce71f
fix: remove preinstall npm script (#53)
martiliones 74f016c
fix: typescript warning
martiliones e864248
chore: git bug
martiliones 1e0c3ee
Merge branch 'dev' into fix/transaction-query
martiliones 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import {transformTransactionQuery} from '../utils'; | ||
|
|
||
| describe('transformTransactionQuery', () => { | ||
| it('should transform `or` and `and` object properties', () => { | ||
| const transformed = transformTransactionQuery({ | ||
| or: { | ||
| maxAmount: 50000000, | ||
| senderPublicKey: | ||
| '801846655523f5e21f2d454b2f98f70aaf5d3887c806463100a1764a4e7c1457', | ||
| senderPublicKeys: [ | ||
| '801846655523f5e21f2d454b2f98f70aaf5d3887c806463100a1764a4e7c1457', | ||
| '4ef885053c630041f57493343d7f6023107c5dc8b8148147e732c93', | ||
| ], | ||
| }, | ||
| and: { | ||
| blockId: '7917597195203393333', | ||
| fromHeight: 10336065, | ||
| toHeight: 11, | ||
| minAmount: 1000000000000001, | ||
| senderId: 'U15423595369615486571', | ||
| senderIds: ['U18132012621449491414', 'U15881344309699504778'], | ||
| recipientId: 'U15423595369615486571', | ||
| recipientIds: ['U18132012621449491414', 'U15881344309699504778'], | ||
| recipientPublicKey: | ||
| '801846655523f5e21f2d454b2f98f70aaf5d3887c806463100a1764a4e7c1457', | ||
| recipientPublicKeys: [ | ||
| '801846655523f5e21f2d454b2f98f70aaf5d3887c806463100a1764a4e7c1457', | ||
| '4ef885053c630041f57493343d7f6023107c5dc8b8148147e732c93', | ||
| ], | ||
| inId: 'U100739400829575109', | ||
| type: 2, | ||
| types: [9, 0], | ||
| key: 'eth:address', | ||
| keyIds: ['eth:address', 'doge:address', 'dash:address'], | ||
| }, | ||
| }); | ||
|
|
||
| expect(transformed).toStrictEqual({ | ||
| 'or:maxAmount': 50000000, | ||
| 'or:senderPublicKey': | ||
| '801846655523f5e21f2d454b2f98f70aaf5d3887c806463100a1764a4e7c1457', | ||
| 'or:senderPublicKeys': [ | ||
| '801846655523f5e21f2d454b2f98f70aaf5d3887c806463100a1764a4e7c1457', | ||
| '4ef885053c630041f57493343d7f6023107c5dc8b8148147e732c93', | ||
| ], | ||
| 'and:blockId': '7917597195203393333', | ||
| 'and:fromHeight': 10336065, | ||
| 'and:toHeight': 11, | ||
| 'and:minAmount': 1000000000000001, | ||
| 'and:senderId': 'U15423595369615486571', | ||
| 'and:senderIds': ['U18132012621449491414', 'U15881344309699504778'], | ||
| 'and:recipientId': 'U15423595369615486571', | ||
| 'and:recipientIds': ['U18132012621449491414', 'U15881344309699504778'], | ||
| 'and:recipientPublicKey': | ||
| '801846655523f5e21f2d454b2f98f70aaf5d3887c806463100a1764a4e7c1457', | ||
| 'and:recipientPublicKeys': [ | ||
| '801846655523f5e21f2d454b2f98f70aaf5d3887c806463100a1764a4e7c1457', | ||
| '4ef885053c630041f57493343d7f6023107c5dc8b8148147e732c93', | ||
| ], | ||
| 'and:inId': 'U100739400829575109', | ||
| 'and:type': 2, | ||
| 'and:types': [9, 0], | ||
| 'and:key': 'eth:address', | ||
| 'and:keyIds': ['eth:address', 'doge:address', 'dash:address'], | ||
| }); | ||
| }); | ||
|
|
||
| it('should NOT transform object properties other than `or` and `and`', () => { | ||
| const transformed = transformTransactionQuery({ | ||
| minAmount: 5000, | ||
| senderId: 'U15423595369615486571', | ||
| senderIds: ['U18132012621449491414', 'U15881344309699504778'], | ||
| and: { | ||
| maxAmount: 6000, | ||
| }, | ||
| or: { | ||
| recipientIds: ['U18132012621449491414', 'U15881344309699504778'], | ||
| }, | ||
| }); | ||
|
|
||
| expect(transformed).toStrictEqual({ | ||
| minAmount: 5000, | ||
| senderId: 'U15423595369615486571', | ||
| senderIds: ['U18132012621449491414', 'U15881344309699504778'], | ||
| 'and:maxAmount': 6000, | ||
| 'or:recipientIds': ['U18132012621449491414', 'U15881344309699504778'], | ||
| }); | ||
| }); | ||
| }); |
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,42 @@ | ||
| import {hasOwnProperty} from '../helpers/utils'; | ||
| import {TransactionQuery} from '.'; | ||
|
|
||
| export type VoteDirection = '+' | '-'; | ||
|
|
||
| export const parseVote = (vote: string): [string, VoteDirection] => { | ||
| const name = vote.slice(1); | ||
| const direction = vote.charAt(0); | ||
|
|
||
| return [name, direction as VoteDirection]; | ||
| }; | ||
|
|
||
| export const transformTransactionQuery = <T extends object>( | ||
| obj?: TransactionQuery<T> | ||
| ) => { | ||
| if (!obj) { | ||
| return {}; | ||
| } | ||
|
|
||
| const transformed: Record<string, unknown> = { | ||
| ...obj, | ||
| }; | ||
|
|
||
| for (const topLevelProp in obj) { | ||
| if (hasOwnProperty(obj, topLevelProp)) { | ||
| if (topLevelProp === 'or' || topLevelProp === 'and') { | ||
| const subProps = obj[topLevelProp]; | ||
|
|
||
| for (const subProp in subProps) { | ||
| if (hasOwnProperty(subProps, subProp)) { | ||
| const newKey = `${topLevelProp}:${subProp}`; | ||
| transformed[newKey] = subProps[subProp]; | ||
| } | ||
| } | ||
|
|
||
| delete transformed[topLevelProp]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return transformed; | ||
| }; |
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
| export const hasOwnProperty = <T extends object, K extends PropertyKey>( | ||
| obj: T, | ||
| prop: K | ||
| ): obj is T & Record<K, unknown> => { | ||
| return Object.prototype.hasOwnProperty.call(obj, prop); | ||
| }; |
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.