Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(synapse-interface): bridge gas handler (#2437)
* Initial gas data slice state * Async thunk fetchGasData * Add gas data reducers * useFetchGasDataOnInterval added to Bridge Listener * Explicitly declare fetching gas data in gwei * Calculate max bridgeable amount * On max balance factoring in gas cost * Add comment * Differentiate max balance vs max bridgeable balance * Add error toaster for when max balance less than bridge fee * refactor; calculateGasFeeInGwei() * Move to util * Fix lint error * Fetch gas when fromChainId on bridge card changes * Use exact token balance when calculate max bridgeable amount * Conditions for showing max button * showMaxOption to determine display * Disable max button if gas fees more than gas balance * Clean jsx * AvailableBalance component to track subscript detail in bridge origin input * Return raw and formatted gas cost in calculateGasCost * Update comments * Fix imports based on name cange * Use parsed * calculateMaxBridgeableGas * Clean * refactor: clean InputContainer * Replace onMaxBalance() with onMaxBridgeableBalance()` * Allow undefined object when destructuring * Display when token balance is trace balance * Typing * showGasReserved * Update avail balance text and color when gas cost greater than balance * Detect when input value is less than required estimated gas * onAvailableBalance applied * Make opacity greater when Max button disabled * Fix calculations for when gas input is enough to cover gas * Clean * Add hover tooltip for warning gas states * Use tooltip to describe gas status * Update tooltip text * Add buffer to calculate gas cost, use 1.5x * AvailableBalance component to replace label in AmountInput * Display trace balances in AvailableBalance * Fix naming * Add HoverTooltip to Available Balance * Add conditions for displaying gas error based on input * Use full parsed balance when making comparisons for gas checks * Show gas reserved in Available Balance * hasOnlyZeroes to return true if string contains only zeroes and periods * Display estimated gas cost in tool tip * Remove Available Balance elements from AmountInput, migrated to AvailableBalance * Display trace amount for input when displaying how much is reserved for gas * Fetch estimated gas limit based on real bridge quote using max gas balance * Fetching accurate gasLimit * Fix Trace balance * Set gasLimit to 0 if not valid bridge data avail * ... * Fix when gas covered msg appears * Available Balance * Clean available balance flow * useGasEstimator hook to encapsulate logic to clean InputContainer * Fix prop issue * Remove duplicate HoverTooltip * Move HoverTooltip to shared component folder * Update gas fetch for wagmi v2, up limit to 1.7 * Estimated gas bridge quote fetched on load * Update var naming * Improve Available Balance flow * Display estimated bridgeable balance on hover * Show gas estimate when estimated gas cost available * Do not show negative bridgable balance * Separate out bridge gas limit calculations into smaller functions * Wrap async functions with try catch * Implement updated gas estimation flow * Move gas estimate logic to useGasEstimator * Move async sdk fetch functions to useGasEstimator file * Remove unused vars * Shorten est gas cost * Improve code legibility in AvailableBalance * Assign conditions to vars to reduce clutter * Reset gas price data when fromChainId changes * Reset fetched gas limit when fromChainId changes * Clean * Fix old import * Fix max button placement * Add loading state for useGasEstimator * Remove available balance states for gas est * Remove unused props * Clean gas token detection in PortfolioTokenAsset * Simplify onMaxBalance() * Clean constants in InputContainer * Clean token detail destructuring * Include gas estimate when updating input from Portfolio token selection * Fire error toaster if gas fees exceed balance * Render error toaster when firing onMaxBalance callback instead of a side effect * Clean useGasEstimator * Ensure available balance does not show if wallet not connected, set default value if balances not loaded * Replicate onMax behavior in Portfolio * Use fetched gas * Improve error handling in gas estimator * ... * Remove tooltip on AvailableBalance * Remove balance prefill from Portfolio Token selection * Update available balance in input based on max bridgeable gas toke * Destructure estimateGasLimit callback from useGasEstimator to retrigger fetching gas estimate * Refetch gas ata in estimateGasLimit callback * Display total vs bridgeable balance on hover in Portfolio gas token when gas data available * Update balance shown on hover * Clean * Simplify useFetchGasDataOnInterval * Prevent unnecessary fetches, fix chain update old gas issue * Fetch estimated bridgeable max gas amount onClick token max input, fill input once amount fetched * Clean * onMaxBalance will use default balanceif fetched bridgeable balance estimate returns null * Show dust gas amounts on hover in Portfolio * Clean * Available balance including gas estimates moved to within Input to synchronize data * Move gasLimit to global store to share data between Bridge components * Display max bridgeable balance on hover in Portfolio, add onMaxBalance onClick Portfolio asset * Portfolio and Input available balance onClick behave the same * Fetch gas prices to provide most accurate gas cost * Remove hover on AvailableBalance * Fix Token Selector width * Remove onClick Portfolio Token Balance, allow Token selection from Portfolio only without Balance input update * Cursor default on Portfolio Token Balance * Show available/max buttons when bridge valid selections * Swap input to have available balance * Clean * Basic MaxButton onClick and hidden when loading gas data * Show MaxButton when input is not full balance or bridgeable balance * Implement Max button and placement in Bridge/Swap * Hide MaxButton until connected * Hide MaxButton conditions * Show Max when all input selections are made * Remove click states for AvailableBalance on Bridge/Swap * Style Input / Max * Max mobile size * Fe/format amount (#2598) * formatAmount util function, use rounded shortened values in Bridge/Swap Input * Update Bridge/Swap page with parsed / formatted balances * Clean imports * Clean imports * Swap Max spacing * Improve html element composition * Prevent layout shift in Swap UI
- Loading branch information