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) Change bridge top bar on deposit address and remove awaiting BTC on more than 1 transfer #3987

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
390 changes: 195 additions & 195 deletions packages/e2e/pages/trade-page.ts

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions packages/web/components/bridge/amount-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
useMemo,
useState,
} from "react";
import { useMeasure } from "react-use";
import { useMeasure, useUnmount } from "react-use";

import { Icon } from "~/components/assets";
import { BridgeReceiveAssetDropdown } from "~/components/bridge/bridge-receive-asset-dropdown";
Expand All @@ -41,7 +41,7 @@ import {
useFeatureFlags,
useTranslation,
} from "~/hooks";
import { BridgeScreen } from "~/hooks/bridge";
import { BridgeScreen, useBridgeStore } from "~/hooks/bridge";
import { useEvmWalletAccount, useSwitchEvmChain } from "~/hooks/evm-wallet";
import { usePrice } from "~/hooks/queries/assets/use-price";
import { BridgeChainWithDisplayInfo } from "~/server/api/routers/bridge-transfer";
Expand Down Expand Up @@ -609,6 +609,10 @@ export const AmountScreen = observer(
toChain,
]);

useUnmount(() => {
useBridgeStore.getState().setType("quote");
});

/** If an asset is disabled */
const areAssetTransfersDisabled = useMemo(() => {
return direction === "withdraw"
Expand Down Expand Up @@ -802,6 +806,7 @@ export const AmountScreen = observer(
toChain &&
toAsset
) {
useBridgeStore.getState().setType("deposit-address");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid mutating state during render

Calling useBridgeStore.getState().setType("deposit-address") directly within the render path can cause side effects during rendering, which violates React's principle that render functions should be pure and side-effect free. This can lead to unexpected behavior and difficult-to-trace bugs.

Consider moving this state mutation into a useEffect hook to ensure it runs after the component renders:

- useBridgeStore.getState().setType("deposit-address");
  return (
+   useEffect(() => {
+     useBridgeStore.getState().setType("deposit-address");
+   }, []);
+
    <DepositAddressScreen
      canonicalAsset={canonicalAsset}
      direction={direction}
      chainSelection={chainSelection}
      assetDropdown={assetDropdown}
      fromChain={fromChain}
      toChain={toChain}
      fromAsset={fromAsset}
      toAsset={toAsset}
      bridge={supportedBridgeInfo.depositAddressBridges[0]} // For now, only one bridge provider is supported
    />
  );

Committable suggestion skipped: line range outside the PR's diff.

return (
<DepositAddressScreen
canonicalAsset={canonicalAsset}
Expand Down Expand Up @@ -851,6 +856,8 @@ export const AmountScreen = observer(
);
}

useBridgeStore.getState().setType("quote");

Comment on lines +859 to +860
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid mutating state during render

Similar to the previous issue, calling useBridgeStore.getState().setType("quote") directly within the render function can introduce side effects during rendering.

Move this state mutation into a useEffect hook to align with React best practices:

- useBridgeStore.getState().setType("quote");

  /**
   * This will trigger an error boundary
   */
  if (!supportedSourceAssets && !isLoading) {
    throw new Error("Supported source assets are not defined");
  }

+ useEffect(() => {
+   useBridgeStore.getState().setType("quote");
+ }, []);

Committable suggestion skipped: line range outside the PR's diff.

/**
* This will trigger an error boundary
*/
Expand Down
8 changes: 5 additions & 3 deletions packages/web/components/nomic/nomic-pending-transfers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,11 @@ export const NomicPendingTransfers = ({
refetchInterval={refetchInterval}
dataUpdatedAt={nomicDepositsDataUpdatedAt}
/>
<p className="text-white-full">
{t("transfer.nomic.awaitingBtc")}
</p>
{transactions.length === 0 && (
<p className="text-white-full">
{t("transfer.nomic.awaitingBtc")}
</p>
)}
</div>
)}
</>
Expand Down
78 changes: 56 additions & 22 deletions packages/web/hooks/bridge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const useBridgeStore = create(
combine(
{
isVisible: false,
type: "quote" as "quote" | "deposit-address",
step: BridgeScreen.Asset,
direction: undefined as "deposit" | "withdraw" | undefined,
selectedAssetDenom: undefined as string | undefined,
Expand Down Expand Up @@ -112,6 +113,9 @@ export const useBridgeStore = create(
fiatRampSelectionOpen: nextValue ?? !state.fiatRampSelectionOpen,
}));
},
setType: (type: "quote" | "deposit-address") => {
set({ type });
},
})
)
);
Expand All @@ -125,6 +129,7 @@ export const ImmersiveBridge = () => {
const { isReady: isRouterReady } = useRouter();

const {
type,
direction,
isVisible,
selectedAssetDenom,
Expand All @@ -143,6 +148,7 @@ export const ImmersiveBridge = () => {
isVisible: state.isVisible,
step: state.step,
direction: state.direction,
type: state.type,
selectedAssetDenom: state.selectedAssetDenom,
setIsVisible: state.setIsVisible,
setStep: state.setStep,
Expand Down Expand Up @@ -298,28 +304,56 @@ export const ImmersiveBridge = () => {
)}
<StepProgress
className="mx-6 max-w-3xl shrink md:hidden"
steps={[
{
displayLabel: t("transfer.stepLabels.asset"),
onClick:
step !== BridgeScreen.Asset
? () => {
setStep(BridgeScreen.Asset);
setSelectedAssetDenom(undefined);
}
: undefined,
},
{
displayLabel: t("transfer.stepLabels.amount"),
onClick:
step === BridgeScreen.Review
? () => setStep(BridgeScreen.Amount)
: undefined,
},
{
displayLabel: t("transfer.stepLabels.review"),
},
]}
steps={
type === "quote"
? [
{
displayLabel: t(
"transfer.stepLabels.asset"
),
onClick:
step !== BridgeScreen.Asset
? () => {
setStep(BridgeScreen.Asset);
setSelectedAssetDenom(undefined);
}
: undefined,
},
{
displayLabel: t(
"transfer.stepLabels.amount"
),
onClick:
step === BridgeScreen.Review
? () => setStep(BridgeScreen.Amount)
: undefined,
},
{
displayLabel: t(
"transfer.stepLabels.review"
),
},
]
: [
{
displayLabel: t(
"transfer.stepLabels.asset"
),
onClick:
step !== BridgeScreen.Asset
? () => {
setStep(BridgeScreen.Asset);
setSelectedAssetDenom(undefined);
}
: undefined,
},
{
displayLabel: t(
"transfer.stepLabels.deposit"
),
},
]
}
currentStep={Number(step)}
/>
<IconButton
Expand Down
3 changes: 2 additions & 1 deletion packages/web/localizations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@
"stepLabels": {
"asset": "Vermögenswert",
"amount": "Menge",
"review": "Rezension"
"review": "Rezension",
"deposit": "Kaution"
},
"moreBridgeOptions": {
"titleDeposit": "Mehr Einzahlungsmöglichkeiten",
Expand Down
3 changes: 2 additions & 1 deletion packages/web/localizations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@
"stepLabels": {
"asset": "Asset",
"amount": "Amount",
"review": "Review"
"review": "Review",
"deposit": "Deposit"
},
"moreBridgeOptions": {
"titleDeposit": "More deposit options",
Expand Down
3 changes: 2 additions & 1 deletion packages/web/localizations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@
"stepLabels": {
"asset": "Activo",
"amount": "Cantidad",
"review": "Revisar"
"review": "Revisar",
"deposit": "Depósito"
},
"moreBridgeOptions": {
"titleDeposit": "Más opciones de depósito",
Expand Down
3 changes: 2 additions & 1 deletion packages/web/localizations/fa.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@
"stepLabels": {
"asset": "دارایی",
"amount": "میزان",
"review": "مرور"
"review": "مرور",
"deposit": "سپرده گذاری"
},
"moreBridgeOptions": {
"titleDeposit": "گزینه های سپرده بیشتر",
Expand Down
3 changes: 2 additions & 1 deletion packages/web/localizations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@
"stepLabels": {
"asset": "Actif",
"amount": "Montant",
"review": "Revoir"
"review": "Revoir",
"deposit": "Dépôt"
},
"moreBridgeOptions": {
"titleDeposit": "Plus d'options de dépôt",
Expand Down
3 changes: 2 additions & 1 deletion packages/web/localizations/gu.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@
"stepLabels": {
"asset": "એસેટ",
"amount": "રકમ",
"review": "સમીક્ષા"
"review": "સમીક્ષા",
"deposit": "જમા"
},
"moreBridgeOptions": {
"titleDeposit": "વધુ થાપણ વિકલ્પો",
Expand Down
3 changes: 2 additions & 1 deletion packages/web/localizations/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@
"stepLabels": {
"asset": "संपत्ति",
"amount": "मात्रा",
"review": "समीक्षा"
"review": "समीक्षा",
"deposit": "जमा"
},
"moreBridgeOptions": {
"titleDeposit": "अधिक जमा विकल्प",
Expand Down
3 changes: 2 additions & 1 deletion packages/web/localizations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@
"stepLabels": {
"asset": "資産",
"amount": "額",
"review": "レビュー"
"review": "レビュー",
"deposit": "デポジット"
},
"moreBridgeOptions": {
"titleDeposit": "その他の入金オプション",
Expand Down
3 changes: 2 additions & 1 deletion packages/web/localizations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@
"stepLabels": {
"asset": "유산",
"amount": "양",
"review": "검토"
"review": "검토",
"deposit": "보증금"
},
"moreBridgeOptions": {
"titleDeposit": "더 많은 입금 옵션",
Expand Down
3 changes: 2 additions & 1 deletion packages/web/localizations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@
"stepLabels": {
"asset": "Zaleta",
"amount": "Kwota",
"review": "Recenzja"
"review": "Recenzja",
"deposit": "Depozyt"
},
"moreBridgeOptions": {
"titleDeposit": "Więcej opcji depozytu",
Expand Down
3 changes: 2 additions & 1 deletion packages/web/localizations/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@
"stepLabels": {
"asset": "Ativo",
"amount": "Quantia",
"review": "Análise"
"review": "Análise",
"deposit": "Depósito"
},
"moreBridgeOptions": {
"titleDeposit": "Mais opções de depósito",
Expand Down
3 changes: 2 additions & 1 deletion packages/web/localizations/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@
"stepLabels": {
"asset": "Atu",
"amount": "Cantitate",
"review": "Revizuire"
"review": "Revizuire",
"deposit": "Depozit"
},
"moreBridgeOptions": {
"titleDeposit": "Mai multe opțiuni de depunere",
Expand Down
3 changes: 2 additions & 1 deletion packages/web/localizations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@
"stepLabels": {
"asset": "Объект",
"amount": "Количество",
"review": "Обзор"
"review": "Обзор",
"deposit": "Депозит"
},
"moreBridgeOptions": {
"titleDeposit": "Больше вариантов депозита",
Expand Down
3 changes: 2 additions & 1 deletion packages/web/localizations/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@
"stepLabels": {
"asset": "Varlık",
"amount": "Miktar",
"review": "Gözden geçirmek"
"review": "Gözden geçirmek",
"deposit": "Depozito"
},
"moreBridgeOptions": {
"titleDeposit": "Daha fazla para yatırma seçeneği",
Expand Down
3 changes: 2 additions & 1 deletion packages/web/localizations/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@
"stepLabels": {
"asset": "资产",
"amount": "数量",
"review": "审查"
"review": "审查",
"deposit": "订金"
},
"moreBridgeOptions": {
"titleDeposit": "更多存款选择",
Expand Down
3 changes: 2 additions & 1 deletion packages/web/localizations/zh-hk.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@
"stepLabels": {
"asset": "資產",
"amount": "數量",
"review": "審查"
"review": "審查",
"deposit": "訂金"
},
"moreBridgeOptions": {
"titleDeposit": "更多存款選擇",
Expand Down
3 changes: 2 additions & 1 deletion packages/web/localizations/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@
"stepLabels": {
"asset": "資產",
"amount": "數量",
"review": "審查"
"review": "審查",
"deposit": "訂金"
},
"moreBridgeOptions": {
"titleDeposit": "更多存款選擇",
Expand Down
Loading