wip: WithdrawDialog migrated to Tauri IPC

This commit is contained in:
binarybaron 2024-08-09 19:46:58 +02:00
parent 47821cbe79
commit 3d16ff6d5c
No known key found for this signature in database
GPG key ID: 99B75D3E1476A26E
118 changed files with 1779 additions and 1868 deletions

View file

@ -24,5 +24,5 @@ export interface Alert {
id: number;
title: string;
body: string;
severity: 'info' | 'warning' | 'error';
severity: "info" | "warning" | "error";
}

View file

@ -1,14 +1,14 @@
export enum SwapSpawnType {
INIT = 'init',
RESUME = 'resume',
CANCEL_REFUND = 'cancel-refund',
INIT = "init",
RESUME = "resume",
CANCEL_REFUND = "cancel-refund",
}
export type CliLogSpanType = string | 'BitcoinWalletSubscription';
export type CliLogSpanType = string | "BitcoinWalletSubscription";
export interface CliLog {
timestamp: string;
level: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'TRACE';
level: "DEBUG" | "INFO" | "WARN" | "ERROR" | "TRACE";
fields: {
message: string;
[index: string]: unknown;
@ -20,12 +20,12 @@ export interface CliLog {
}
export function isCliLog(log: unknown): log is CliLog {
if (log && typeof log === 'object') {
if (log && typeof log === "object") {
return (
'timestamp' in (log as CliLog) &&
'level' in (log as CliLog) &&
'fields' in (log as CliLog) &&
typeof (log as CliLog).fields?.message === 'string'
"timestamp" in (log as CliLog) &&
"level" in (log as CliLog) &&
"fields" in (log as CliLog) &&
typeof (log as CliLog).fields?.message === "string"
);
}
return false;
@ -33,7 +33,7 @@ export function isCliLog(log: unknown): log is CliLog {
export interface CliLogStartedRpcServer extends CliLog {
fields: {
message: 'Started RPC server';
message: "Started RPC server";
addr: string;
};
}
@ -41,12 +41,12 @@ export interface CliLogStartedRpcServer extends CliLog {
export function isCliLogStartedRpcServer(
log: CliLog,
): log is CliLogStartedRpcServer {
return log.fields.message === 'Started RPC server';
return log.fields.message === "Started RPC server";
}
export interface CliLogReleasingSwapLockLog extends CliLog {
fields: {
message: 'Releasing swap lock';
message: "Releasing swap lock";
swap_id: string;
};
}
@ -54,23 +54,23 @@ export interface CliLogReleasingSwapLockLog extends CliLog {
export function isCliLogReleasingSwapLockLog(
log: CliLog,
): log is CliLogReleasingSwapLockLog {
return log.fields.message === 'Releasing swap lock';
return log.fields.message === "Releasing swap lock";
}
export interface CliLogApiCallError extends CliLog {
fields: {
message: 'API call resulted in an error';
message: "API call resulted in an error";
err: string;
};
}
export function isCliLogApiCallError(log: CliLog): log is CliLogApiCallError {
return log.fields.message === 'API call resulted in an error';
return log.fields.message === "API call resulted in an error";
}
export interface CliLogAcquiringSwapLockLog extends CliLog {
fields: {
message: 'Acquiring swap lock';
message: "Acquiring swap lock";
swap_id: string;
};
}
@ -78,12 +78,12 @@ export interface CliLogAcquiringSwapLockLog extends CliLog {
export function isCliLogAcquiringSwapLockLog(
log: CliLog,
): log is CliLogAcquiringSwapLockLog {
return log.fields.message === 'Acquiring swap lock';
return log.fields.message === "Acquiring swap lock";
}
export interface CliLogReceivedQuote extends CliLog {
fields: {
message: 'Received quote';
message: "Received quote";
price: string;
minimum_amount: string;
maximum_amount: string;
@ -91,12 +91,12 @@ export interface CliLogReceivedQuote extends CliLog {
}
export function isCliLogReceivedQuote(log: CliLog): log is CliLogReceivedQuote {
return log.fields.message === 'Received quote';
return log.fields.message === "Received quote";
}
export interface CliLogWaitingForBtcDeposit extends CliLog {
fields: {
message: 'Waiting for Bitcoin deposit';
message: "Waiting for Bitcoin deposit";
deposit_address: string;
min_deposit_until_swap_will_start: string;
max_deposit_until_maximum_amount_is_reached: string;
@ -111,24 +111,24 @@ export interface CliLogWaitingForBtcDeposit extends CliLog {
export function isCliLogWaitingForBtcDeposit(
log: CliLog,
): log is CliLogWaitingForBtcDeposit {
return log.fields.message === 'Waiting for Bitcoin deposit';
return log.fields.message === "Waiting for Bitcoin deposit";
}
export interface CliLogReceivedBtc extends CliLog {
fields: {
message: 'Received Bitcoin';
message: "Received Bitcoin";
max_giveable: string;
new_balance: string;
};
}
export function isCliLogReceivedBtc(log: CliLog): log is CliLogReceivedBtc {
return log.fields.message === 'Received Bitcoin';
return log.fields.message === "Received Bitcoin";
}
export interface CliLogDeterminedSwapAmount extends CliLog {
fields: {
message: 'Determined swap amount';
message: "Determined swap amount";
amount: string;
fees: string;
};
@ -137,49 +137,49 @@ export interface CliLogDeterminedSwapAmount extends CliLog {
export function isCliLogDeterminedSwapAmount(
log: CliLog,
): log is CliLogDeterminedSwapAmount {
return log.fields.message === 'Determined swap amount';
return log.fields.message === "Determined swap amount";
}
export interface CliLogStartedSwap extends CliLog {
fields: {
message: 'Starting new swap';
message: "Starting new swap";
swap_id: string;
};
}
export function isCliLogStartedSwap(log: CliLog): log is CliLogStartedSwap {
return log.fields.message === 'Starting new swap';
return log.fields.message === "Starting new swap";
}
export interface CliLogPublishedBtcTx extends CliLog {
fields: {
message: 'Published Bitcoin transaction';
message: "Published Bitcoin transaction";
txid: string;
kind: 'lock' | 'cancel' | 'withdraw' | 'refund';
kind: "lock" | "cancel" | "withdraw" | "refund";
};
}
export function isCliLogPublishedBtcTx(
log: CliLog,
): log is CliLogPublishedBtcTx {
return log.fields.message === 'Published Bitcoin transaction';
return log.fields.message === "Published Bitcoin transaction";
}
export interface CliLogBtcTxFound extends CliLog {
fields: {
message: 'Found relevant Bitcoin transaction';
message: "Found relevant Bitcoin transaction";
txid: string;
status: string;
};
}
export function isCliLogBtcTxFound(log: CliLog): log is CliLogBtcTxFound {
return log.fields.message === 'Found relevant Bitcoin transaction';
return log.fields.message === "Found relevant Bitcoin transaction";
}
export interface CliLogBtcTxStatusChanged extends CliLog {
fields: {
message: 'Bitcoin transaction status changed';
message: "Bitcoin transaction status changed";
txid: string;
new_status: string;
};
@ -188,12 +188,12 @@ export interface CliLogBtcTxStatusChanged extends CliLog {
export function isCliLogBtcTxStatusChanged(
log: CliLog,
): log is CliLogBtcTxStatusChanged {
return log.fields.message === 'Bitcoin transaction status changed';
return log.fields.message === "Bitcoin transaction status changed";
}
export interface CliLogAliceLockedXmr extends CliLog {
fields: {
message: 'Alice locked Monero';
message: "Alice locked Monero";
txid: string;
};
}
@ -201,12 +201,12 @@ export interface CliLogAliceLockedXmr extends CliLog {
export function isCliLogAliceLockedXmr(
log: CliLog,
): log is CliLogAliceLockedXmr {
return log.fields.message === 'Alice locked Monero';
return log.fields.message === "Alice locked Monero";
}
export interface CliLogReceivedXmrLockTxConfirmation extends CliLog {
fields: {
message: 'Received new confirmation for Monero lock tx';
message: "Received new confirmation for Monero lock tx";
txid: string;
seen_confirmations: string;
needed_confirmations: string;
@ -216,50 +216,50 @@ export interface CliLogReceivedXmrLockTxConfirmation extends CliLog {
export function isCliLogReceivedXmrLockTxConfirmation(
log: CliLog,
): log is CliLogReceivedXmrLockTxConfirmation {
return log.fields.message === 'Received new confirmation for Monero lock tx';
return log.fields.message === "Received new confirmation for Monero lock tx";
}
export interface CliLogAdvancingState extends CliLog {
fields: {
message: 'Advancing state';
message: "Advancing state";
state:
| 'quote has been requested'
| 'execution setup done'
| 'btc is locked'
| 'XMR lock transaction transfer proof received'
| 'xmr is locked'
| 'encrypted signature is sent'
| 'btc is redeemed'
| 'cancel timelock is expired'
| 'btc is cancelled'
| 'btc is refunded'
| 'xmr is redeemed'
| 'btc is punished'
| 'safely aborted';
| "quote has been requested"
| "execution setup done"
| "btc is locked"
| "XMR lock transaction transfer proof received"
| "xmr is locked"
| "encrypted signature is sent"
| "btc is redeemed"
| "cancel timelock is expired"
| "btc is cancelled"
| "btc is refunded"
| "xmr is redeemed"
| "btc is punished"
| "safely aborted";
};
}
export function isCliLogAdvancingState(
log: CliLog,
): log is CliLogAdvancingState {
return log.fields.message === 'Advancing state';
return log.fields.message === "Advancing state";
}
export interface CliLogRedeemedXmr extends CliLog {
fields: {
message: 'Successfully transferred XMR to wallet';
message: "Successfully transferred XMR to wallet";
monero_receive_address: string;
txid: string;
};
}
export function isCliLogRedeemedXmr(log: CliLog): log is CliLogRedeemedXmr {
return log.fields.message === 'Successfully transferred XMR to wallet';
return log.fields.message === "Successfully transferred XMR to wallet";
}
export interface YouHaveBeenPunishedCliLog extends CliLog {
fields: {
message: 'You have been punished for not refunding in time';
message: "You have been punished for not refunding in time";
};
}
@ -267,7 +267,7 @@ export function isYouHaveBeenPunishedCliLog(
log: CliLog,
): log is YouHaveBeenPunishedCliLog {
return (
log.fields.message === 'You have been punished for not refunding in time'
log.fields.message === "You have been punished for not refunding in time"
);
}
@ -280,14 +280,14 @@ function getCliLogSpanAttribute<T>(log: CliLog, key: string): T | null {
}
export function getCliLogSpanSwapId(log: CliLog): string | null {
return getCliLogSpanAttribute<string>(log, 'swap_id');
return getCliLogSpanAttribute<string>(log, "swap_id");
}
export function getCliLogSpanLogReferenceId(log: CliLog): string | null {
return (
getCliLogSpanAttribute<string>(log, 'log_reference_id')?.replace(
getCliLogSpanAttribute<string>(log, "log_reference_id")?.replace(
/"/g,
'',
"",
) || null
);
}
@ -301,7 +301,7 @@ export function hasCliLogOneOfMultipleSpans(
export interface CliLogStartedSyncingMoneroWallet extends CliLog {
fields: {
message: 'Syncing Monero wallet';
message: "Syncing Monero wallet";
current_sync_height?: boolean;
};
}
@ -309,18 +309,18 @@ export interface CliLogStartedSyncingMoneroWallet extends CliLog {
export function isCliLogStartedSyncingMoneroWallet(
log: CliLog,
): log is CliLogStartedSyncingMoneroWallet {
return log.fields.message === 'Syncing Monero wallet';
return log.fields.message === "Syncing Monero wallet";
}
export interface CliLogFinishedSyncingMoneroWallet extends CliLog {
fields: {
message: 'Synced Monero wallet';
message: "Synced Monero wallet";
};
}
export interface CliLogFailedToSyncMoneroWallet extends CliLog {
fields: {
message: 'Failed to sync Monero wallet';
message: "Failed to sync Monero wallet";
error: string;
};
}
@ -328,18 +328,18 @@ export interface CliLogFailedToSyncMoneroWallet extends CliLog {
export function isCliLogFailedToSyncMoneroWallet(
log: CliLog,
): log is CliLogFailedToSyncMoneroWallet {
return log.fields.message === 'Failed to sync Monero wallet';
return log.fields.message === "Failed to sync Monero wallet";
}
export function isCliLogFinishedSyncingMoneroWallet(
log: CliLog,
): log is CliLogFinishedSyncingMoneroWallet {
return log.fields.message === 'Monero wallet synced';
return log.fields.message === "Monero wallet synced";
}
export interface CliLogDownloadingMoneroWalletRpc extends CliLog {
fields: {
message: 'Downloading monero-wallet-rpc';
message: "Downloading monero-wallet-rpc";
progress: string;
size: string;
download_url: string;
@ -349,19 +349,19 @@ export interface CliLogDownloadingMoneroWalletRpc extends CliLog {
export function isCliLogDownloadingMoneroWalletRpc(
log: CliLog,
): log is CliLogDownloadingMoneroWalletRpc {
return log.fields.message === 'Downloading monero-wallet-rpc';
return log.fields.message === "Downloading monero-wallet-rpc";
}
export interface CliLogStartedSyncingMoneroWallet extends CliLog {
fields: {
message: 'Syncing Monero wallet';
message: "Syncing Monero wallet";
current_sync_height?: boolean;
};
}
export interface CliLogDownloadingMoneroWalletRpc extends CliLog {
fields: {
message: 'Downloading monero-wallet-rpc';
message: "Downloading monero-wallet-rpc";
progress: string;
size: string;
download_url: string;
@ -370,7 +370,7 @@ export interface CliLogDownloadingMoneroWalletRpc extends CliLog {
export interface CliLogGotNotificationForNewBlock extends CliLog {
fields: {
message: 'Got notification for new block';
message: "Got notification for new block";
block_height: string;
};
}
@ -378,29 +378,36 @@ export interface CliLogGotNotificationForNewBlock extends CliLog {
export function isCliLogGotNotificationForNewBlock(
log: CliLog,
): log is CliLogGotNotificationForNewBlock {
return log.fields.message === 'Got notification for new block';
return log.fields.message === "Got notification for new block";
}
export interface CliLogAttemptingToCooperativelyRedeemXmr extends CliLog {
fields: {
message: 'Attempting to cooperatively redeem XMR after being punished';
message: "Attempting to cooperatively redeem XMR after being punished";
};
}
export function isCliLogAttemptingToCooperativelyRedeemXmr(
log: CliLog,
): log is CliLogAttemptingToCooperativelyRedeemXmr {
return log.fields.message === 'Attempting to cooperatively redeem XMR after being punished';
return (
log.fields.message ===
"Attempting to cooperatively redeem XMR after being punished"
);
}
export interface CliLogAliceHasAcceptedOurRequestToCooperativelyRedeemTheXmr extends CliLog {
export interface CliLogAliceHasAcceptedOurRequestToCooperativelyRedeemTheXmr
extends CliLog {
fields: {
message: 'Alice has accepted our request to cooperatively redeem the XMR';
message: "Alice has accepted our request to cooperatively redeem the XMR";
};
}
export function isCliLogAliceHasAcceptedOurRequestToCooperativelyRedeemTheXmr(
log: CliLog,
): log is CliLogAliceHasAcceptedOurRequestToCooperativelyRedeemTheXmr {
return log.fields.message === 'Alice has accepted our request to cooperatively redeem the XMR';
}
return (
log.fields.message ===
"Alice has accepted our request to cooperatively redeem the XMR"
);
}

View file

@ -1,5 +1,5 @@
import { CliLog, SwapSpawnType } from './cliModel';
import { Provider } from './apiModel';
import { CliLog, SwapSpawnType } from "./cliModel";
import { Provider } from "./apiModel";
export interface SwapSlice {
state: SwapState | null;
@ -20,21 +20,21 @@ export interface SwapState {
}
export enum SwapStateType {
INITIATED = 'initiated',
RECEIVED_QUOTE = 'received quote',
WAITING_FOR_BTC_DEPOSIT = 'waiting for btc deposit',
STARTED = 'started',
BTC_LOCK_TX_IN_MEMPOOL = 'btc lock tx is in mempool',
XMR_LOCK_TX_IN_MEMPOOL = 'xmr lock tx is in mempool',
XMR_LOCKED = 'xmr is locked',
BTC_REDEEMED = 'btc redeemed',
XMR_REDEEM_IN_MEMPOOL = 'xmr redeem tx is in mempool',
PROCESS_EXITED = 'process exited',
BTC_CANCELLED = 'btc cancelled',
BTC_REFUNDED = 'btc refunded',
BTC_PUNISHED = 'btc punished',
ATTEMPTING_COOPERATIVE_REDEEM = 'attempting cooperative redeem',
COOPERATIVE_REDEEM_REJECTED = 'cooperative redeem rejected',
INITIATED = "initiated",
RECEIVED_QUOTE = "received quote",
WAITING_FOR_BTC_DEPOSIT = "waiting for btc deposit",
STARTED = "started",
BTC_LOCK_TX_IN_MEMPOOL = "btc lock tx is in mempool",
XMR_LOCK_TX_IN_MEMPOOL = "xmr lock tx is in mempool",
XMR_LOCKED = "xmr is locked",
BTC_REDEEMED = "btc redeemed",
XMR_REDEEM_IN_MEMPOOL = "xmr redeem tx is in mempool",
PROCESS_EXITED = "process exited",
BTC_CANCELLED = "btc cancelled",
BTC_REFUNDED = "btc refunded",
BTC_PUNISHED = "btc punished",
ATTEMPTING_COOPERATIVE_REDEEM = "attempting cooperative redeem",
COOPERATIVE_REDEEM_REJECTED = "cooperative redeem rejected",
}
export function isSwapState(state?: SwapState | null): state is SwapState {