Skip to content

Commit b8900c9

Browse files
committed
mobx: update types in the mobx stores
1 parent 7b13915 commit b8900c9

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

app/src/store/stores/accountStore.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
values,
99
} from 'mobx';
1010
import { AccountState } from 'types/generated/trader_pb';
11+
import Big from 'big.js';
1112
import copyToClipboard from 'copy-to-clipboard';
1213
import debounce from 'lodash/debounce';
1314
import { hex } from 'util/strings';
@@ -86,7 +87,7 @@ export default class AccountStore {
8687
* @param amount the amount (sats) to fund the account with
8788
* @param expiryBlocks the number of blocks from now to expire the account
8889
*/
89-
async createAccount(amount: number, expiryBlocks: number, confTarget?: number) {
90+
async createAccount(amount: Big, expiryBlocks: number, confTarget?: number) {
9091
this._store.log.info(`creating new account with ${amount}sats`);
9192
try {
9293
const acct = await this._store.api.pool.initAccount(
@@ -142,7 +143,7 @@ export default class AccountStore {
142143
const res = await this._store.api.pool.renewAccount(
143144
acct.traderKey,
144145
expiryBlocks,
145-
feeRate,
146+
Big(feeRate),
146147
);
147148
runInAction(() => {
148149
// the account should always be defined but if not, fetch all accounts as a fallback
@@ -214,7 +215,11 @@ export default class AccountStore {
214215
const acct = this.activeAccount;
215216
this._store.log.info(`depositing ${amount}sats into account ${acct.traderKey}`);
216217

217-
const res = await this._store.api.pool.deposit(acct.traderKey, amount, feeRate);
218+
const res = await this._store.api.pool.deposit(
219+
acct.traderKey,
220+
Big(amount),
221+
feeRate,
222+
);
218223
runInAction(() => {
219224
// the account should always be defined but if not, fetch all accounts as a fallback
220225
if (res.account) {
@@ -238,7 +243,11 @@ export default class AccountStore {
238243
const acct = this.activeAccount;
239244
this._store.log.info(`withdrawing ${amount}sats into account ${acct.traderKey}`);
240245

241-
const res = await this._store.api.pool.withdraw(acct.traderKey, amount, feeRate);
246+
const res = await this._store.api.pool.withdraw(
247+
acct.traderKey,
248+
Big(amount),
249+
feeRate,
250+
);
242251
runInAction(() => {
243252
if (res.account) {
244253
acct.update(res.account);

app/src/store/stores/batchStore.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from 'mobx';
1010
import { NodeTier } from 'types/generated/auctioneerrpc/auctioneer_pb';
1111
import { LeaseDuration } from 'types/state';
12+
import Big from 'big.js';
1213
import { IS_DEV, IS_TEST } from 'config';
1314
import debounce from 'lodash/debounce';
1415
import { hex } from 'util/strings';
@@ -35,7 +36,7 @@ export default class BatchStore {
3536
markets: ObservableMap<LeaseDuration, Market> = observable.map();
3637

3738
/** the timestamp of the next batch in seconds */
38-
nextBatchTimestamp = 0;
39+
nextBatchTimestamp = Big(0);
3940

4041
/** the fee rate (sats/vbyte) estimated by the auctioneer to use for the next batch */
4142
nextFeeRate = 0;
@@ -166,12 +167,12 @@ export default class BatchStore {
166167
try {
167168
const res = await this._store.api.pool.nextBatchInfo();
168169
runInAction(() => {
169-
this.setNextBatchTimestamp(res.clearTimestamp);
170+
this.setNextBatchTimestamp(Big(res.clearTimestamp));
170171
this._store.log.info(
171172
'updated batchStore.nextBatchTimestamp',
172173
this.nextBatchTimestamp,
173174
);
174-
this.setNextFeeRate(res.feeRateSatPerKw);
175+
this.setNextFeeRate(Big(res.feeRateSatPerKw));
175176
this._store.log.info('updated batchStore.nextFeeRate', this.nextFeeRate);
176177
});
177178
} catch (error) {
@@ -254,15 +255,15 @@ export default class BatchStore {
254255
* batched to be processed
255256
* @param timestamp the next batch timestamp in seconds since epoch
256257
*/
257-
setNextBatchTimestamp(timestamp: number) {
258+
setNextBatchTimestamp(timestamp: Big) {
258259
// if the value is the same, then just return immediately
259-
if (this.nextBatchTimestamp === timestamp) return;
260+
if (this.nextBatchTimestamp.eq(timestamp)) return;
260261

261262
this.nextBatchTimestamp = timestamp;
262263

263264
if (this._nextBatchTimer) clearTimeout(this._nextBatchTimer);
264265
// calc the number of ms between now and the next batch timestamp
265-
let ms = timestamp * 1000 - Date.now();
266+
let ms = timestamp.mul(1000).sub(Date.now()).toNumber();
266267
// if the timestamp is somehow in the past, use 10 mins as a default
267268
if (ms < 0) ms = 10 * 60 * 1000;
268269
this._nextBatchTimer = setTimeout(this.fetchLatestBatch, ms + 3000);
@@ -271,9 +272,9 @@ export default class BatchStore {
271272
/**
272273
* sets the nextFeeRate by converting the provided sats/kw to sats/vbyte
273274
*/
274-
setNextFeeRate(satsPerKWeight: number) {
275+
setNextFeeRate(satsPerKWeight: Big) {
275276
const satsPerVbyte = this._store.api.pool.satsPerKWeightToVByte(satsPerKWeight);
276-
this.nextFeeRate = Math.ceil(satsPerVbyte);
277+
this.nextFeeRate = satsPerVbyte.round(0, Big.roundUp).toNumber();
277278
}
278279

279280
startPolling() {

app/src/store/stores/channelStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export default class ChannelStore {
240240
const localPubkey = this._store.nodeStore.pubkey;
241241
const policy = node1Pub === localPubkey ? node2Policy : node1Policy;
242242
if (policy) {
243-
acc[channelId] = policy.feeRateMilliMsat;
243+
acc[channelId] = +Big(policy.feeRateMilliMsat);
244244
}
245245
return acc;
246246
}, data);

app/src/store/stores/orderStore.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export default class OrderStore {
174174
* @param maxBatchFeeRate the maximum batch fee rate to allowed as sats per vByte
175175
*/
176176
async quoteOrder(
177-
amount: number,
177+
amount: Big,
178178
rateFixed: number,
179179
duration: number,
180180
minUnitsMatch: number,
@@ -202,9 +202,9 @@ export default class OrderStore {
202202
return {
203203
ratePerBlock: rateFixed,
204204
ratePercent: 0,
205-
totalExecutionFeeSat: 0,
206-
totalPremiumSat: 0,
207-
worstCaseChainFeeSat: 0,
205+
totalExecutionFeeSat: '0',
206+
totalPremiumSat: '0',
207+
worstCaseChainFeeSat: '0',
208208
};
209209
}
210210
}
@@ -221,7 +221,7 @@ export default class OrderStore {
221221
*/
222222
async submitOrder(
223223
type: OrderType,
224-
amount: number,
224+
amount: Big,
225225
rateFixed: number,
226226
duration: number,
227227
minUnitsMatch: number,

0 commit comments

Comments
 (0)