From 0294b94c3079d21be8a91e6b78a6bd38511a3251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Mon, 15 Jul 2024 10:24:59 +0200 Subject: [PATCH 1/9] refactor: simplify blockexplorer link working on integration a blockexplorer setting i found it very difficult to understand the BlockExplorerLink component, i would suggest of removing the general one on the `Pay` page and put it explicitly into each relevant swap status page. this removed the needs of the `BlockExplorerLink` component it can be tested for each status page --- src/components/BlockExplorerLink.tsx | 89 ------------ src/consts/Types.ts | 5 + src/context/Global.tsx | 8 -- src/context/Pay.tsx | 6 +- src/pages/Pay.tsx | 34 ----- src/status/SwapExpired.tsx | 14 +- tests/components/BlockExplorerLink.spec.tsx | 151 -------------------- 7 files changed, 17 insertions(+), 290 deletions(-) delete mode 100644 src/components/BlockExplorerLink.tsx delete mode 100644 tests/components/BlockExplorerLink.spec.tsx diff --git a/src/components/BlockExplorerLink.tsx b/src/components/BlockExplorerLink.tsx deleted file mode 100644 index 132e08b4..00000000 --- a/src/components/BlockExplorerLink.tsx +++ /dev/null @@ -1,89 +0,0 @@ -import { Accessor, Show, createEffect, createSignal } from "solid-js"; - -import { SwapType } from "../consts/Enums"; -import { - ChainSwap, - ReverseSwap, - SomeSwap, - SubmarineSwap, - getRelevantAssetForSwap, -} from "../utils/swapCreator"; -import BlockExplorer from "./BlockExplorer"; - -enum TransactionType { - Lockup = "lockupTx", - Claim = "claimTx", -} - -const BlockExplorerLink = ({ - swap, - swapStatus, - contractTransaction, - contractTransactionType, -}: { - swap: Accessor; - swapStatus: Accessor; - contractTransaction: Accessor; - contractTransactionType: Accessor; -}) => { - // Refund transactions are handled in SwapRefunded - - if (swap().type !== SwapType.Chain) { - return ( - <> - - - - - - - - ); - } - - // TODO: RSK - - const [hasBeenClaimed, setHasBeenClaimed] = createSignal(false); - - createEffect(() => { - setHasBeenClaimed(swap().claimTx !== undefined); - }); - - return ( - - ); -}; - -export default BlockExplorerLink; -export { TransactionType }; diff --git a/src/consts/Types.ts b/src/consts/Types.ts index bcbd86dd..d3ba064b 100644 --- a/src/consts/Types.ts +++ b/src/consts/Types.ts @@ -2,3 +2,8 @@ export type ButtonLabelParams = { key: string; params?: Record; }; + +export type SwapStatusTransaction = { + hex?: string; + id?: string; +}; diff --git a/src/context/Global.tsx b/src/context/Global.tsx index c30308f9..e520b194 100644 --- a/src/context/Global.tsx +++ b/src/context/Global.tsx @@ -37,8 +37,6 @@ export type GlobalContextType = { setWasmSupported: Setter; refundAddress: Accessor; setRefundAddress: Setter; - transactionToRefund: Accessor; - setTransactionToRefund: Setter; i18n: Accessor; setI18n: Setter; notification: Accessor; @@ -107,10 +105,6 @@ const GlobalProvider = (props: { children: any }) => { const [wasmSupported, setWasmSupported] = createSignal(true); const [refundAddress, setRefundAddress] = createSignal(null); - const [transactionToRefund, setTransactionToRefund] = createSignal< - string | null - >(null); - const [i18n, setI18n] = createSignal(null); const [notification, setNotification] = createSignal(""); @@ -326,8 +320,6 @@ const GlobalProvider = (props: { children: any }) => { setWasmSupported, refundAddress, setRefundAddress, - transactionToRefund, - setTransactionToRefund, i18n, setI18n, notification, diff --git a/src/context/Pay.tsx b/src/context/Pay.tsx index 662506d5..03d99e70 100644 --- a/src/context/Pay.tsx +++ b/src/context/Pay.tsx @@ -6,6 +6,7 @@ import { useContext, } from "solid-js"; +import { SwapStatusTransaction } from "../consts/Types"; import { SomeSwap } from "../utils/swapCreator"; export type PayContextType = { @@ -21,11 +22,6 @@ export type PayContextType = { const PayContext = createContext(); -type SwapStatusTransaction = { - hex?: string; - id?: string; -}; - const PayProvider = (props: { children: any }) => { const [failureReason, setFailureReason] = createSignal(""); const [swap, setSwap] = createSignal(null, { diff --git a/src/pages/Pay.tsx b/src/pages/Pay.tsx index e5c1bdaa..01edfb03 100644 --- a/src/pages/Pay.tsx +++ b/src/pages/Pay.tsx @@ -5,18 +5,13 @@ import { Show, Switch, createEffect, - createSignal, onCleanup, } from "solid-js"; -import BlockExplorerLink, { - TransactionType, -} from "../components/BlockExplorerLink"; import LoadingSpinner from "../components/LoadingSpinner"; import { SwapIcons } from "../components/SwapIcons"; import SettingsCog from "../components/settings/SettingsCog"; import SettingsMenu from "../components/settings/SettingsMenu"; -import { RBTC } from "../consts/Assets"; import { SwapType } from "../consts/Enums"; import { swapStatusFailed, @@ -42,11 +37,6 @@ import { getRelevantAssetForSwap } from "../utils/swapCreator"; const Pay = () => { const params = useParams(); - const [contractTransaction, setContractTransaction] = - createSignal(undefined); - const [contractTransactionType, setContractTransactionType] = createSignal( - TransactionType.Lockup, - ); const { getSwap, t } = useGlobalContext(); const { @@ -68,24 +58,6 @@ const Pay = () => { setSwapStatus(res.status); setSwapStatusTransaction(res.transaction); setFailureReason(res.failureReason); - - // RSK - if ( - asset === RBTC && - res.transaction && - currentSwap.claimTx === undefined - ) { - setContractTransaction(res.transaction.id); - } - - if (asset === RBTC && currentSwap["lockupTx"]) { - setContractTransaction(currentSwap["lockupTx"]); - } - - if (asset === RBTC && currentSwap.claimTx) { - setContractTransaction(currentSwap.claimTx); - setContractTransactionType(TransactionType.Claim); - } } }); @@ -208,12 +180,6 @@ const Pay = () => { - diff --git a/src/status/SwapExpired.tsx b/src/status/SwapExpired.tsx index c1448e3d..3291d2a0 100644 --- a/src/status/SwapExpired.tsx +++ b/src/status/SwapExpired.tsx @@ -1,7 +1,9 @@ import { useNavigate } from "@solidjs/router"; import log from "loglevel"; -import { Accessor, Show, createEffect } from "solid-js"; +import { Accessor, Show, createEffect, createSignal } from "solid-js"; +//import { SwapType } from "../consts/Enums"; +import BlockExplorer from "../components/BlockExplorer"; import RefundButton from "../components/RefundButton"; import { useGlobalContext } from "../context/Global"; import { usePayContext } from "../context/Pay"; @@ -11,8 +13,10 @@ import { ChainSwap, SubmarineSwap } from "../utils/swapCreator"; const SwapExpired = () => { const navigate = useNavigate(); const { failureReason, swap } = usePayContext(); - const { t, setTransactionToRefund, transactionToRefund } = - useGlobalContext(); + const { t } = useGlobalContext(); + + const [transactionToRefund, setTransactionToRefund] = + createSignal(""); createEffect(async () => { setTransactionToRefund(null); @@ -40,6 +44,10 @@ const SwapExpired = () => { swap={swap as Accessor} />
+