on master help sign in
star release: fix string<->int shenanigans

For linear releases, this was causing us false positives on the "does this address have a lockup" check. Subsequently calling the withdrawe limit function for an address without a lockup would result in a contract-side exception being thrown due to the division by zero. This exception wasn't getting handled properly, and prevented users with conditional lockups from actually viewing those in Bridge. So now we make sure to diligently convert received values into actual integers, instead of the strings we get them as. For conditional releases, this wasn't actively causing any problems (that we were aware of), but we make similar changes there anyway, for peace of mind.

commitd1be6c69c16024c46aa8847acb24ec402179b459 authorFang <git@fang.io> dateThu 12 Aug 2021, 23:49 (5 years ago) parent2d969f1
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 {