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

refactor: simplify blockexplorer link #638

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/components/BlockExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { chooseUrl, config } from "../config";
import { useGlobalContext } from "../context/Global";

const blockExplorerLink = (asset: string, isTxId: boolean, val: string) => {
const basePath = chooseUrl(config.assets[asset].blockExplorerUrl);
const basePath = chooseUrl(config.assets[asset]?.blockExplorerUrl);
return `${basePath}/${isTxId ? "tx" : "address"}/${val}`;
};

Expand Down
89 changes: 0 additions & 89 deletions src/components/BlockExplorerLink.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/consts/Types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type ButtonLabelParams = {
key: string;
params?: Record<string, string>;
params?: Record;

Check failure on line 3 in src/consts/Types.ts

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Record' requires 2 type argument(s).

Check failure on line 3 in src/consts/Types.ts

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Record' requires 2 type argument(s).
};
8 changes: 0 additions & 8 deletions src/context/Global.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ export type GlobalContextType = {
setWasmSupported: Setter<boolean>;
refundAddress: Accessor<string | null>;
setRefundAddress: Setter<string | null>;
transactionToRefund: Accessor<string | null>;
setTransactionToRefund: Setter<string | null>;
i18n: Accessor<string | null>;
setI18n: Setter<string | null>;
notification: Accessor<string>;
Expand Down Expand Up @@ -107,10 +105,6 @@ const GlobalProvider = (props: { children: any }) => {
const [wasmSupported, setWasmSupported] = createSignal<boolean>(true);
const [refundAddress, setRefundAddress] = createSignal<string | null>(null);

const [transactionToRefund, setTransactionToRefund] = createSignal<
string | null
>(null);

const [i18n, setI18n] = createSignal<string | null>(null);

const [notification, setNotification] = createSignal<string>("");
Expand Down Expand Up @@ -326,8 +320,6 @@ const GlobalProvider = (props: { children: any }) => {
setWasmSupported,
refundAddress,
setRefundAddress,
transactionToRefund,
setTransactionToRefund,
i18n,
setI18n,
notification,
Expand Down
24 changes: 10 additions & 14 deletions src/context/Pay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,22 @@
useContext,
} from "solid-js";

import { SwapStatusTransaction } from "../utils/boltzClient";
import { SomeSwap } from "../utils/swapCreator";

export type PayContextType = {
failureReason: Accessor<string>;
setFailureReason: Setter<string>;
swap: Accessor<SomeSwap | null>;
setSwap: Setter<SomeSwap | null>;
swapStatus: Accessor<string>;
setSwapStatus: Setter<string>;
swapStatusTransaction: Accessor<SwapStatusTransaction>;
setSwapStatusTransaction: Setter<SwapStatusTransaction>;
failureReason: Accessor;

Check failure on line 13 in src/context/Pay.tsx

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Accessor' requires 1 type argument(s).

Check failure on line 13 in src/context/Pay.tsx

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Accessor' requires 1 type argument(s).
setFailureReason: Setter;

Check failure on line 14 in src/context/Pay.tsx

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Setter' requires 1 type argument(s).

Check failure on line 14 in src/context/Pay.tsx

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Setter' requires 1 type argument(s).
swap: Accessor;

Check failure on line 15 in src/context/Pay.tsx

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Accessor' requires 1 type argument(s).

Check failure on line 15 in src/context/Pay.tsx

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Accessor' requires 1 type argument(s).
setSwap: Setter;

Check failure on line 16 in src/context/Pay.tsx

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Setter' requires 1 type argument(s).

Check failure on line 16 in src/context/Pay.tsx

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Setter' requires 1 type argument(s).
swapStatus: Accessor;

Check failure on line 17 in src/context/Pay.tsx

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Accessor' requires 1 type argument(s).

Check failure on line 17 in src/context/Pay.tsx

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Accessor' requires 1 type argument(s).
setSwapStatus: Setter;

Check failure on line 18 in src/context/Pay.tsx

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Setter' requires 1 type argument(s).

Check failure on line 18 in src/context/Pay.tsx

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Setter' requires 1 type argument(s).
swapStatusTransaction: Accessor;

Check failure on line 19 in src/context/Pay.tsx

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Accessor' requires 1 type argument(s).

Check failure on line 19 in src/context/Pay.tsx

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Accessor' requires 1 type argument(s).
setSwapStatusTransaction: Setter;

Check failure on line 20 in src/context/Pay.tsx

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Setter' requires 1 type argument(s).

Check failure on line 20 in src/context/Pay.tsx

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Setter' requires 1 type argument(s).
};

const PayContext = createContext<PayContextType>();

type SwapStatusTransaction = {
hex?: string;
id?: string;
};

const PayProvider = (props: { children: any }) => {
const [failureReason, setFailureReason] = createSignal<string>("");
const [swap, setSwap] = createSignal<SomeSwap | null>(null, {
Expand All @@ -34,7 +30,7 @@
});
const [swapStatus, setSwapStatus] = createSignal<string>("");
const [swapStatusTransaction, setSwapStatusTransaction] =
createSignal<SwapStatusTransaction>({});
createSignal<SwapStatusTransaction | null>(null);

return (
<PayContext.Provider
Expand Down
42 changes: 1 addition & 41 deletions src/pages/Pay.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import { useParams } from "@solidjs/router";
import log from "loglevel";
import {
Match,
Show,
Switch,
createEffect,
createSignal,
onCleanup,
} from "solid-js";
import { Match, Show, Switch, createEffect, 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,
Expand All @@ -42,11 +31,6 @@ import { getRelevantAssetForSwap } from "../utils/swapCreator";

const Pay = () => {
const params = useParams();
const [contractTransaction, setContractTransaction] =
createSignal<string>(undefined);
const [contractTransactionType, setContractTransactionType] = createSignal(
TransactionType.Lockup,
);

const { getSwap, t } = useGlobalContext();
const {
Expand All @@ -68,24 +52,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);
}
}
});

Expand Down Expand Up @@ -208,12 +174,6 @@ const Pay = () => {
<SwapCreated />
</Match>
</Switch>
<BlockExplorerLink
swap={swap}
swapStatus={swapStatus}
contractTransaction={contractTransaction}
contractTransactionType={contractTransactionType}
/>
</Show>
</Show>
<Show when={!swap()}>
Expand Down
8 changes: 7 additions & 1 deletion src/status/InvoiceFailedToPay.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { OutputType } from "boltz-core";
import { Accessor, Show } from "solid-js";

import BlockExplorer from "../components/BlockExplorer";
import DownloadRefund from "../components/DownloadRefund";
import RefundButton from "../components/RefundButton";
import { RBTC } from "../consts/Assets";
import { useGlobalContext } from "../context/Global";
import { usePayContext } from "../context/Pay";
import { getLockupAddress } from "../utils/helper";
import { ChainSwap, SubmarineSwap } from "../utils/swapCreator";

const InvoiceFailedToPay = () => {
Expand All @@ -20,11 +22,15 @@
{t("failure_reason")}: {failureReason()}
</p>
<hr />
<RefundButton swap={swap as Accessor<SubmarineSwap | ChainSwap>} />
<RefundButton swap={swap as Accessor} />

Check failure on line 25 in src/status/InvoiceFailedToPay.tsx

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Accessor' requires 1 type argument(s).

Check failure on line 25 in src/status/InvoiceFailedToPay.tsx

View workflow job for this annotation

GitHub Actions / ci

Generic type 'Accessor' requires 1 type argument(s).
<Show when={swap().assetSend !== RBTC && !isTaproot}>
<DownloadRefund />
</Show>
<hr />
<BlockExplorer
asset={swap()?.assetSend}
address={getLockupAddress(swap() as SubmarineSwap | ChainSwap)}
dni marked this conversation as resolved.
Show resolved Hide resolved
/>
</div>
);
};
Expand Down
12 changes: 12 additions & 0 deletions src/status/InvoicePending.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import { Show } from "solid-js";

import BlockExplorer from "../components/BlockExplorer";
import LoadingSpinner from "../components/LoadingSpinner";
import { useGlobalContext } from "../context/Global";
import { usePayContext } from "../context/Pay";

const InvoicePending = () => {
const { t } = useGlobalContext();
const { swap, swapStatusTransaction } = usePayContext();
return (
<div>
<p>{t("invoice_pending")}</p>
<LoadingSpinner />
<Show when={swapStatusTransaction()}>
<BlockExplorer
asset={swap().assetSend}
txId={swapStatusTransaction().id}
typeLabel="lockup_tx"
/>
</Show>
</div>
);
};
Expand Down
26 changes: 16 additions & 10 deletions src/status/SwapExpired.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
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 BlockExplorer from "../components/BlockExplorer";
import RefundButton from "../components/RefundButton";
import { useGlobalContext } from "../context/Global";
import { usePayContext } from "../context/Pay";
import { getLockupTransaction } from "../utils/boltzClient";
import { LockupTransaction, getLockupTransaction } from "../utils/boltzClient";
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<LockupTransaction>(null);

createEffect(async () => {
setTransactionToRefund(null);
Expand All @@ -22,10 +25,10 @@ const SwapExpired = () => {
swap().id,
swap().type,
);
log.debug(`got swap transaction for ${swap().id}`);
setTransactionToRefund(res.hex);
log.debug(`got swap transaction for ${swap()?.id}`);
setTransactionToRefund(res);
} catch (error: any) {
log.warn(`no swap transaction for: ${swap().id}`, error);
log.warn(`no swap transaction for: ${swap()?.id}`, error);
}
});

Expand All @@ -36,10 +39,13 @@ const SwapExpired = () => {
</p>
<hr />
<Show when={transactionToRefund() !== null}>
<RefundButton
swap={swap as Accessor<SubmarineSwap | ChainSwap>}
/>
<RefundButton swap={swap as Accessor} />
<hr />
<BlockExplorer
typeLabel="lockup_tx"
asset={swap()?.assetSend}
txId={transactionToRefund()?.id}
/>
</Show>
<button class="btn" onClick={() => navigate("/swap")}>
{t("new_swap")}
Expand Down
Loading