wallet-core: report supportedAgeGroups
This commit is contained in:
parent
a0305884eb
commit
d63a773bf5
@ -1025,6 +1025,23 @@ export namespace AgeRestriction {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the starting points for age groups in the mask.
|
||||||
|
*/
|
||||||
|
export function getAgeGroupsFromMask(mask: number): number[] {
|
||||||
|
const groups: number[] = [];
|
||||||
|
let age = 1;
|
||||||
|
let m = mask >> 1;
|
||||||
|
while (m > 0) {
|
||||||
|
if (m & 1) {
|
||||||
|
groups.push(age);
|
||||||
|
}
|
||||||
|
m = m >> 1;
|
||||||
|
age++;
|
||||||
|
}
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
|
||||||
export function getAgeGroupIndex(mask: number, age: number): number {
|
export function getAgeGroupIndex(mask: number, age: number): number {
|
||||||
invariant((mask & 1) === 1);
|
invariant((mask & 1) === 1);
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
@ -919,6 +919,7 @@ export interface ExchangeListItem {
|
|||||||
paytoUris: string[];
|
paytoUris: string[];
|
||||||
tosStatus: ExchangeTosStatus;
|
tosStatus: ExchangeTosStatus;
|
||||||
exchangeStatus: ExchangeEntryStatus;
|
exchangeStatus: ExchangeEntryStatus;
|
||||||
|
supportedAgeGroups: number[];
|
||||||
/**
|
/**
|
||||||
* Permanently added to the wallet, as opposed to just
|
* Permanently added to the wallet, as opposed to just
|
||||||
* temporarily queried.
|
* temporarily queried.
|
||||||
@ -998,6 +999,7 @@ export const codecForExchangeListItem = (): Codec<ExchangeListItem> =>
|
|||||||
.property("tosStatus", codecForAny())
|
.property("tosStatus", codecForAny())
|
||||||
.property("exchangeStatus", codecForAny())
|
.property("exchangeStatus", codecForAny())
|
||||||
.property("permanent", codecForBoolean())
|
.property("permanent", codecForBoolean())
|
||||||
|
.property("supportedAgeGroups", codecForList(codecForNumber()))
|
||||||
.build("ExchangeListItem");
|
.build("ExchangeListItem");
|
||||||
|
|
||||||
export const codecForExchangesListResponse = (): Codec<ExchangesListResponse> =>
|
export const codecForExchangesListResponse = (): Codec<ExchangesListResponse> =>
|
||||||
|
@ -473,6 +473,11 @@ export interface ExchangeDetailsRecord {
|
|||||||
| undefined;
|
| undefined;
|
||||||
|
|
||||||
wireInfo: WireInfo;
|
wireInfo: WireInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Age restrictions supported by the exchange (bitmask).
|
||||||
|
*/
|
||||||
|
ageMask?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ExchangeTosRecord {
|
export interface ExchangeTosRecord {
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
* Imports.
|
* Imports.
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
|
AgeRestriction,
|
||||||
AmountJson,
|
AmountJson,
|
||||||
Amounts,
|
Amounts,
|
||||||
CoinRefreshRequest,
|
CoinRefreshRequest,
|
||||||
@ -365,6 +366,7 @@ export function makeExchangeListItem(
|
|||||||
paytoUris: [],
|
paytoUris: [],
|
||||||
exchangeStatus: ExchangeEntryStatus.Unknown,
|
exchangeStatus: ExchangeEntryStatus.Unknown,
|
||||||
permanent: r.permanent,
|
permanent: r.permanent,
|
||||||
|
supportedAgeGroups: [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
let exchangeStatus;
|
let exchangeStatus;
|
||||||
@ -376,5 +378,8 @@ export function makeExchangeListItem(
|
|||||||
paytoUris: exchangeDetails.wireInfo.accounts.map((x) => x.payto_uri),
|
paytoUris: exchangeDetails.wireInfo.accounts.map((x) => x.payto_uri),
|
||||||
exchangeStatus,
|
exchangeStatus,
|
||||||
permanent: r.permanent,
|
permanent: r.permanent,
|
||||||
|
supportedAgeGroups: exchangeDetails.ageMask
|
||||||
|
? AgeRestriction.getAgeGroupsFromMask(exchangeDetails.ageMask)
|
||||||
|
: [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -76,6 +76,7 @@ import {
|
|||||||
runOperationHandlerForResult,
|
runOperationHandlerForResult,
|
||||||
} from "../util/retries.js";
|
} from "../util/retries.js";
|
||||||
import { WALLET_EXCHANGE_PROTOCOL_VERSION } from "../versions.js";
|
import { WALLET_EXCHANGE_PROTOCOL_VERSION } from "../versions.js";
|
||||||
|
import { isWithdrawableDenom } from "./withdraw.js";
|
||||||
|
|
||||||
const logger = new Logger("exchanges.ts");
|
const logger = new Logger("exchanges.ts");
|
||||||
|
|
||||||
@ -657,6 +658,14 @@ export async function updateExchangeFromUrlHandler(
|
|||||||
|
|
||||||
let detailsPointerChanged = false;
|
let detailsPointerChanged = false;
|
||||||
|
|
||||||
|
let ageMask = 0;
|
||||||
|
for (const x of keysInfo.currentDenominations) {
|
||||||
|
if (isWithdrawableDenom(x) && x.denomPub.age_mask != 0) {
|
||||||
|
ageMask = x.denomPub.age_mask;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const updated = await ws.db
|
const updated = await ws.db
|
||||||
.mktx((x) => [
|
.mktx((x) => [
|
||||||
x.exchanges,
|
x.exchanges,
|
||||||
@ -699,6 +708,7 @@ export async function updateExchangeFromUrlHandler(
|
|||||||
wireInfo,
|
wireInfo,
|
||||||
tosCurrentEtag: tosDownload.tosEtag,
|
tosCurrentEtag: tosDownload.tosEtag,
|
||||||
tosAccepted: existingTosAccepted,
|
tosAccepted: existingTosAccepted,
|
||||||
|
ageMask,
|
||||||
};
|
};
|
||||||
if (existingDetails?.rowId) {
|
if (existingDetails?.rowId) {
|
||||||
newDetails.rowId = existingDetails.rowId;
|
newDetails.rowId = existingDetails.rowId;
|
||||||
|
Loading…
Reference in New Issue
Block a user