Skip to content

Commit

Permalink
fix: separated default dest n/w logic from first render logic
Browse files Browse the repository at this point in the history
  • Loading branch information
salil-naik committed Mar 27, 2023
1 parent a0bf5db commit f7b92c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/components/Output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,29 @@ export const Output = ({
}
setSupportedNetworksSubset(networksSubset);

/**
* If it's first render show the default dest network or the first n/w from the list
* If the source chain is same as destination chain && same chain swaps is disabled, show the first chain from the list
*/
if (firstNetworkRender) {
updateNetwork(
networksSubset?.find(
(x: Network) => x.chainId === defaultDestNetwork
) ?? networksSubset?.[0]
);
setFirstRenderNetwork(false);
} else updateNetwork(networksSubset?.[0]);
} else if (!sameChainSwapsEnabled && sourceChainId === destChainId) {
updateNetwork(networksSubset?.[0]);
}
}
}, [sourceChainId, supportedNetworks]);

// when the default dest n/w is changed
useEffect(() => {
if(!firstNetworkRender && defaultDestNetwork){
updateNetwork(supportedNetworks?.find((x:Network) => x.chainId === defaultDestNetwork))
}
}, [supportedNetworks, sourceChainId, defaultDestNetwork]);
}, [supportedNetworks, defaultDestNetwork])

// For Input & tokens
const [outputAmount, updateOutputAmount] = useState<string>("");
Expand Down
5 changes: 4 additions & 1 deletion src/stories/Test.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ const Template = (args: WidgetProps) => {
</button>
)}
</div>
<Bridge {...args} provider={provider} />
<Bridge {...args} provider={provider}
// defaultDestNetwork={_defaultDestNetwork}
// destNetworks={_destNetworks}
/>
</div>
);
};
Expand Down

0 comments on commit f7b92c9

Please sign in to comment.