consolidate wallet sync status into shared WalletSyncStatus type.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { ServiceUnavailableException } from '@nestjs/common';
|
import { ServiceUnavailableException } from '@nestjs/common';
|
||||||
import type { ConfigService } from '@nestjs/config';
|
import type { ConfigService } from '@nestjs/config';
|
||||||
import { BitcoinWalletSyncStatus } from '../types/BitcoinWalletSyncStatus';
|
import { WalletSyncStatus } from '../../../types/wallet/WalletSyncStatus';
|
||||||
import type { ElectrumWalletRpcClient } from './ElectrumWalletRpcClient';
|
import type { ElectrumWalletRpcClient } from './ElectrumWalletRpcClient';
|
||||||
import { BitcoinWalletAdminService } from './BitcoinWalletAdminService';
|
import { BitcoinWalletAdminService } from './BitcoinWalletAdminService';
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ describe('BitcoinWalletAdminService', () => {
|
|||||||
rpcVersion: '4.8.1',
|
rpcVersion: '4.8.1',
|
||||||
blockHeight: 900_000,
|
blockHeight: 900_000,
|
||||||
serverHeight: 900_000,
|
serverHeight: 900_000,
|
||||||
syncStatus: BitcoinWalletSyncStatus.Synced,
|
syncStatus: WalletSyncStatus.Synced,
|
||||||
balanceBtc: '0.00150000',
|
balanceBtc: '0.00150000',
|
||||||
confirmedBalanceBtc: '0.00150000'
|
confirmedBalanceBtc: '0.00150000'
|
||||||
})
|
})
|
||||||
@@ -63,7 +63,7 @@ describe('BitcoinWalletAdminService', () => {
|
|||||||
|
|
||||||
const status = await service.getStatus();
|
const status = await service.getStatus();
|
||||||
|
|
||||||
expect(status.syncStatus).toBe(BitcoinWalletSyncStatus.Syncing);
|
expect(status.syncStatus).toBe(WalletSyncStatus.Syncing);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws when RPC calls fail', async () => {
|
it('throws when RPC calls fail', async () => {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Injectable, ServiceUnavailableException } from '@nestjs/common';
|
|||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { convertBtcAtomicToBtc } from '../../../utils/bitcoin/convertBtcAtomicToBtc';
|
import { convertBtcAtomicToBtc } from '../../../utils/bitcoin/convertBtcAtomicToBtc';
|
||||||
import type { Config } from '../../../types/Config';
|
import type { Config } from '../../../types/Config';
|
||||||
import { BitcoinWalletSyncStatus } from '../types/BitcoinWalletSyncStatus';
|
import { WalletSyncStatus } from '../../../types/wallet/WalletSyncStatus';
|
||||||
import type { BitcoinWalletStatusView } from '../types/BitcoinWalletStatusView';
|
import type { BitcoinWalletStatusView } from '../types/BitcoinWalletStatusView';
|
||||||
import { ElectrumWalletRpcClient } from './ElectrumWalletRpcClient';
|
import { ElectrumWalletRpcClient } from './ElectrumWalletRpcClient';
|
||||||
|
|
||||||
@@ -47,15 +47,15 @@ export class BitcoinWalletAdminService {
|
|||||||
isSynchronized: boolean,
|
isSynchronized: boolean,
|
||||||
blockHeight: number | null,
|
blockHeight: number | null,
|
||||||
serverHeight: number | null
|
serverHeight: number | null
|
||||||
): BitcoinWalletSyncStatus {
|
): WalletSyncStatus {
|
||||||
if (isSynchronized) {
|
if (isSynchronized) {
|
||||||
return BitcoinWalletSyncStatus.Synced;
|
return WalletSyncStatus.Synced;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blockHeight === null || serverHeight === null) {
|
if (blockHeight === null || serverHeight === null) {
|
||||||
return BitcoinWalletSyncStatus.Unknown;
|
return WalletSyncStatus.Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
return BitcoinWalletSyncStatus.Syncing;
|
return WalletSyncStatus.Syncing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { ElectrumNetwork } from '../../../types/ElectrumNetwork';
|
import { ElectrumNetwork } from '../../../types/ElectrumNetwork';
|
||||||
import { BitcoinWalletSyncStatus } from './BitcoinWalletSyncStatus';
|
import { WalletSyncStatus } from '../../../types/wallet/WalletSyncStatus';
|
||||||
|
|
||||||
export interface BitcoinWalletStatusView {
|
export interface BitcoinWalletStatusView {
|
||||||
network: ElectrumNetwork;
|
network: ElectrumNetwork;
|
||||||
rpcVersion: string;
|
rpcVersion: string;
|
||||||
blockHeight: number | null;
|
blockHeight: number | null;
|
||||||
serverHeight: number | null;
|
serverHeight: number | null;
|
||||||
syncStatus: BitcoinWalletSyncStatus;
|
syncStatus: WalletSyncStatus;
|
||||||
balanceBtc: string;
|
balanceBtc: string;
|
||||||
confirmedBalanceBtc: string;
|
confirmedBalanceBtc: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
export enum BitcoinWalletSyncStatus {
|
|
||||||
Synced = 'synced',
|
|
||||||
Syncing = 'syncing',
|
|
||||||
Unknown = 'unknown'
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@ import { BadRequestException, ServiceUnavailableException } from '@nestjs/common
|
|||||||
import type { ConfigService } from '@nestjs/config';
|
import type { ConfigService } from '@nestjs/config';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import type { AuthService } from '../../auth/services/AuthService';
|
import type { AuthService } from '../../auth/services/AuthService';
|
||||||
import { MoneroWalletSyncStatus } from '../types/MoneroWalletSyncStatus';
|
import { WalletSyncStatus } from '../../../types/wallet/WalletSyncStatus';
|
||||||
import type { MoneroWalletRpcClient } from './MoneroWalletRpcClient';
|
import type { MoneroWalletRpcClient } from './MoneroWalletRpcClient';
|
||||||
import { MoneroWalletAdminService } from './MoneroWalletAdminService';
|
import { MoneroWalletAdminService } from './MoneroWalletAdminService';
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ describe('MoneroWalletAdminService', () => {
|
|||||||
rpcVersion: '0.18.3.1',
|
rpcVersion: '0.18.3.1',
|
||||||
walletHeight: 3_000_000,
|
walletHeight: 3_000_000,
|
||||||
daemonHeight: 3_000_000,
|
daemonHeight: 3_000_000,
|
||||||
syncStatus: MoneroWalletSyncStatus.Synced,
|
syncStatus: WalletSyncStatus.Synced,
|
||||||
balanceXmr: '2.00000000',
|
balanceXmr: '2.00000000',
|
||||||
unlockedBalanceXmr: '1.00000000'
|
unlockedBalanceXmr: '1.00000000'
|
||||||
})
|
})
|
||||||
@@ -137,7 +137,7 @@ describe('MoneroWalletAdminService', () => {
|
|||||||
|
|
||||||
const status = await service.getStatus();
|
const status = await service.getStatus();
|
||||||
|
|
||||||
expect(status.syncStatus).toBe(MoneroWalletSyncStatus.Unknown);
|
expect(status.syncStatus).toBe(WalletSyncStatus.Unknown);
|
||||||
expect(status.daemonHeight).toBeNull();
|
expect(status.daemonHeight).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -149,7 +149,7 @@ describe('MoneroWalletAdminService', () => {
|
|||||||
|
|
||||||
const status = await service.getStatus();
|
const status = await service.getStatus();
|
||||||
|
|
||||||
expect(status.syncStatus).toBe(MoneroWalletSyncStatus.Synced);
|
expect(status.syncStatus).toBe(WalletSyncStatus.Synced);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws when reveal seed RPC fails', async () => {
|
it('throws when reveal seed RPC fails', async () => {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import type { Config } from '../../../types/Config';
|
|||||||
import type { MoneroDaemonGetInfoResult } from '../types/MoneroDaemonGetInfoResult';
|
import type { MoneroDaemonGetInfoResult } from '../types/MoneroDaemonGetInfoResult';
|
||||||
import type { MoneroWalletRevealSeedResult } from '../types/MoneroWalletRevealSeedResult';
|
import type { MoneroWalletRevealSeedResult } from '../types/MoneroWalletRevealSeedResult';
|
||||||
import type { MoneroWalletStatusView } from '../types/MoneroWalletStatusView';
|
import type { MoneroWalletStatusView } from '../types/MoneroWalletStatusView';
|
||||||
import { MoneroWalletSyncStatus } from '../types/MoneroWalletSyncStatus';
|
import { WalletSyncStatus } from '../../../types/wallet/WalletSyncStatus';
|
||||||
import type { MoneroWalletWithdrawResult } from '../types/MoneroWalletWithdrawResult';
|
import type { MoneroWalletWithdrawResult } from '../types/MoneroWalletWithdrawResult';
|
||||||
import { MoneroWalletRpcClient } from './MoneroWalletRpcClient';
|
import { MoneroWalletRpcClient } from './MoneroWalletRpcClient';
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ export class MoneroWalletAdminService {
|
|||||||
throw new BadRequestException('No unlocked balance to withdraw.');
|
throw new BadRequestException('No unlocked balance to withdraw.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.resolveSyncStatus(walletHeight, daemonHeight) !== MoneroWalletSyncStatus.Synced) {
|
if (this.resolveSyncStatus(walletHeight, daemonHeight) !== WalletSyncStatus.Synced) {
|
||||||
throw new BadRequestException('Wallet is still syncing. Try again after sync completes.');
|
throw new BadRequestException('Wallet is still syncing. Try again after sync completes.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,11 +125,11 @@ export class MoneroWalletAdminService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private resolveSyncStatus(walletHeight: number, daemonHeight: number | null): MoneroWalletSyncStatus {
|
private resolveSyncStatus(walletHeight: number, daemonHeight: number | null): WalletSyncStatus {
|
||||||
if (daemonHeight === null) {
|
if (daemonHeight === null) {
|
||||||
return MoneroWalletSyncStatus.Unknown;
|
return WalletSyncStatus.Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
return walletHeight >= daemonHeight - 1 ? MoneroWalletSyncStatus.Synced : MoneroWalletSyncStatus.Syncing;
|
return walletHeight >= daemonHeight - 1 ? WalletSyncStatus.Synced : WalletSyncStatus.Syncing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { MoneroNetwork } from '../../../types/MoneroNetwork';
|
import { MoneroNetwork } from '../../../types/MoneroNetwork';
|
||||||
import { MoneroWalletSyncStatus } from './MoneroWalletSyncStatus';
|
import { WalletSyncStatus } from '../../../types/wallet/WalletSyncStatus';
|
||||||
|
|
||||||
export interface MoneroWalletStatusView {
|
export interface MoneroWalletStatusView {
|
||||||
network: MoneroNetwork;
|
network: MoneroNetwork;
|
||||||
rpcVersion: string;
|
rpcVersion: string;
|
||||||
walletHeight: number;
|
walletHeight: number;
|
||||||
daemonHeight: number | null;
|
daemonHeight: number | null;
|
||||||
syncStatus: MoneroWalletSyncStatus;
|
syncStatus: WalletSyncStatus;
|
||||||
balanceXmr: string;
|
balanceXmr: string;
|
||||||
unlockedBalanceXmr: string;
|
unlockedBalanceXmr: string;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
export enum MoneroWalletSyncStatus {
|
export enum WalletSyncStatus {
|
||||||
Synced = 'synced',
|
Synced = 'synced',
|
||||||
Syncing = 'syncing',
|
Syncing = 'syncing',
|
||||||
Unknown = 'unknown'
|
Unknown = 'unknown'
|
||||||
Reference in New Issue
Block a user