Skip to content
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

[wip] feat(synapse-interface): track bridge quoted tokens #3018

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ export const BridgeTransactionButton = ({
const stringifiedBridgeQuote = constructStringifiedBridgeSelections(
bridgeQuote.inputAmountForQuote,
bridgeQuote.originChainId,
bridgeQuote.destChainId
bridgeQuote.originTokenForQuote,
bridgeQuote.destChainId,
bridgeQuote.destTokenForQuote
)
const stringifiedBridgeState = constructStringifiedBridgeSelections(
debouncedFromValue,
fromChainId,
toChainId
fromToken,
toChainId,
toToken
)
Comment on lines 80 to 93
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider memoizing these stringified selections to avoid unnecessary recalculations on each render.


const bridgeStateMatchesQuote =
Expand Down Expand Up @@ -207,12 +211,16 @@ export const BridgeTransactionButton = ({
const constructStringifiedBridgeSelections = (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: This function might produce inconsistent results if the objects have different property orders. Consider using a more robust comparison method.

originAmount,
originChainId,
destinationChainId
originToken,
destChainId,
destToken
) => {
const state = {
originAmount,
originChainId,
destinationChainId,
originToken,
destChainId,
destToken,
}
return JSON.stringify(state)
}
4 changes: 4 additions & 0 deletions packages/synapse-interface/constants/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export const QUOTE_POLLING_INTERVAL = 10000

export const EMPTY_BRIDGE_QUOTE = {
inputAmountForQuote: '',
originTokenForQuote: null,
destTokenForQuote: null,
outputAmount: 0n,
outputAmountString: '',
routerAddress: '',
Expand All @@ -24,6 +26,8 @@ export const EMPTY_BRIDGE_QUOTE = {

export const EMPTY_BRIDGE_QUOTE_ZERO = {
inputAmountForQuote: '',
originTokenForQuote: null,
destTokenForQuote: null,
outputAmount: 0n,
outputAmountString: '0',
routerAddress: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ const StateManagedBridge = () => {
dispatch(
setBridgeQuote({
inputAmountForQuote: debouncedFromValue,
originTokenForQuote: fromToken,
destTokenForQuote: toToken,
outputAmount: toValueBigInt,
outputAmountString: commify(
formatBigIntToString(
Expand Down
2 changes: 2 additions & 0 deletions packages/synapse-interface/utils/types/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ type QuoteQuery = {

export type BridgeQuote = {
inputAmountForQuote: string
originTokenForQuote: Token
destTokenForQuote: Token
outputAmount: bigint
outputAmountString: string
routerAddress: string
Expand Down
Loading