Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Deposit/Withdraw) Resolve initial layout race condition #4023

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/web/components/bridge/amount-and-review-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ export const AmountAndReviewScreen = observer(
const { supportedAssetsByChainId: counterpartySupportedAssetsByChainId } =
supportedAssets;

const hasNoSupportedChains =
!supportedAssets.isLoading &&
supportedAssets.supportedChains.length === 0;
const hasSupportedChains =
!supportedAssets.isLoading && supportedAssets.supportedChains.length > 0;

/** Filter for bridges for the current to/from chain/asset selection. */
const supportedBridgeInfo = useMemo<SupportedBridgeInfo>(() => {
Expand Down Expand Up @@ -287,7 +286,7 @@ export const AmountAndReviewScreen = observer(
isLoadingAssetsInOsmosis={isLoadingAssetsInOsmosis}
bridgesSupportedAssets={supportedAssets}
supportedBridgeInfo={supportedBridgeInfo}
hasNoSupportedChains={hasNoSupportedChains}
hasSupportedChains={hasSupportedChains}
fromChain={fromChain}
setFromChain={setFromChain}
toChain={toChain}
Expand Down
23 changes: 14 additions & 9 deletions packages/web/components/bridge/amount-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ interface AmountScreenProps {

bridgesSupportedAssets: ReturnType<typeof useBridgesSupportedAssets>;
supportedBridgeInfo: SupportedBridgeInfo;
hasNoSupportedChains: boolean;
hasSupportedChains: boolean;

fromChain: BridgeChainWithDisplayInfo | undefined;
setFromChain: (chain: BridgeChainWithDisplayInfo) => void;
Expand Down Expand Up @@ -126,7 +126,7 @@ export const AmountScreen = observer(
isLoading: isLoadingSupportedAssets,
},
supportedBridgeInfo,
hasNoSupportedChains,
hasSupportedChains,

fromChain,
setFromChain,
Expand Down Expand Up @@ -666,9 +666,13 @@ export const AmountScreen = observer(
isLoadingAssetsInOsmosis ||
!canonicalAsset ||
!canonicalAssetPrice ||
(direction === "withdraw"
? !fromChain || !fromAsset
: !toChain || !toAsset);
// If we don't have supported chains, we won't have a fromAsset or toAsset
// so we can't consider the loading state.
// therefore we only consider the loading state if we have supported chains.
(hasSupportedChains &&
(direction === "withdraw"
? !fromChain || !fromAsset
: !toChain || !toAsset));

const shouldShowAssetDropdown = useMemo(() => {
return direction === "deposit"
Expand Down Expand Up @@ -831,8 +835,9 @@ export const AmountScreen = observer(
* - Quoting is disabled for the current selection, meaning providers can't provide quotes but they may provide external URLs
*/
if (
(!isLoading || hasNoSupportedChains) &&
(areAssetTransfersDisabled ||
!isLoading &&
(!hasSupportedChains ||
areAssetTransfersDisabled ||
!fromChain ||
!fromAsset ||
!toChain ||
Expand All @@ -842,14 +847,14 @@ export const AmountScreen = observer(
) {
return (
<>
{!hasNoSupportedChains && chainSelection}
{hasSupportedChains && chainSelection}
<OnlyExternalBridgeSuggest
direction={direction}
toChain={toChain}
toAsset={
// If we haven't supported a chain, we can't suggest an asset
// so we use the canonical asset as a fallback
canonicalAsset && !toAsset && hasNoSupportedChains
canonicalAsset && !toAsset && !hasSupportedChains
? {
address: canonicalAsset?.coinMinimalDenom,
decimals: canonicalAsset?.coinDecimals,
Expand Down
Loading