From 76c6d162a1a958e81a28af5f4e8fb0f9d030ec5d Mon Sep 17 00:00:00 2001 From: michael1011 Date: Tue, 3 Dec 2024 16:56:09 +0100 Subject: [PATCH] refactor: make RSK log scan endpoint optional --- .env.sample | 6 ++++++ build.py | 24 ++++++++++++------------ src/pages/Refund.tsx | 2 ++ src/utils/contractLogs.ts | 5 +++++ 4 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 .env.sample diff --git a/.env.sample b/.env.sample new file mode 100644 index 00000000..4559c95d --- /dev/null +++ b/.env.sample @@ -0,0 +1,6 @@ +# RSK RPC URL for logs scanning which is not supported by the public RPCs +VITE_RSK_LOG_SCAN_ENDPOINT= + +# Token for the Chatwoot website inbox +# The chat widget will not be loaded if not set +VITE_CHATWOOT_TOKEN= diff --git a/build.py b/build.py index 5e9224f4..72674b20 100755 --- a/build.py +++ b/build.py @@ -5,7 +5,6 @@ def handle_coop_disabled(): print("Cooperative signatures are disabled in config") - sys.exit(1) with open("./src/config.ts", "r") as f: for line in f: @@ -28,14 +27,15 @@ def handle_coop_disabled(): # .env file is not required on regtest if network != "regtest": - 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) - - for var in ["VITE_CHATWOOT_TOKEN"]: - if var not in data: - print(f"WARN: {var} not in .env file") + try: + with open(".env", "r") as f: + data = f.read() + + for var in [ + "VITE_RSK_LOG_SCAN_ENDPOINT", + "VITE_CHATWOOT_TOKEN" + ]: + if var not in data: + print(f"WARN: {var} not in .env file") + except Exception as e: + print("WARN: could not open .env file:", e) diff --git a/src/pages/Refund.tsx b/src/pages/Refund.tsx index aab0ce26..bfd985aa 100644 --- a/src/pages/Refund.tsx +++ b/src/pages/Refund.tsx @@ -231,6 +231,8 @@ const Refund = () => { /> 0 && (refundJson() === null || refundJson().assetSend === RBTC) diff --git a/src/utils/contractLogs.ts b/src/utils/contractLogs.ts index cdf48381..8cc1ae2a 100644 --- a/src/utils/contractLogs.ts +++ b/src/utils/contractLogs.ts @@ -66,6 +66,11 @@ async function* scanLogsForPossibleRefunds( ); const scanProviderUrl = import.meta.env.VITE_RSK_LOG_SCAN_ENDPOINT; + if (scanProviderUrl === undefined) { + return; + } + + console.log(scanProviderUrl); const etherSwapScan = scanProviderUrl !== undefined ? (new Contract(