Skip to content

Commit 7b13915

Browse files
committed
mobx: update types in the mobx models
1 parent d0872b1 commit 7b13915

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

app/src/store/models/batch.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default class Batch {
4848
prevBatchId = '';
4949
clearingPriceRate = 0;
5050
batchTxId = '';
51-
batchTxFeeRateSatPerKw = 0;
51+
batchTxFeeRateSatPerKw = Big(0);
5252
matchedOrders: MatchedOrder[] = [];
5353

5454
// the provided lease duration to filter orders by
@@ -101,21 +101,21 @@ export default class Batch {
101101
/** the total amount of sats earned in this batch */
102102
get earnedSats() {
103103
const pctRate = this._store.api.pool.calcPctRate(
104-
this.clearingPriceRate,
105-
this.leaseDuration,
104+
Big(this.clearingPriceRate),
105+
Big(this.leaseDuration),
106106
);
107107
return this.volume.mul(pctRate);
108108
}
109109

110110
/** the fee in sats/vbyte rounded to the nearest whole number */
111111
get feeLabel() {
112-
return `${Math.round(this.feeInVBytes)}`;
112+
return this.feeInVBytes.round().toString();
113113
}
114114

115115
/** a label containing the batch fee in both sats/kw and sats/vbyte */
116116
get feeDescription() {
117117
// round the fee to 2 decimal places
118-
const fee = Math.round(this.feeInVBytes * 100) / 100;
118+
const fee = this.feeInVBytes.mul(100).round().div(100);
119119
return `${this.batchTxFeeRateSatPerKw} sats/kw - ${fee} sats/vbyte`;
120120
}
121121

@@ -145,8 +145,8 @@ export default class Batch {
145145
/** the batch clearing rate expressed as basis points */
146146
get basisPoints() {
147147
const pct = this._store.api.pool.calcPctRate(
148-
this.clearingPriceRate,
149-
this.leaseDuration,
148+
Big(this.clearingPriceRate),
149+
Big(this.leaseDuration),
150150
);
151151
// convert the percentage to basis points. round up to prevent 0 bps
152152
// which is the case for the first batch on testnet which has a
@@ -173,7 +173,7 @@ export default class Batch {
173173
this.batchId = hex(llmBatch.batchId);
174174
this.prevBatchId = hex(llmBatch.prevBatchId);
175175
this.batchTxId = llmBatch.batchTxId;
176-
this.batchTxFeeRateSatPerKw = llmBatch.batchTxFeeRateSatPerKw;
176+
this.batchTxFeeRateSatPerKw = Big(llmBatch.batchTxFeeRateSatPerKw);
177177
// loop over all markets to limit the orders of this batch to a specific lease duration
178178
llmBatch.matchedMarketsMap.forEach(([duration, market]) => {
179179
// ignore markets for other lease durations

app/src/store/models/lease.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export default class Lease {
1515
premiumSat = Big(0);
1616
executionFeeSat = Big(0);
1717
chainFeeSat = Big(0);
18-
clearingRatePrice = 0;
19-
orderFixedRate = 0;
18+
clearingRatePrice = Big(0);
19+
orderFixedRate = Big(0);
2020
orderNonce = '';
2121
purchased = false;
2222
channelRemoteNodeKey = '';
@@ -45,8 +45,8 @@ export default class Lease {
4545
this.premiumSat = Big(poolLease.premiumSat);
4646
this.executionFeeSat = Big(poolLease.executionFeeSat);
4747
this.chainFeeSat = Big(poolLease.chainFeeSat);
48-
this.clearingRatePrice = poolLease.clearingRatePrice;
49-
this.orderFixedRate = poolLease.orderFixedRate;
48+
this.clearingRatePrice = Big(poolLease.clearingRatePrice);
49+
this.orderFixedRate = Big(poolLease.orderFixedRate);
5050
this.orderNonce = hex(poolLease.orderNonce);
5151
this.purchased = poolLease.purchased;
5252
this.channelRemoteNodeKey = hex(poolLease.channelRemoteNodeKey);

app/src/store/models/order.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ export default class Order {
2727
traderKey = '';
2828
amount = Big(0);
2929
state = 0;
30-
rateFixed = 0;
31-
maxBatchFeeRateSatPerKw = 0;
30+
rateFixed = Big(0);
31+
maxBatchFeeRateSatPerKw = Big(0);
3232
units = 0;
3333
unitsUnfulfilled = 0;
3434
reserved = Big(0);
35-
creationTimestamp = 0;
35+
creationTimestamp = Big(0);
3636
minNodeTier?: Tier = 0;
3737
// custom app values
3838
type: OrderType = OrderType.Bid;
3939
// for bids, this is the minimum. for asks this is the maximum
40-
duration = 0;
40+
duration = Big(0);
4141

4242
constructor(store: Store) {
4343
makeAutoObservable(this, {}, { deep: false, autoBind: true });
@@ -102,7 +102,7 @@ export default class Order {
102102

103103
/** The date this swap was created as a JS Date object */
104104
get createdOn() {
105-
return new Date(this.creationTimestamp / 1000 / 1000);
105+
return new Date(this.creationTimestamp.div(1000).div(1000).toNumber());
106106
}
107107

108108
/** The date this swap was created as formatted string */
@@ -124,15 +124,15 @@ export default class Order {
124124
this.traderKey = hex(poolOrder.traderKey);
125125
this.amount = Big(poolOrder.amt);
126126
this.state = poolOrder.state;
127-
this.rateFixed = poolOrder.rateFixed;
128-
this.maxBatchFeeRateSatPerKw = poolOrder.maxBatchFeeRateSatPerKw;
127+
this.rateFixed = Big(poolOrder.rateFixed);
128+
this.maxBatchFeeRateSatPerKw = Big(poolOrder.maxBatchFeeRateSatPerKw);
129129
this.units = poolOrder.units;
130130
this.unitsUnfulfilled = poolOrder.unitsUnfulfilled;
131131
this.reserved = Big(poolOrder.reservedValueSat);
132-
this.creationTimestamp = poolOrder.creationTimestampNs;
132+
this.creationTimestamp = Big(poolOrder.creationTimestampNs);
133133

134134
this.type = type;
135-
this.duration = duration;
135+
this.duration = Big(duration);
136136
this.minNodeTier = minNodeTier;
137137
}
138138

@@ -149,16 +149,16 @@ export default class Order {
149149
case 'type':
150150
return a.type.toLowerCase() > b.type.toLowerCase() ? 1 : -1;
151151
case 'amount':
152-
return +a.amount.sub(b.amount);
152+
return a.amount.sub(b.amount).toNumber();
153153
case 'rateFixed':
154-
return a.rateFixed - b.rateFixed;
154+
return a.rateFixed.sub(b.rateFixed).toNumber();
155155
case 'duration':
156-
return a.duration - b.duration;
156+
return a.duration.sub(b.duration).toNumber();
157157
case 'stateLabel':
158158
return a.stateLabel.toLowerCase() > b.stateLabel.toLowerCase() ? 1 : -1;
159159
case 'creationTimestamp':
160160
default:
161-
return a.creationTimestamp - b.creationTimestamp;
161+
return a.creationTimestamp.sub(b.creationTimestamp).toNumber();
162162
}
163163
}
164164
}

app/src/store/models/swap.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export default class Swap {
1212
id = '';
1313
type = 0;
1414
amount = Big(0);
15-
initiationTime = 0;
16-
lastUpdateTime = 0;
15+
initiationTime = Big(0);
16+
lastUpdateTime = Big(0);
1717
state = 0;
1818
failureReason = 0;
1919

@@ -107,7 +107,7 @@ export default class Swap {
107107

108108
/** The date this swap was created as a JS Date object */
109109
get createdOn() {
110-
return new Date(this.initiationTime / 1000 / 1000);
110+
return new Date(this.initiationTime.div(1000).div(1000).toNumber());
111111
}
112112

113113
/** The date this swap was created as formatted string */
@@ -117,7 +117,7 @@ export default class Swap {
117117

118118
/** The date this swap was last updated as a JS Date object */
119119
get updatedOn() {
120-
return new Date(this.lastUpdateTime / 1000 / 1000);
120+
return new Date(this.lastUpdateTime.div(1000).div(1000).toNumber());
121121
}
122122

123123
/** The date this swap was last updated as formatted string */
@@ -133,8 +133,8 @@ export default class Swap {
133133
this.id = loopSwap.id;
134134
this.type = loopSwap.type;
135135
this.amount = Big(loopSwap.amt);
136-
this.initiationTime = loopSwap.initiationTime;
137-
this.lastUpdateTime = loopSwap.lastUpdateTime;
136+
this.initiationTime = Big(loopSwap.initiationTime);
137+
this.lastUpdateTime = Big(loopSwap.lastUpdateTime);
138138
this.state = loopSwap.state;
139139
this.failureReason = loopSwap.failureReason;
140140
}
@@ -154,12 +154,12 @@ export default class Swap {
154154
case 'typeName':
155155
return a.typeName.toLowerCase() > b.typeName.toLowerCase() ? 1 : -1;
156156
case 'amount':
157-
return +a.amount.sub(b.amount);
157+
return a.amount.sub(b.amount).toNumber();
158158
case 'initiationTime':
159-
return a.initiationTime - b.initiationTime;
159+
return a.initiationTime.sub(b.initiationTime).toNumber();
160160
case 'lastUpdateTime':
161161
default:
162-
return a.lastUpdateTime - b.lastUpdateTime;
162+
return a.lastUpdateTime.sub(b.lastUpdateTime).toNumber();
163163
}
164164
}
165165

0 commit comments

Comments
 (0)