on master help sign in
star release: fix string<->int shenanigans
d1be6c6Fang
src/lib/starRelease.js+22−10
@@ -82,21 +82,28 @@ export async function getConditional(contracts, address) {
82 conditionalSR.getRemainingStars(contracts, address),
82 conditionalSR.getRemainingStars(contracts, address),
83 ]);
83 ]);
84
84
85− if (commitment === null || batches === null) {
85+ if (batches === [] || commitment.total === '0') {
86 return { total: 0, available: 0, withdrawn: 0, batchLimits: [] };
86 return { total: 0, available: 0, withdrawn: 0, batchLimits: [] };
87 }
87 }
88
88
89 const total = remaining.length;
89 const total = remaining.length;
90 let balance = total;
90 let balance = total;
91
91
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+
92 // does not account for forfeiting or withdrawl
95 // does not account for forfeiting or withdrawl
96+ const limits = (
93− const limits = await Promise.all(
97+ await Promise.all(
94− batches.map((_, idx) =>
98+ batches.map((_, idx) =>
95− conditionalSR.getWithdrawLimit(contracts, address, idx)
99+ conditionalSR.getWithdrawLimit(contracts, address, idx)
100+ )
96 )
101 )
97− );
102+ ).map(n => parseInt(n));
98
103
104+ const withdrawn = (
99− const withdrawn = await conditionalSR.getWithdrawn(contracts, address);
105+ await conditionalSR.getWithdrawn(contracts, address)
106+ ).map(n => parseInt(n));
100
107
101 const forfeited = await conditionalSR.getForfeited(contracts, address);
108 const forfeited = await conditionalSR.getForfeited(contracts, address);
102
109
@@ -132,17 +139,22 @@ export async function getConditional(contracts, address) {
132
139
133export async function getLinear(contracts, address) {
140export async function getLinear(contracts, address) {
134 const batch = await linearSR.getBatch(contracts, address);
141 const batch = await linearSR.getBatch(contracts, address);
142+
143+ //NOTE careful, we get the batch data as strings!
144+ const amount = parseInt(batch.amount);
145+ const withdrawn = parseInt(batch.withdrawn);
146+
135− if (batch.amount === 0) {
147+ if (amount === 0) {
136 return { available: 0, withdrawn: 0, total: 0 };
148 return { available: 0, withdrawn: 0, total: 0 };
137 }
149 }
138
150
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);
139 const remaining = (await linearSR.getRemainingStars(contracts, address))
154 const remaining = (await linearSR.getRemainingStars(contracts, address))
140 .length;
155 .length;
141− const { amount, withdrawn } = batch;
142
156
143− const limit = await linearSR.getWithdrawLimit(contracts, address);
144 const available = Math.min(limit - withdrawn, remaining);
157 const available = Math.min(limit - withdrawn, remaining);
145−
146 const total = Math.min(amount, remaining);
158 const total = Math.min(amount, remaining);
147
159
148 return {
160 return {