-
Notifications
You must be signed in to change notification settings - Fork 117
[New TX Flow] Add backward compatibility for old saved transactions and urls; add submitStepContent test #2015
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
80e5986
add submitStepContent.test.ts
jeesunikim e2fc16a
[New Tx Flow] Migrate saved transactions to use flow store
jeesunikim a29f893
[New Tx Flow] Skip URL param tests pending backward compatibility mig…
jeesunikim 54d25cc
[New Tx Flow] Add backward compatibility for legacy URL params
jeesunikim 2984a95
fix re-running validation on classic when operation gets updated
jeesunikim 0f4822a
[New Tx Flow] Show deprecation warning for legacy URL format
jeesunikim 99dee7e
fix tests
jeesunikim 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { useEffect, useState } from "react"; | ||
|
|
||
| import { useStore } from "@/store/useStore"; | ||
| import { useBuildFlowStore } from "@/store/createTransactionFlowStore"; | ||
|
|
||
| /** | ||
| * One-time migration hook that bridges legacy querystring-persisted transaction | ||
| * params into the sessionStorage-based flow store. | ||
| * | ||
| * Old bookmarked URLs encode build params in the querystring via | ||
| * zustand-querystring. The build page now reads from the flow store | ||
| * (sessionStorage). This hook detects legacy params and seeds the flow store | ||
| * so old URLs continue to work. | ||
| * | ||
| * @returns `isLegacyUrl` — true when data was migrated from a legacy URL. | ||
| */ | ||
| export const useLegacyUrlMigration = () => { | ||
| const [isLegacyUrl, setIsLegacyUrl] = useState(false); | ||
| const { transaction } = useStore(); | ||
|
|
||
| useEffect(() => { | ||
| const legacyParams = transaction.build.params; | ||
| const legacyClassicOps = transaction.build.classic.operations; | ||
| const legacySorobanOp = transaction.build.soroban.operation; | ||
|
|
||
| // Check if the legacy store has non-default params from a URL | ||
| const hasLegacyParams = Boolean(legacyParams.source_account); | ||
| const hasLegacyClassicOps = | ||
| legacyClassicOps.length > 0 && | ||
| legacyClassicOps.some((op) => Boolean(op.operation_type)); | ||
| const hasLegacySorobanOp = Boolean(legacySorobanOp.operation_type); | ||
|
|
||
| if (!hasLegacyParams && !hasLegacyClassicOps && !hasLegacySorobanOp) { | ||
| return; | ||
| } | ||
|
|
||
| const flowStore = useBuildFlowStore.getState(); | ||
|
|
||
| let didMigrate = false; | ||
|
|
||
| // Seed params if the flow store doesn't have them yet | ||
| if (hasLegacyParams && !flowStore.build.params.source_account) { | ||
| flowStore.setBuildParams(legacyParams); | ||
| didMigrate = true; | ||
| } | ||
|
|
||
| // Seed operations if the flow store doesn't have them yet | ||
| const flowHasOps = flowStore.build.classic.operations.some((op) => | ||
| Boolean(op.operation_type), | ||
| ); | ||
| const flowHasSorobanOp = Boolean( | ||
| flowStore.build.soroban.operation.operation_type, | ||
| ); | ||
|
|
||
| if (hasLegacySorobanOp && !flowHasSorobanOp) { | ||
| flowStore.setBuildSorobanOperation(legacySorobanOp); | ||
|
|
||
| if (transaction.build.soroban.xdr) { | ||
| flowStore.setBuildSorobanXdr(transaction.build.soroban.xdr); | ||
| } | ||
| didMigrate = true; | ||
| } else if (hasLegacyClassicOps && !flowHasOps) { | ||
| flowStore.setBuildClassicOperations(legacyClassicOps); | ||
|
|
||
| if (transaction.build.classic.xdr) { | ||
| flowStore.setBuildClassicXdr(transaction.build.classic.xdr); | ||
| } | ||
| didMigrate = true; | ||
| } | ||
|
|
||
| if (didMigrate) { | ||
| setIsLegacyUrl(true); | ||
| } | ||
| }, [transaction]); | ||
|
|
||
| const dismissLegacyAlert = () => setIsLegacyUrl(false); | ||
|
|
||
| return { isLegacyUrl, dismissLegacyAlert }; | ||
| }; |
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.
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.