@@ -65,21 +65,36 @@ function generateLinearWithdrawTxs(contracts, amount, to) {
67export async function getConditional(contracts, address) {
67export async function getConditional(contracts, address) {
68− const [commitment, batches] = await Promise.all([
68+ const [commitment, batches, remaining] = await Promise.all([
69 conditionalSR.getCommitment(contracts, address),
69 conditionalSR.getCommitment(contracts, address),
70 conditionalSR.getBatches(contracts, address),
70 conditionalSR.getBatches(contracts, address),
71+ conditionalSR.getRemainingStars(contracts, address),
73 if (commitment === null || batches === null) {
74 if (commitment === null || batches === null) {
74 return { total: 0, available: 0, withdrawn: 0, batchLimits: [] };
75 return { total: 0, available: 0, withdrawn: 0, batchLimits: [] };
77− const { total } = commitment;
78+ const forfeited = await conditionalSR.getForfeited(contracts, address);
79+ const total = remaining.length;
78− const withdrawLimits = await Promise.all(
82+ const withdrawLimits = await batches.reduce(async (p, _, idx) => {
79− batches.map((_, idx) =>
83+ const acc = await p;
84+ if (forfeited[idx] || balance === 0) {
80− conditionalSR.getWithdrawLimit(contracts, address, idx)
87+ const limit = await conditionalSR.getWithdrawLimit(contracts, address, idx);
81− )
88+ if (limit <= balance) {
82− );
89+ balance -= limit;
90+ return [...acc, limit];
92+ const remaining = balance;
95+ return [...acc, remaining];
96+ }, Promise.resolve([]));
83 const available = withdrawLimits.reduce((acc, val) => acc + val, 0);
98 const available = withdrawLimits.reduce((acc, val) => acc + val, 0);
85 const withdrawnAmounts = await conditionalSR.getWithdrawn(contracts, address);
100 const withdrawnAmounts = await conditionalSR.getWithdrawn(contracts, address);
@@ -93,9 +108,18 @@ export async function getConditional(contracts, address) {
95export async function getLinear(contracts, address) {
110export async function getLinear(contracts, address) {
111+ const remaining = (await linearSR.getRemainingStars(contracts, address))
113+ const batch = await linearSR.getBatch(contracts, address);
114+ const { amount, withdrawn } = batch;
116+ // Contract errors on withdrawing from a user that does not have any
96− const { amount, withdrawn } = await linearSR.getBatch(contracts, address);
119+ ? Math.min(await linearSR.getWithdrawLimit(contracts, address), remaining)
122+ const total = Math.min(amount, remaining);
98− const available = // Contract errors on withdrawing from a user that does not have any
99− amount > 0 ? await linearSR.getWithdrawLimit(contracts, address) : 0;
100− return { available, withdrawn, total: amount };
124+ return { available, withdrawn, total };