UNPKG

@frak-labs/core-sdk

Version:

Core SDK of the Frak wallet, low level library to interact directly with the frak ecosystem.

147 lines 7.12 kB
import { a as MerchantReward, c as RuleConditions, d as InteractionTypeKey, f as Currency, r as EstimatedReward, u as TokenAmountType } from "./merchantInformation-BFdhF3De.js"; //#region src/rewards/conditions.d.ts declare function extractMinPurchaseAmount(conditions: RuleConditions): number | undefined; declare function extractStartDate(conditions: RuleConditions): Date | undefined; //#endregion //#region src/rewards/example.d.ts type PercentageReward = Extract<EstimatedReward, { payoutType: "percentage"; }>; type RewardExample = { basket: number; reward: number; }; declare function pickFlatBasket(minPurchase: number | undefined): number; declare function pickTierBasket(minValue: number, maxValue: number | undefined): number; declare function buildPercentageExample(reward: PercentageReward, minPurchase: number | undefined): RewardExample | undefined; declare function buildTierExample(percent: number, minValue: number, maxValue: number | undefined): RewardExample | undefined; //#endregion //#region src/rewards/format.d.ts /** * Format an {@link EstimatedReward} into a human-readable string. * * - `fixed` → e.g. `"5 €"` * - `percentage` → e.g. `"10 %"` * - `tiered` → the richest tier: max token amount (e.g. `"50 €"`) or, when * tiers only carry percentages, the max percent (e.g. `"10 %"`) * * Percentages are always rendered as a `"X %"` string: the backend never sends * a reference basket, so the reward cannot be resolved to a concrete amount * here. Callers that need a worked example use the `example` helpers instead. */ declare function formatEstimatedReward(reward: EstimatedReward, currency?: Currency): string; /** * Format a reward for display, or return `undefined` when it is not worth * advertising. Callers rely on `undefined` to hide a badge / fall back to * other copy. * * A reward is hidden only when it carries no displayable value — a `fixed` or * `tiered` reward whose money value is `0` (e.g. an unknown token price). An * uncapped percentage always renders as `"X %"`, since the percent itself is * meaningful even without a money value. */ declare function formatRewardOrHide(reward: EstimatedReward | undefined, currency?: Currency): string | undefined; /** * Replace the `{REWARD}` placeholder in a text string with a reward value. * If no reward is provided, returns the text with `{REWARD}` stripped. */ declare function applyRewardPlaceholder(text: string, reward: string | undefined): string; //#endregion //#region src/rewards/select.d.ts /** Reward side a surface cares about: the sharer (`referrer`) or the referred * user (`referee`). Drives both campaign ranking and which side is displayed. */ type RewardAudience = "referrer" | "referee"; type DisplayCampaign = { campaign: MerchantReward; status: "live" | "upcoming"; startsAt?: Date; }; type SelectDisplayCampaignOptions = { /** Reference "now" for expiry / start gating; defaults to the current time. */ now?: Date; /** Currency the ranking is expressed in; defaults to EUR. */ currency?: Currency; /** When set, only campaigns triggered by this interaction are considered. */ targetInteraction?: InteractionTypeKey; /** Reward side to rank campaigns by; defaults to `"referrer"`. */ audience?: RewardAudience; }; /** * Pick the single campaign a merchant surface should display. * * Filters out expired (and, when `targetInteraction` is set, non-matching) * campaigns, then prefers the highest-ranked *live* campaign — ranked by the * `audience` reward side in the requested currency. When none has started yet * it falls back to the soonest-starting upcoming campaign (the endpoint does * not gate on the start-date condition, so future-start campaigns come * through). */ declare function selectDisplayCampaign(rewards: readonly MerchantReward[], options?: SelectDisplayCampaignOptions): DisplayCampaign | undefined; /** * The single reward a merchant surface should display: its formatted string * plus the `payoutType` of the underlying reward, so surfaces can adapt their * presentation (e.g. hide percentage rewards, prefix tiered ones with "Up to"). */ type BestReward = { /** Display-ready reward string (e.g. `"5 €"`, `"10 %"`). */ formatted: string; /** Payout type of the selected reward. */ payoutType: EstimatedReward["payoutType"]; /** * Minimum purchase amount gating the reward, formatted with the requested * currency (e.g. `"10 €"`), or `undefined` when the campaign sets no * minimum. */ minPurchaseAmount?: string; /** * Whole-day lockup applied before the reward settles, or `undefined` when * the campaign has no lockup. */ lockupDurationDays?: number; /** * Raw referrer/referee rewards of the selected campaign, surfaced so * consumers can render the full per-audience breakdown (tier rows, * percentage examples) rather than only the headline number. */ referrerReward?: EstimatedReward; refereeReward?: EstimatedReward; /** * Raw minimum purchase value (unformatted), used to build percentage * worked-examples consistent with the campaign's gating. */ minPurchaseValue?: number; }; /** * Pick the best campaign for `options` and resolve its `audience`-side reward * to a formatted string plus its `payoutType`, or `undefined` when there is * nothing worth showing. * * Single entry point shared by every "headline reward" surface (share button, * wallet modal, sharing/install screens) so they all show the same number for * a given merchant and can branch on the payout type. */ declare function selectBestReward(rewards: readonly MerchantReward[], options?: SelectDisplayCampaignOptions): BestReward | undefined; /** * Headline reward string for a merchant: picks the best campaign for `options` * and formats its `audience`-side reward, or returns `undefined` when there is * nothing worth showing. * * Thin wrapper over {@link selectBestReward} for callers that only need the * formatted string. */ declare function formatBestReward(rewards: readonly MerchantReward[], options?: SelectDisplayCampaignOptions): string | undefined; //#endregion //#region src/rewards/value.d.ts /** * Comparable fiat value of a single reward, used to rank rewards against each * other. * * - `fixed` → the token amount in the requested currency * - `tiered` → the highest token amount across tiers * - `percentage` → the capped (`maxAmount`) value when present, otherwise `0` * (an uncapped percentage has no comparable fiat value) */ declare function getRewardValue(reward: EstimatedReward, key: keyof TokenAmountType): number; //#endregion export { type BestReward, type DisplayCampaign, type RewardAudience, type RewardExample, type SelectDisplayCampaignOptions, applyRewardPlaceholder, buildPercentageExample, buildTierExample, extractMinPurchaseAmount, extractStartDate, formatBestReward, formatEstimatedReward, formatRewardOrHide, getRewardValue, pickFlatBasket, pickTierBasket, selectBestReward, selectDisplayCampaign }; //# sourceMappingURL=rewards.d.ts.map