Skip to content

Commit

Permalink
Enhance tx notify
Browse files Browse the repository at this point in the history
  • Loading branch information
JayJay1024 committed May 24, 2024
1 parent cb6c1c5 commit 5a4083a
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 495 deletions.
9 changes: 3 additions & 6 deletions packages/xtoken-ui/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Header from "@/components/header";
import RainbowProvider from "@/providers/rainbow-provider";
import GraphqlProvider from "@/providers/graphql-provider";
import AppProvider from "@/providers/app-provider";
import TransferProvider from "@/providers/transfer-provider";

const ibm_plex_sans = IBM_Plex_Sans({
subsets: ["latin", "latin-ext"],
Expand All @@ -25,11 +24,9 @@ export default function RootLayout({ children }: { children: React.ReactNode })
<GraphqlProvider>
<RainbowProvider>
<AppProvider>
<TransferProvider>
<Header />
{children}
{/* <Footer /> */}
</TransferProvider>
<Header />
{children}
{/* <Footer /> */}
</AppProvider>
</RainbowProvider>
</GraphqlProvider>
Expand Down
8 changes: 4 additions & 4 deletions packages/xtoken-ui/src/components/transaction-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function TransactionStatus({ record }: Props) {
try {
setBusy(true);
const receipt = await bridge?.claim(record);
notifyTransaction(receipt, targetChain);
notifyTransaction(receipt, targetChain, "Claim");
} catch (err) {
console.error(err);
notification.error({ title: "Claim failed", description: (err as Error).message });
Expand All @@ -82,7 +82,7 @@ export default function TransactionStatus({ record }: Props) {
try {
setBusy(true);
const receipt = await bridge?.refund(record);
notifyTransaction(receipt, targetChain);
notifyTransaction(receipt, targetChain, "Refund");
} catch (err) {
console.error(err);
notification.error({ title: "Refund failed", description: (err as Error).message });
Expand Down Expand Up @@ -111,13 +111,13 @@ export default function TransactionStatus({ record }: Props) {
try {
setBusy(true);
const receipt = await bridge?.speedUp(record, n > o ? n - o : 0n);
notifyTransaction(receipt, sourceChain);
notifyTransaction(receipt, sourceChain, "SpeedUp");
if (receipt?.status === "success") {
setIsOpen(false);
}
} catch (err) {
console.error(err);
notification.error({ title: "Refund failed", description: (err as Error).message });
notification.error({ title: "SpeedUp failed", description: (err as Error).message });
} finally {
setBusy(false);
}
Expand Down
133 changes: 0 additions & 133 deletions packages/xtoken-ui/src/components/transfer-action.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions packages/xtoken-ui/src/components/transfer-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function Component() {
const receipt = await approve(
fee?.token.type === "native" ? deferredAmount.value : deferredAmount.value + (fee?.value ?? 0n),
);
notifyTransaction(receipt, sourceChain);
notifyTransaction(receipt, sourceChain, "Approval");
} else if (actionText === "Deposit" || actionText === "Withdraw") {
setIsOpen(true);
}
Expand All @@ -196,7 +196,7 @@ function Component() {
const receipt = await bridge.transfer(account.address, recipient.value, deferredAmount.value, {
totalFee: fee?.value,
});
notifyTransaction(receipt, sourceChain);
notifyTransaction(receipt, sourceChain, "Transfer");
setIsTransfering(false);
if (receipt?.status === "success") {
setAmount({ input: "", valid: true, value: 0n, alert: "" });
Expand Down
40 changes: 2 additions & 38 deletions packages/xtoken-ui/src/components/user.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import { useApp, useTransfer } from "@/hooks";
import { useApp } from "@/hooks";
import Dropdown from "@/ui/dropdown";
import {
formatBalance,
getAvailableBridges,
getAvailableTargetChains,
getAvailableTargetTokens,
getChainLogoSrc,
getTokenLogoSrc,
toShortAdrress,
} from "@/utils";
import { formatBalance, getChainLogoSrc, getTokenLogoSrc, toShortAdrress } from "@/utils";
import { useConnectModal } from "@rainbow-me/rainbowkit";
import Image from "next/image";
import { PropsWithChildren } from "react";
import { useAccount, useDisconnect } from "wagmi";
import PrettyAddress from "./pretty-address";
import AddressIdenticon from "./address-identicon";
import { Placement } from "@floating-ui/react";
import { useRouter, useSearchParams } from "next/navigation";
import ComponentLoading from "@/ui/component-loading";
import History from "./history";

Expand All @@ -28,17 +19,12 @@ interface Props {
}

export default function User({ placement, prefixLength = 10, suffixLength = 8 }: Props) {
const { setBridgeCategory, setSourceChain, setTargetChain, setSourceToken, setTargetToken, updateUrlParams } =
useTransfer();
const { balanceAll, loadingBalanceAll } = useApp();

const { address } = useAccount();
const { disconnect } = useDisconnect();
const { openConnectModal } = useConnectModal();

const searchParams = useSearchParams();
const router = useRouter();

return address ? (
<Dropdown
childClassName="bg-background py-large rounded-large border border-white/20 flex flex-col gap-large"
Expand Down Expand Up @@ -92,28 +78,6 @@ export default function User({ placement, prefixLength = 10, suffixLength = 8 }:
key={`${balance.chain.network}-${balance.token.symbol}`}
className="gap-large lg:py-medium flex items-center rounded-2xl px-3 py-2 transition-colors hover:bg-white/10 disabled:cursor-default"
disabled
onClick={() => {
const _sourceChain = balance.chain;
const _sourceToken = balance.token;
const _targetChains = getAvailableTargetChains(_sourceChain);
const _targetChain = _targetChains.at(0);
const _targetTokens = getAvailableTargetTokens(_sourceChain, _targetChain, _sourceToken);
const _targetToken = _targetTokens.at(0);
const _category = getAvailableBridges(_sourceChain, _targetChain, _sourceToken).at(0);

setBridgeCategory(_category);
setSourceChain(_sourceChain);
setTargetChain(_targetChain);
setSourceToken(_sourceToken);
setTargetToken(_targetToken);
updateUrlParams(router, searchParams, {
_category,
_sourceChain,
_targetChain,
_sourceToken,
_targetToken,
});
}}
>
<div className="relative">
<Image
Expand Down
4 changes: 2 additions & 2 deletions packages/xtoken-ui/src/components/wrap-unwrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default function WrapUnwrap() {
try {
const receipt = await approve(amountRef.current.value);
setBusy(false);
notifyTransaction(receipt, ethereumChain);
notifyTransaction(receipt, ethereumChain, "Approval");
if (receipt?.status === "success") {
refreshAllowance();
}
Expand All @@ -147,7 +147,7 @@ export default function WrapUnwrap() {
});
const receipt = await publicClient.waitForTransactionReceipt({ hash });
setBusy(false);
notifyTransaction(receipt, ethereumChain);
notifyTransaction(receipt, ethereumChain, actionText === "Unwrap" ? "Withdraw" : "Deposit");
if (receipt.status === "success") {
refreshBalance();
}
Expand Down
1 change: 0 additions & 1 deletion packages/xtoken-ui/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from "./use-app";
export * from "./use-toggle";
export * from "./use-transfer";
export * from "./use-balance-all";
export * from "./use-balance";
export * from "./use-transfer-v2";
Expand Down
4 changes: 0 additions & 4 deletions packages/xtoken-ui/src/hooks/use-transfer.ts

This file was deleted.

Loading

0 comments on commit 5a4083a

Please sign in to comment.