Skip to content

Commit

Permalink
fix(gui): Fetch balance after swap is released, re-fetch database aft…
Browse files Browse the repository at this point in the history
…er progress event, change wording in progress page (#237)
  • Loading branch information
binarybaron authored Dec 23, 2024
1 parent 27e8467 commit cf20891
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions src-gui/src/renderer/background.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { listen } from "@tauri-apps/api/event";
import { TauriSwapProgressEventWrapper, TauriContextStatusEvent, TauriLogEvent, BalanceResponse, TauriDatabaseStateEvent, TauriTimelockChangeEvent, TauriBackgroundRefundEvent } from "models/tauriModel";
import { TauriSwapProgressEventWrapper, TauriContextStatusEvent, TauriLogEvent, BalanceResponse, TauriDatabaseStateEvent, TauriTimelockChangeEvent, TauriBackgroundRefundEvent, TauriTorEvent } from "models/tauriModel";
import { contextStatusEventReceived, receivedCliLog, rpcSetBalance, timelockChangeEventReceived, rpcSetBackgroundRefundState } from "store/features/rpcSlice";
import { swapProgressEventReceived } from "store/features/swapSlice";
import logger from "utils/logger";
import { updatePublicRegistry, updateRates } from "./api";
import { checkContextAvailability, getSwapInfo, initializeContext, updateAllNodeStatuses } from "./rpc";
import { store } from "./store/storeRenderer";
import { torEventReceived } from "store/features/torSlice";

// Update the public registry every 5 minutes
const PROVIDER_UPDATE_INTERVAL = 5 * 60 * 1_000;
Expand Down Expand Up @@ -56,7 +57,6 @@ export async function setupBackgroundTasks(): Promise<void> {
});

listen<TauriLogEvent>("cli-log-emitted", (event) => {
logger.info("Received cli log event", event.payload);
store.dispatch(receivedCliLog(event.payload));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function DebugPage() {
data={cliState}
label="Swap Daemon State (exposed via API)"
/>
<CliLogsBox label="Tor Daemon Logs" logs={torStdOut.split("\n")} />
<CliLogsBox label="Tor Daemon Logs" logs={(torStdOut || "").split("\n")} />
</Box>
</DialogContentText>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import CircularProgressWithSubtitle from "../../CircularProgressWithSubtitle";

export default function ReceivedQuotePage() {
return (
<CircularProgressWithSubtitle description="Exchanging keys, zero-knowledge proofs and generating multi-signature addresses" />
<CircularProgressWithSubtitle description="Processing received quote" />
);
}
3 changes: 2 additions & 1 deletion src-gui/src/store/features/rpcSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export const rpcSlice = createSlice({
receivedCliLog(slice, action: PayloadAction<TauriLogEvent>) {
const buffer = action.payload.buffer;
const logs = getLogsAndStringsFromRawFileString(buffer);
slice.logs = slice.logs.concat(logs);
const logsWithoutExisting = logs.filter(log => !slice.logs.includes(log));
slice.logs = slice.logs.concat(logsWithoutExisting);
},
contextStatusEventReceived(
slice,
Expand Down
20 changes: 19 additions & 1 deletion src-gui/src/store/middleware/storeListener.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { createListenerMiddleware } from "@reduxjs/toolkit";
import { getAllSwapInfos, checkBitcoinBalance, updateAllNodeStatuses, fetchSellersAtPresetRendezvousPoints } from "renderer/rpc";
import { getAllSwapInfos, checkBitcoinBalance, updateAllNodeStatuses, fetchSellersAtPresetRendezvousPoints, getSwapInfo } from "renderer/rpc";
import logger from "utils/logger";
import { contextStatusEventReceived } from "store/features/rpcSlice";
import { addNode, setFetchFiatPrices, setFiatCurrency } from "store/features/settingsSlice";
import { updateRates } from "renderer/api";
import { store } from "renderer/store/storeRenderer";
import { swapProgressEventReceived } from "store/features/swapSlice";

export function createMainListeners() {
const listener = createListenerMiddleware();
Expand All @@ -30,6 +31,23 @@ export function createMainListeners() {
},
});

// Listener for:
// - when a swap is released (fetch bitcoin balance)
// - when a swap progress event is received (update the swap info)
listener.startListening({
actionCreator: swapProgressEventReceived,
effect: async (action) => {
if (action.payload.event.type === "Released") {
logger.info("Swap released, updating bitcoin balance...");
await checkBitcoinBalance();
}

// Update the swap info
logger.info("Swap progress event received, updating swap info from database...");
await getSwapInfo(action.payload.swap_id);
},
});

// Update the rates when the fiat currency is changed
listener.startListening({
actionCreator: setFiatCurrency,
Expand Down
2 changes: 1 addition & 1 deletion swap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ hex = "0.4"
jsonrpsee = { version = "0.16.2", features = [ "server" ] }
jsonrpsee-core = "0.16.2"
libp2p = { version = "0.53.2", features = [ "tcp", "yamux", "dns", "noise", "request-response", "ping", "rendezvous", "identify", "macros", "cbor", "json", "tokio", "serde", "rsa" ] }
libp2p-community-tor = { git = "https://github.com/umgefahren/libp2p-tor", features = [ "listen-onion-service" ] }
libp2p-community-tor = { git = "https://github.com/umgefahren/libp2p-tor", branch = "main", features = [ "listen-onion-service" ] }
monero = { version = "0.12", features = [ "serde_support" ] }
monero-rpc = { path = "../monero-rpc" }
once_cell = "1.19"
Expand Down

0 comments on commit cf20891

Please sign in to comment.