on master help sign in
Merge pull request #602 from urbit/m/limit-unbreaker

star release: fix string<->int shenanigans

commitd19634ceebe4c22ac325065f3add40720727fab8 authorfang <github@fang.io> dateFri 13 Aug 2021, 00:09 (5 years ago) parent2d969f1d1be6c6
1 file changed+22−10
src/lib/starRelease.js+22−10
src/lib/starRelease.js+22−10
@@ -82,21 +82,28 @@ export async function getConditional(contracts, address) {
8282 conditionalSR.getRemainingStars(contracts, address),
8383 ]);
8484
85− if (commitment === null || batches === null) {
85+ if (batches === [] || commitment.total === '0') {
8686 return { total: 0, available: 0, withdrawn: 0, batchLimits: [] };
8787 }
8888
8989 const total = remaining.length;
9090 let balance = total;
9191
92+ //NOTE we don't strictly need to convert the received number-strings to
93+ // integers, but it helps keep the shenanigans at bay.
94+
9295 // does not account for forfeiting or withdrawl
93− const limits = await Promise.all(
94− batches.map((_, idx) =>
95− conditionalSR.getWithdrawLimit(contracts, address, idx)
96+ const limits = (
97+ await Promise.all(
98+ batches.map((_, idx) =>
99+ conditionalSR.getWithdrawLimit(contracts, address, idx)
100+ )
96101 )
97− );
102+ ).map(n => parseInt(n));
98103
99− const withdrawn = await conditionalSR.getWithdrawn(contracts, address);
104+ const withdrawn = (
105+ await conditionalSR.getWithdrawn(contracts, address)
106+ ).map(n => parseInt(n));
100107
101108 const forfeited = await conditionalSR.getForfeited(contracts, address);
102109
@@ -132,17 +139,22 @@ export async function getConditional(contracts, address) {
132139
133140export async function getLinear(contracts, address) {
134141 const batch = await linearSR.getBatch(contracts, address);
135− if (batch.amount === 0) {
142+
143+ //NOTE careful, we get the batch data as strings!
144+ const amount = parseInt(batch.amount);
145+ const withdrawn = parseInt(batch.withdrawn);
146+
147+ if (amount === 0) {
136148 return { available: 0, withdrawn: 0, total: 0 };
137149 }
138150
151+ //NOTE be careful, getting the withdraw limit for an address that doesn't
152+ // have a lockup throws an exception!
153+ const limit = await linearSR.getWithdrawLimit(contracts, address);
139154 const remaining = (await linearSR.getRemainingStars(contracts, address))
140155 .length;
141− const { amount, withdrawn } = batch;
142156
143− const limit = await linearSR.getWithdrawLimit(contracts, address);
144157 const available = Math.min(limit - withdrawn, remaining);
145−
146158 const total = Math.min(amount, remaining);
147159
148160 return {