Skip to content

Commit

Permalink
Pull out variables for prev input / output native values for code rea…
Browse files Browse the repository at this point in the history
…dability
  • Loading branch information
jinchung committed Jul 10, 2024
1 parent ed69c45 commit 4db4e06
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/__swaps__/screens/Swap/hooks/useSwapInputsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,13 @@ export function useSwapInputsController({
const inputNativePrice = internalSelectedInputAsset.value?.nativePrice || internalSelectedInputAsset.value?.price?.value || 0;
const outputNativePrice = internalSelectedOutputAsset.value?.nativePrice || internalSelectedOutputAsset.value?.price?.value || 0;

const prevInputNativeValue = inputValues.value.inputNativeValue;
const prevOutputAmount = inputValues.value.outputAmount;
const newInputAmount = inputNativePrice > 0 ? divWorklet(prevInputNativeValue, inputNativePrice) : prevOutputAmount;

const inputAmount = Number(
valueBasedDecimalFormatter({
amount:
inputNativePrice > 0 ? divWorklet(inputValues.value.inputNativeValue, inputNativePrice) : inputValues.value.outputAmount,
amount: newInputAmount,
nativePrice: inputNativePrice,
roundingMode: 'up',
precisionAdjustment: -1,
Expand All @@ -846,13 +849,16 @@ export function useSwapInputsController({
})
);

const prevOutputNativeValue = inputValues.value.outputNativeValue;
const prevInputAmount = inputValues.value.inputAmount;
const newOutputAmount = outputNativePrice > 0 ? divWorklet(prevOutputNativeValue, outputNativePrice) : prevInputAmount;

inputValues.modify(values => {
return {
...values,
inputAmount,
inputNativeValue: inputValues.value.inputNativeValue,
outputAmount:
outputNativePrice > 0 ? divWorklet(inputValues.value.outputNativeValue, outputNativePrice) : inputValues.value.inputAmount,
outputAmount: newOutputAmount,
outputNativeValue: inputValues.value.outputNativeValue,
};
});
Expand Down

0 comments on commit 4db4e06

Please sign in to comment.