diff --git a/.changeset/rude-fireants-pump.md b/.changeset/rude-fireants-pump.md new file mode 100644 index 0000000000..ca4f081c5a --- /dev/null +++ b/.changeset/rude-fireants-pump.md @@ -0,0 +1,5 @@ +--- +'minifront': minor +--- + +automatically perform swap estimation on user input diff --git a/apps/minifront/src/components/swap/swap-form/simulate-swap-result/traces/index.tsx b/apps/minifront/src/components/swap/swap-form/simulate-swap-result/traces/index.tsx index bae3cac392..984448b47b 100644 --- a/apps/minifront/src/components/swap/swap-form/simulate-swap-result/traces/index.tsx +++ b/apps/minifront/src/components/swap/swap-form/simulate-swap-result/traces/index.tsx @@ -2,7 +2,7 @@ import { SwapExecution_Trace } from '@penumbra-zone/protobuf/penumbra/core/compo import { Trace } from './trace'; import { Metadata, ValueView } from '@penumbra-zone/protobuf/penumbra/core/asset/v1/asset_pb'; import { ValueViewComponent } from '@penumbra-zone/ui-deprecated/components/ui/value'; -import { ArrowDown, ArrowUp } from 'lucide-react'; +import { ArrowRight } from 'lucide-react'; export const Traces = ({ traces, @@ -29,17 +29,14 @@ export const Traces = ({
-
-
- - -
-
- - +
+ +
+
+
-
+
{traces.map((trace, index) => (
; }) => { return ( -
+
{trace.value.map((value, index) => ( -
+
{index === 0 && } diff --git a/apps/minifront/src/components/swap/swap-form/simulate-swap.tsx b/apps/minifront/src/components/swap/swap-form/simulate-swap.tsx index ef44742e22..cc26c46433 100644 --- a/apps/minifront/src/components/swap/swap-form/simulate-swap.tsx +++ b/apps/minifront/src/components/swap/swap-form/simulate-swap.tsx @@ -3,16 +3,33 @@ import { SimulateSwapResult } from './simulate-swap-result'; import { AllSlices } from '../../../state'; import { useStoreShallow } from '../../../utils/use-store-shallow'; import { EstimateButton } from './estimate-button'; +import { useEffect } from 'react'; const simulateSwapSelector = (state: AllSlices) => ({ simulateSwap: state.swap.instantSwap.simulateSwap, + resetSimulateSwap: state.swap.instantSwap.reset, disabled: state.swap.txInProgress || !state.swap.amount || state.swap.instantSwap.simulateSwapLoading, result: state.swap.instantSwap.simulateSwapResult, + amount: state.swap.amount, }); +// Automatically trigger swap simulation on user input export const SimulateSwap = ({ layoutId }: { layoutId: string }) => { - const { simulateSwap, disabled, result } = useStoreShallow(simulateSwapSelector); + const { simulateSwap, resetSimulateSwap, disabled, result, amount } = + useStoreShallow(simulateSwapSelector); + + useEffect(() => { + if (!disabled && amount && parseFloat(amount) > 0) { + // Prevents re-triggering the swap simulation if it's already computed + if (!result) { + void simulateSwap(); + } + } else if (result) { + // Reset simulation + resetSimulateSwap(); + } + }, [simulateSwap, resetSimulateSwap, disabled, result, amount]); return (