fix totally broken withdrawal coin selection

This commit is contained in:
Florian Dold 2020-07-16 15:13:52 +05:30
parent 75c5c59316
commit bcd9e2e5ff
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B

View File

@ -162,6 +162,9 @@ export async function getBankWithdrawalInfo(
}; };
} }
/**
* Return denominations that can potentially used for a withdrawal.
*/
async function getPossibleDenoms( async function getPossibleDenoms(
ws: InternalWalletState, ws: InternalWalletState,
exchangeBaseUrl: string, exchangeBaseUrl: string,
@ -458,24 +461,17 @@ export async function selectWithdrawalDenoms(
throw Error(`exchange ${exchangeBaseUrl} details not available`); throw Error(`exchange ${exchangeBaseUrl} details not available`);
} }
console.log("getting possible denoms");
const possibleDenoms = await getPossibleDenoms(ws, exchange.baseUrl);
console.log("got possible denoms");
let allValid = false; let allValid = false;
let selectedDenoms: DenominationSelectionInfo; let selectedDenoms: DenominationSelectionInfo;
// Find a denomination selection for the requested amount.
// If a selected denomination has not been validated yet
// and turns our to be invalid, we try again with the
// reduced set of denominations.
do { do {
allValid = true; allValid = true;
const nextPossibleDenoms = []; const nextPossibleDenoms = await getPossibleDenoms(ws, exchange.baseUrl);
selectedDenoms = getWithdrawDenomList(amount, possibleDenoms); selectedDenoms = getWithdrawDenomList(amount, nextPossibleDenoms);
console.log("got withdraw denom list");
if (!selectedDenoms) {
console;
}
for (const denomSel of selectedDenoms.selectedDenoms) { for (const denomSel of selectedDenoms.selectedDenoms) {
const denom = denomSel.denom; const denom = denomSel.denom;
if (denom.status === DenominationStatus.Unverified) { if (denom.status === DenominationStatus.Unverified) {
@ -488,17 +484,12 @@ export async function selectWithdrawalDenoms(
allValid = false; allValid = false;
} else { } else {
denom.status = DenominationStatus.VerifiedGood; denom.status = DenominationStatus.VerifiedGood;
nextPossibleDenoms.push(denom);
} }
await ws.db.put(Stores.denominations, denom); await ws.db.put(Stores.denominations, denom);
} else {
nextPossibleDenoms.push(denom);
} }
} }
} while (selectedDenoms.selectedDenoms.length > 0 && !allValid); } while (selectedDenoms.selectedDenoms.length > 0 && !allValid);
console.log("returning denoms");
return selectedDenoms; return selectedDenoms;
} }