-
Notifications
You must be signed in to change notification settings - Fork 528
fix: select gas account for private send when megafuel is suppressed (OK-59993) #12916
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 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7e59d91
fix: select gas account for private send when megafuel is suppressed
weatherstar bd34e7b
Merge branch 'x' into fix/ok-59993-private-send-payer-selection
weatherstar 719c6ab
fix: address PR review feedback
weatherstar c535656
Merge branch 'x' into fix/ok-59993-private-send-payer-selection
weatherstar f6b69f4
fix: gate effectiveFeePayer by gas account quote eligibility
weatherstar 380cd47
Merge branch 'x' into fix/ok-59993-private-send-payer-selection
weatherstar 32a9b4d
Merge branch 'x' into fix/ok-59993-private-send-payer-selection
weatherstar 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
243 changes: 243 additions & 0 deletions
243
packages/kit/src/views/SignatureConfirm/utils/gasAccountPayerSelection.test.ts
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,243 @@ | ||
| import { resolveSponsorPayerState } from './gasAccountPayerSelection'; | ||
|
|
||
| const baseParams = { | ||
| serverPayer: 'user' as const, | ||
| megafuelSponsorable: false, | ||
| gasAccountQuoteEligible: false, | ||
| isCustomRpcEnabled: false, | ||
| sponsorDisabledForBatch: false, | ||
| megafuelDisabledForPrivateSend: false, | ||
| gasAccountDisabledByScenario: false, | ||
| gasAccountTemporarilyDisabled: false, | ||
| }; | ||
|
|
||
| describe('resolveSponsorPayerState', () => { | ||
| describe('default flow (no suppression)', () => { | ||
| it('keeps user payer when the server does not sponsor', () => { | ||
| expect(resolveSponsorPayerState(baseParams)).toEqual({ | ||
| effectiveFeePayer: 'user', | ||
| selectedPayer: 'user', | ||
| }); | ||
| }); | ||
|
|
||
| it('selects gas account when the server prefers it and a quote is eligible', () => { | ||
| expect( | ||
| resolveSponsorPayerState({ | ||
| ...baseParams, | ||
| serverPayer: 'gasAccount', | ||
| gasAccountQuoteEligible: true, | ||
| }), | ||
| ).toEqual({ | ||
| effectiveFeePayer: 'gasAccount', | ||
| selectedPayer: 'gasAccount', | ||
| }); | ||
| }); | ||
|
|
||
| it('keeps user submit when megafuel sponsors even if a gas account quote exists', () => { | ||
| expect( | ||
| resolveSponsorPayerState({ | ||
| ...baseParams, | ||
| serverPayer: 'megafuel', | ||
| megafuelSponsorable: true, | ||
| gasAccountQuoteEligible: true, | ||
| }), | ||
| ).toEqual({ | ||
| effectiveFeePayer: 'megafuel', | ||
| selectedPayer: 'user', | ||
| }); | ||
| }); | ||
|
|
||
| it('lets megafuel win submit wiring when sponsorable alongside a gasAccount payer', () => { | ||
| expect( | ||
| resolveSponsorPayerState({ | ||
| ...baseParams, | ||
| serverPayer: 'gasAccount', | ||
| megafuelSponsorable: true, | ||
| gasAccountQuoteEligible: true, | ||
| }), | ||
| ).toEqual({ | ||
| effectiveFeePayer: 'gasAccount', | ||
| selectedPayer: 'user', | ||
| }); | ||
| }); | ||
|
|
||
| it('does not select gas account without an eligible quote', () => { | ||
| expect( | ||
| resolveSponsorPayerState({ | ||
| ...baseParams, | ||
| serverPayer: 'gasAccount', | ||
| gasAccountQuoteEligible: false, | ||
| }), | ||
| ).toEqual({ | ||
| effectiveFeePayer: 'gasAccount', | ||
| selectedPayer: 'user', | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('global suppressions', () => { | ||
| it('forces user for both payers when a custom RPC is enabled', () => { | ||
| expect( | ||
| resolveSponsorPayerState({ | ||
| ...baseParams, | ||
| serverPayer: 'gasAccount', | ||
| gasAccountQuoteEligible: true, | ||
| isCustomRpcEnabled: true, | ||
| }), | ||
| ).toEqual({ | ||
| effectiveFeePayer: 'user', | ||
| selectedPayer: 'user', | ||
| }); | ||
| }); | ||
|
|
||
| it('forces user for both payers on batch transactions', () => { | ||
| expect( | ||
| resolveSponsorPayerState({ | ||
| ...baseParams, | ||
| serverPayer: 'megafuel', | ||
| megafuelSponsorable: true, | ||
| gasAccountQuoteEligible: true, | ||
| sponsorDisabledForBatch: true, | ||
| }), | ||
| ).toEqual({ | ||
| effectiveFeePayer: 'user', | ||
| selectedPayer: 'user', | ||
| }); | ||
| }); | ||
|
|
||
| it('forces user when gas account is temporarily disabled after a fallback', () => { | ||
| expect( | ||
| resolveSponsorPayerState({ | ||
| ...baseParams, | ||
| serverPayer: 'gasAccount', | ||
| gasAccountQuoteEligible: true, | ||
| gasAccountTemporarilyDisabled: true, | ||
| }), | ||
| ).toEqual({ | ||
| effectiveFeePayer: 'user', | ||
| selectedPayer: 'user', | ||
| }); | ||
| }); | ||
|
|
||
| it('forces user when the frontend scenario disables gas account', () => { | ||
| expect( | ||
| resolveSponsorPayerState({ | ||
| ...baseParams, | ||
| serverPayer: 'gasAccount', | ||
| gasAccountQuoteEligible: true, | ||
| gasAccountDisabledByScenario: true, | ||
| }), | ||
| ).toEqual({ | ||
| effectiveFeePayer: 'user', | ||
| selectedPayer: 'user', | ||
| }); | ||
| }); | ||
|
|
||
| it('still surfaces megafuel display when only the gas account path is scenario-disabled', () => { | ||
| expect( | ||
| resolveSponsorPayerState({ | ||
| ...baseParams, | ||
| serverPayer: 'megafuel', | ||
| megafuelSponsorable: true, | ||
| gasAccountQuoteEligible: true, | ||
| gasAccountDisabledByScenario: true, | ||
| }), | ||
| ).toEqual({ | ||
| effectiveFeePayer: 'megafuel', | ||
| selectedPayer: 'user', | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('private send (megafuel suppressed)', () => { | ||
| it('falls back to the eligible gas account quote when the server prefers megafuel', () => { | ||
| expect( | ||
| resolveSponsorPayerState({ | ||
| ...baseParams, | ||
| serverPayer: 'megafuel', | ||
| megafuelSponsorable: true, | ||
| gasAccountQuoteEligible: true, | ||
| megafuelDisabledForPrivateSend: true, | ||
| }), | ||
| ).toEqual({ | ||
| effectiveFeePayer: 'gasAccount', | ||
| selectedPayer: 'gasAccount', | ||
| }); | ||
| }); | ||
|
|
||
| it('falls back to user when the server prefers megafuel and no quote is eligible', () => { | ||
| expect( | ||
| resolveSponsorPayerState({ | ||
| ...baseParams, | ||
| serverPayer: 'megafuel', | ||
| megafuelSponsorable: true, | ||
| gasAccountQuoteEligible: false, | ||
| megafuelDisabledForPrivateSend: true, | ||
| }), | ||
| ).toEqual({ | ||
| effectiveFeePayer: 'user', | ||
| selectedPayer: 'user', | ||
| }); | ||
| }); | ||
|
|
||
| it('selects gas account when the server prefers it even with megafuel sponsorable', () => { | ||
| expect( | ||
| resolveSponsorPayerState({ | ||
| ...baseParams, | ||
| serverPayer: 'gasAccount', | ||
| megafuelSponsorable: true, | ||
| gasAccountQuoteEligible: true, | ||
| megafuelDisabledForPrivateSend: true, | ||
| }), | ||
| ).toEqual({ | ||
| effectiveFeePayer: 'gasAccount', | ||
| selectedPayer: 'gasAccount', | ||
| }); | ||
| }); | ||
|
|
||
| it('keeps user payer when the server does not sponsor', () => { | ||
| expect( | ||
| resolveSponsorPayerState({ | ||
| ...baseParams, | ||
| serverPayer: 'user', | ||
| megafuelDisabledForPrivateSend: true, | ||
| }), | ||
| ).toEqual({ | ||
| effectiveFeePayer: 'user', | ||
| selectedPayer: 'user', | ||
| }); | ||
| }); | ||
|
|
||
| it('does not fall back to gas account when a custom RPC is enabled', () => { | ||
| expect( | ||
| resolveSponsorPayerState({ | ||
| ...baseParams, | ||
| serverPayer: 'megafuel', | ||
| megafuelSponsorable: true, | ||
| gasAccountQuoteEligible: true, | ||
| megafuelDisabledForPrivateSend: true, | ||
| isCustomRpcEnabled: true, | ||
| }), | ||
| ).toEqual({ | ||
| effectiveFeePayer: 'user', | ||
| selectedPayer: 'user', | ||
| }); | ||
| }); | ||
|
|
||
| it('does not fall back to gas account while it is temporarily disabled', () => { | ||
| expect( | ||
| resolveSponsorPayerState({ | ||
| ...baseParams, | ||
| serverPayer: 'megafuel', | ||
| megafuelSponsorable: true, | ||
| gasAccountQuoteEligible: true, | ||
| megafuelDisabledForPrivateSend: true, | ||
| gasAccountTemporarilyDisabled: true, | ||
| }), | ||
| ).toEqual({ | ||
| effectiveFeePayer: 'user', | ||
| selectedPayer: 'user', | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.