wallet-core: better KYC error message
This commit is contained in:
parent
d751f1a267
commit
8e1622a915
File diff suppressed because it is too large
Load Diff
@ -564,6 +564,7 @@ export interface ExchangeRecord {
|
|||||||
|
|
||||||
export enum PlanchetStatus {
|
export enum PlanchetStatus {
|
||||||
Pending = 10 /* ACTIVE_START */,
|
Pending = 10 /* ACTIVE_START */,
|
||||||
|
KycRequired = 11 /* ACTIVE_START + 1 */,
|
||||||
WithdrawalDone = 50 /* DORMANT_START */,
|
WithdrawalDone = 50 /* DORMANT_START */,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +79,9 @@ export interface DetailsMap {
|
|||||||
[TalerErrorCode.WALLET_CRYPTO_WORKER_BAD_REQUEST]: {
|
[TalerErrorCode.WALLET_CRYPTO_WORKER_BAD_REQUEST]: {
|
||||||
detail: string;
|
detail: string;
|
||||||
};
|
};
|
||||||
|
[TalerErrorCode.WALLET_WITHDRAWAL_KYC_REQUIRED]: {
|
||||||
|
// FIXME!
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
type ErrBody<Y> = Y extends keyof DetailsMap ? DetailsMap[Y] : never;
|
type ErrBody<Y> = Y extends keyof DetailsMap ? DetailsMap[Y] : never;
|
||||||
|
@ -47,6 +47,7 @@ import {
|
|||||||
ExchangeWithdrawRequest,
|
ExchangeWithdrawRequest,
|
||||||
ForcedDenomSel,
|
ForcedDenomSel,
|
||||||
getRandomBytes,
|
getRandomBytes,
|
||||||
|
HttpStatusCode,
|
||||||
j2s,
|
j2s,
|
||||||
LibtoolVersion,
|
LibtoolVersion,
|
||||||
Logger,
|
Logger,
|
||||||
@ -527,6 +528,23 @@ async function processPlanchetExchangeRequest(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = await ws.http.postJson(reqUrl, reqBody);
|
const resp = await ws.http.postJson(reqUrl, reqBody);
|
||||||
|
if (resp.status === HttpStatusCode.UnavailableForLegalReasons) {
|
||||||
|
logger.info("withdrawal requires KYC");
|
||||||
|
await ws.db
|
||||||
|
.mktx((x) => [x.planchets])
|
||||||
|
.runReadWrite(async (tx) => {
|
||||||
|
let planchet = await tx.planchets.indexes.byGroupAndIndex.get([
|
||||||
|
withdrawalGroup.withdrawalGroupId,
|
||||||
|
coinIdx,
|
||||||
|
]);
|
||||||
|
if (!planchet) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
planchet.planchetStatus = PlanchetStatus.KycRequired;
|
||||||
|
await tx.planchets.put(planchet);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
const r = await readSuccessResponseJsonOrThrow(
|
const r = await readSuccessResponseJsonOrThrow(
|
||||||
resp,
|
resp,
|
||||||
codecForWithdrawResponse(),
|
codecForWithdrawResponse(),
|
||||||
@ -1126,6 +1144,7 @@ export async function processWithdrawalGroup(
|
|||||||
await Promise.all(work);
|
await Promise.all(work);
|
||||||
|
|
||||||
let numFinished = 0;
|
let numFinished = 0;
|
||||||
|
let numKycRequired = 0;
|
||||||
let finishedForFirstTime = false;
|
let finishedForFirstTime = false;
|
||||||
let errorsPerCoin: Record<number, TalerErrorDetail> = {};
|
let errorsPerCoin: Record<number, TalerErrorDetail> = {};
|
||||||
|
|
||||||
@ -1143,6 +1162,9 @@ export async function processWithdrawalGroup(
|
|||||||
if (x.planchetStatus === PlanchetStatus.WithdrawalDone) {
|
if (x.planchetStatus === PlanchetStatus.WithdrawalDone) {
|
||||||
numFinished++;
|
numFinished++;
|
||||||
}
|
}
|
||||||
|
if (x.planchetStatus === PlanchetStatus.KycRequired) {
|
||||||
|
numKycRequired++;
|
||||||
|
}
|
||||||
if (x.lastError) {
|
if (x.lastError) {
|
||||||
errorsPerCoin[x.coinIdx] = x.lastError;
|
errorsPerCoin[x.coinIdx] = x.lastError;
|
||||||
}
|
}
|
||||||
@ -1156,7 +1178,13 @@ export async function processWithdrawalGroup(
|
|||||||
|
|
||||||
await tx.withdrawalGroups.put(wg);
|
await tx.withdrawalGroups.put(wg);
|
||||||
});
|
});
|
||||||
|
if (numKycRequired > 0) {
|
||||||
|
throw TalerError.fromDetail(
|
||||||
|
TalerErrorCode.WALLET_WITHDRAWAL_KYC_REQUIRED,
|
||||||
|
{},
|
||||||
|
`KYC check required for withdrawal (not yet implemented in wallet-core)`,
|
||||||
|
);
|
||||||
|
}
|
||||||
if (numFinished != numTotalCoins) {
|
if (numFinished != numTotalCoins) {
|
||||||
throw TalerError.fromDetail(
|
throw TalerError.fromDetail(
|
||||||
TalerErrorCode.WALLET_WITHDRAWAL_GROUP_INCOMPLETE,
|
TalerErrorCode.WALLET_WITHDRAWAL_GROUP_INCOMPLETE,
|
||||||
|
Loading…
Reference in New Issue
Block a user