Skip to content

Commit

Permalink
Add getMaxSlippage
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcramer committed Sep 10, 2024
1 parent 428ecd3 commit 431fb76
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/swap/components/SwapProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ export function SwapProvider({
// Refreshes balances and inputs post-swap
const resetInputs = useResetInputs({ from, to });

const getMaxSlippage = useCallback(() => {
return lifeCycleStatus.statusName !== 'error'
? lifeCycleStatus.statusData.maxSlippage

Check failure on line 74 in src/swap/components/SwapProvider.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/swap/components/SwapProvider.test.tsx > SwapProvider > should emit onStatus when setLifeCycleStatus is called with transactionPending

TypeError: Cannot read properties of null (reading 'maxSlippage') ❯ src/swap/components/SwapProvider.tsx:74:36 ❯ src/swap/components/SwapProvider.tsx:127:25 ❯ commitHookEffectListMount node_modules/react-dom/cjs/react-dom.development.js:23189:26 ❯ commitPassiveMountOnFiber node_modules/react-dom/cjs/react-dom.development.js:24970:11 ❯ commitPassiveMountEffects_complete node_modules/react-dom/cjs/react-dom.development.js:24930:9 ❯ commitPassiveMountEffects_begin node_modules/react-dom/cjs/react-dom.development.js:24917:7 ❯ commitPassiveMountEffects node_modules/react-dom/cjs/react-dom.development.js:24905:3 ❯ flushPassiveEffectsImpl node_modules/react-dom/cjs/react-dom.development.js:27078:3 ❯ flushPassiveEffects node_modules/react-dom/cjs/react-dom.development.js:27023:14 ❯ commitRootImpl node_modules/react-dom/cjs/react-dom.development.js:26974:5
: experimental.maxSlippage || DEFAULT_MAX_SLIPPAGE;
}, [lifeCycleStatus, experimental.maxSlippage]);

// Component lifecycle emitters
useEffect(() => {
// Error
Expand Down Expand Up @@ -118,17 +124,18 @@ export function SwapProvider({
}, [hasHandledSuccess, lifeCycleStatus.statusName, resetInputs]);

useEffect(() => {
const maxSlippage = getMaxSlippage();
// Reset status to init after success has been handled
if (lifeCycleStatus.statusName === 'success' && hasHandledSuccess) {
setLifeCycleStatus({
statusName: 'init',
statusData: {
isMissingRequiredField: false,
maxSlippage: initialMaxSlippage,
maxSlippage,
},
});
}
}, [hasHandledSuccess, lifeCycleStatus.statusName, initialMaxSlippage]);
}, [hasHandledSuccess, lifeCycleStatus.statusName]);

const handleToggle = useCallback(() => {
from.setAmount(to.amount);
Expand Down Expand Up @@ -248,17 +255,14 @@ export function SwapProvider({
destination.setLoading(false);
}
},
[from, initialMaxSlippage, to, useAggregator],
[from, to, useAggregator],
);

const handleSubmit = useCallback(async () => {
if (!address || !from.token || !to.token || !from.amount) {
return;
}
const maxSlippage =
lifeCycleStatus.statusName !== 'error'
? lifeCycleStatus.statusData.maxSlippage
: DEFAULT_MAX_SLIPPAGE;
const maxSlippage = getMaxSlippage();
setLifeCycleStatus({
statusName: 'init',
statusData: {
Expand Down Expand Up @@ -316,7 +320,6 @@ export function SwapProvider({
from.amount,
from.token,
lifeCycleStatus,
initialMaxSlippage,
sendTransactionAsync,
to.token,
useAggregator,
Expand Down

0 comments on commit 431fb76

Please sign in to comment.