mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-11-26 02:36:20 -05:00
fix(gui): "Approval not found or already handled"
This commit is contained in:
parent
3ebaaad1fa
commit
293ff2cdf3
11 changed files with 167 additions and 64 deletions
|
|
@ -22,6 +22,7 @@ import {
|
|||
getSwapInfo,
|
||||
initializeContext,
|
||||
listSellersAtRendezvousPoint,
|
||||
refreshApprovals,
|
||||
updateAllNodeStatuses,
|
||||
} from "./rpc";
|
||||
import { store } from "./store/storeRenderer";
|
||||
|
|
@ -44,6 +45,9 @@ const UPDATE_RATE_INTERVAL = 5 * 60 * 1_000;
|
|||
// Fetch all conversations every 10 minutes
|
||||
const FETCH_CONVERSATIONS_INTERVAL = 10 * 60 * 1_000;
|
||||
|
||||
// Fetch pending approvals every 10 seconds
|
||||
const FETCH_PENDING_APPROVALS_INTERVAL = 2 * 1_000;
|
||||
|
||||
function setIntervalImmediate(callback: () => void, interval: number): void {
|
||||
callback();
|
||||
setInterval(callback, interval);
|
||||
|
|
@ -60,6 +64,7 @@ export async function setupBackgroundTasks(): Promise<void> {
|
|||
listSellersAtRendezvousPoint(store.getState().settings.rendezvousPoints),
|
||||
DISCOVER_PEERS_INTERVAL,
|
||||
);
|
||||
setIntervalImmediate(refreshApprovals, FETCH_PENDING_APPROVALS_INTERVAL);
|
||||
|
||||
// Fetch all alerts
|
||||
updateAlerts();
|
||||
|
|
|
|||
|
|
@ -19,10 +19,17 @@ export default function SwapWidget() {
|
|||
sx={{ display: "flex", flexDirection: "column", gap: 2, width: "100%" }}
|
||||
>
|
||||
<SwapStatusAlert swap={swapInfo} onlyShowIfUnusualAmountOfTimeHasPassed />
|
||||
<Dialog fullWidth maxWidth="md" open={debug} onClose={() => setDebug(false)}>
|
||||
<Dialog
|
||||
fullWidth
|
||||
maxWidth="md"
|
||||
open={debug}
|
||||
onClose={() => setDebug(false)}
|
||||
>
|
||||
<DebugPage />
|
||||
<DialogActions>
|
||||
<Button variant="outlined" onClick={() => setDebug(false)}>Close</Button>
|
||||
<Button variant="outlined" onClick={() => setDebug(false)}>
|
||||
Close
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
<Paper
|
||||
|
|
|
|||
|
|
@ -31,8 +31,14 @@ import {
|
|||
RedactResponse,
|
||||
GetCurrentSwapResponse,
|
||||
LabeledMoneroAddress,
|
||||
GetPendingApprovalsArgs,
|
||||
GetPendingApprovalsResponse,
|
||||
} from "models/tauriModel";
|
||||
import { rpcSetBalance, rpcSetSwapInfo } from "store/features/rpcSlice";
|
||||
import {
|
||||
rpcSetBalance,
|
||||
rpcSetSwapInfo,
|
||||
approvalRequestsReplaced,
|
||||
} from "store/features/rpcSlice";
|
||||
import { store } from "./store/storeRenderer";
|
||||
import { Maker } from "models/apiModel";
|
||||
import { providerToConcatenatedMultiAddr } from "utils/multiAddrUtils";
|
||||
|
|
@ -422,10 +428,23 @@ export async function resolveApproval(
|
|||
requestId: string,
|
||||
accept: object,
|
||||
): Promise<void> {
|
||||
await invoke<ResolveApprovalArgs, ResolveApprovalResponse>(
|
||||
"resolve_approval_request",
|
||||
{ request_id: requestId, accept },
|
||||
try {
|
||||
await invoke<ResolveApprovalArgs, ResolveApprovalResponse>(
|
||||
"resolve_approval_request",
|
||||
{ request_id: requestId, accept },
|
||||
);
|
||||
} catch (error) {
|
||||
// Refresh approval list when resolve fails to keep UI in sync
|
||||
await refreshApprovals();
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function refreshApprovals(): Promise<void> {
|
||||
const response = await invokeNoArgs<GetPendingApprovalsResponse>(
|
||||
"get_pending_approvals",
|
||||
);
|
||||
store.dispatch(approvalRequestsReplaced(response.approvals));
|
||||
}
|
||||
|
||||
export async function checkSeed(seed: string): Promise<boolean> {
|
||||
|
|
|
|||
|
|
@ -140,6 +140,13 @@ export const rpcSlice = createSlice({
|
|||
const requestId = event.request_id;
|
||||
slice.state.approvalRequests[requestId] = event;
|
||||
},
|
||||
approvalRequestsReplaced(slice, action: PayloadAction<ApprovalRequest[]>) {
|
||||
// Clear existing approval requests and replace with new ones
|
||||
slice.state.approvalRequests = {};
|
||||
action.payload.forEach((approval) => {
|
||||
slice.state.approvalRequests[approval.request_id] = approval;
|
||||
});
|
||||
},
|
||||
backgroundProgressEventReceived(
|
||||
slice,
|
||||
action: PayloadAction<TauriBackgroundProgressWrapper>,
|
||||
|
|
@ -165,6 +172,7 @@ export const {
|
|||
rpcSetBackgroundRefundState,
|
||||
timelockChangeEventReceived,
|
||||
approvalEventReceived,
|
||||
approvalRequestsReplaced,
|
||||
backgroundProgressEventReceived,
|
||||
backgroundProgressEventRemoved,
|
||||
} = rpcSlice.actions;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue