Skip to content

Commit

Permalink
Merge pull request #653 from BoltzExchange/rif
Browse files Browse the repository at this point in the history
RIF relay for claim transactions
  • Loading branch information
michael1011 authored Aug 15, 2024
2 parents 0fe7bcf + c04ad81 commit 5369ed8
Show file tree
Hide file tree
Showing 62 changed files with 2,218 additions and 548 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ tags
.idea/
.vscode/

.env
*.log
dist/
ts-out/
Expand Down
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
"@babel/preset-typescript",
],
plugins: [
"babel-plugin-transform-vite-meta-env",
[
"@babel/plugin-transform-modules-commonjs",
{ allowTopLevelThis: true },
Expand Down
22 changes: 22 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#! /bin/python3

import sys

with open("./src/config.ts", "r") as f:
for line in f:
if "cooperativeDisabled" not in line:
continue

if "true" in line:
print("Cooperative signatures are disabled in config")
sys.exit(1)

break

with open(".env", "r") as f:
data = f.read()

for var in ["VITE_RSK_LOG_SCAN_ENDPOINT"]:
if var not in data:
print(f"{var} not in .env file")
sys.exit(1)
10 changes: 0 additions & 10 deletions build.ts

This file was deleted.

80 changes: 21 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dev": "vite",
"regtest": "cp src/configs/regtest.json public/config.json",
"preview": "vite preview",
"build": "vite-node build.ts && vite build; cp dist/index.html dist/404.html",
"build": "./build.py && vite build; cp dist/index.html dist/404.html",
"mainnet": "cp src/configs/mainnet.json public/config.json",
"beta": "cp src/configs/beta.json public/config.json",
"testnet": "cp src/configs/testnet.json public/config.json",
Expand All @@ -30,9 +30,9 @@
"@testing-library/user-event": "^14.5.2",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/jest": "^29.5.12",
"@types/node": "^22.0.2",
"@webbtc/webln-types": "^3.0.0",
"babel-jest": "^29.7.0",
"babel-plugin-transform-vite-meta-env": "^1.0.3",
"babel-preset-jest": "^29.6.3",
"babel-preset-solid": "^1.8.18",
"eventsource": "^2.0.2",
Expand All @@ -45,7 +45,6 @@
"solid-jest": "^0.2.0",
"typescript": "^5.5.4",
"vite": "^5.3.4",
"vite-node": "^2.0.4",
"vite-plugin-mkcert": "^1.17.5",
"vite-plugin-node-polyfills": "^0.22.0",
"vite-plugin-solid": "^2.10.2"
Expand Down
3 changes: 2 additions & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export default defineConfig({
ignoreHTTPSErrors: true,

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
headless: true,
trace: "on-first-retry",

headless: true,
},

/* Configure projects for major browsers */
Expand Down
2 changes: 1 addition & 1 deletion regtest
2 changes: 1 addition & 1 deletion src/components/BlockExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const BlockExplorer = (props: {

txId?: string;
address?: string;
typeLabel?: string;
typeLabel?: "lockup_address" | "lockup_tx" | "claim_tx" | "refund_tx";
}) => {
const { t } = useGlobalContext();
const href = () =>
Expand Down
84 changes: 41 additions & 43 deletions src/components/BlockExplorerLink.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Accessor, Show, createEffect, createSignal } from "solid-js";

import { RBTC } from "../consts/Assets";
import { SwapType } from "../consts/Enums";
import { usePayContext } from "../context/Pay";
import {
ChainSwap,
ReverseSwap,
Expand All @@ -10,60 +12,57 @@ import {
} from "../utils/swapCreator";
import BlockExplorer from "./BlockExplorer";

enum TransactionType {
Lockup = "lockupTx",
Claim = "claimTx",
}

const BlockExplorerLink = ({
swap,
swapStatus,
contractTransaction,
contractTransactionType,
}: {
swap: Accessor<SomeSwap>;
swapStatus: Accessor<string>;
contractTransaction: Accessor<string>;
contractTransactionType: Accessor<TransactionType>;
}) => {
// Refund transactions are handled in SwapRefunded
// Showing addresses makes no sense for EVM based chains
if (
(swap().type !== SwapType.Chain && getRelevantAssetForSwap(swap())) ===
RBTC
) {
const { swapStatusTransaction } = usePayContext();
const txId = () =>
swap().claimTx || swap().lockupTx || swapStatusTransaction()?.id;

if (swap().type !== SwapType.Chain) {
return (
<>
<Show
when={
getRelevantAssetForSwap(swap()) &&
swapStatus() !== null &&
swapStatus() !== "invoice.set" &&
swapStatus() !== "swap.created"
}>
<BlockExplorer
asset={getRelevantAssetForSwap(swap())}
txId={swap().claimTx}
address={
swap().type === SwapType.Submarine
? (swap() as SubmarineSwap).address
: (swap() as ReverseSwap).lockupAddress
}
/>
</Show>
<Show
when={
getRelevantAssetForSwap(swap()) &&
contractTransaction() !== undefined
}>
<BlockExplorer
asset={getRelevantAssetForSwap(swap())}
txId={contractTransaction()}
typeLabel={contractTransactionType()}
/>
</Show>
</>
<Show when={txId() !== undefined}>
<BlockExplorer
asset={getRelevantAssetForSwap(swap())}
txId={txId()}
typeLabel={
swap().claimTx !== undefined ? "claim_tx" : "lockup_tx"
}
/>
</Show>
);
}

// TODO: RSK
if (swap().type !== SwapType.Chain) {
// Refund transactions are handled in SwapRefunded
return (
<Show
when={
getRelevantAssetForSwap(swap()) &&
swapStatus() !== null &&
swapStatus() !== "invoice.set" &&
swapStatus() !== "swap.created"
}>
<BlockExplorer
asset={getRelevantAssetForSwap(swap())}
txId={swap().claimTx}
address={
swap().type === SwapType.Submarine
? (swap() as SubmarineSwap).address
: (swap() as ReverseSwap).lockupAddress
}
/>
</Show>
);
}

const [hasBeenClaimed, setHasBeenClaimed] = createSignal<boolean>(false);

Expand All @@ -86,4 +85,3 @@ const BlockExplorerLink = ({
};

export default BlockExplorerLink;
export { TransactionType };
Loading

0 comments on commit 5369ed8

Please sign in to comment.