@polkadot/util#BN_BILLION TypeScript Examples
The following examples show how to use
@polkadot/util#BN_BILLION.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: useStakerPayouts.ts From crust-apps with Apache License 2.0 | 6 votes |
export default function useStakerPayouts (): BN {
const { api } = useApi();
const migrateEraOpt = useCall<Option<EraIndex>>(api.query.staking?.migrateEra);
return useMemo(
() => (migrateEraOpt && migrateEraOpt.isSome && migrateEraOpt.unwrap()) || (
isFunction(api.tx.staking.payoutStakers)
? BN_ZERO
: BN_BILLION
),
[api, migrateEraOpt]
);
}
Example #2
Source File: ChartPrefs.tsx From crust-apps with Apache License 2.0 | 6 votes |
function extractPrefs (prefs: DeriveStakerPrefs[] = []): ChartInfo {
const labels: string[] = [];
const avgSet: LineDataEntry = [];
const idxSet: LineDataEntry = [];
let avgCount = 0;
let total = 0;
prefs.forEach(({ era, validatorPrefs }): void => {
// @ts-ignore
const comm = validatorPrefs.guarantee_fee.unwrap().mul(MULT).div(BN_BILLION).toNumber() / 100;
total += comm;
labels.push(era.toHuman());
if (comm !== 0) {
avgCount++;
}
avgSet.push((avgCount ? Math.ceil(total * 100 / avgCount) : 0) / 100);
idxSet.push(comm);
});
return {
chart: [idxSet, avgSet],
labels
};
}
Example #3
Source File: useWeightFee.ts From subscan-multisig-react with Apache License 2.0 | 6 votes |
export function useWeightFee(weight: BN | number, apiOverride?: ApiPromise | null): BN {
const { api } = useApi();
return useMemo(
() =>
isUndefined(apiOverride) || apiOverride
? (((apiOverride || api).consts.transactionPayment?.weightToFee as unknown as any[]) || []).reduce(
(acc, { coeffFrac, coeffInteger, degree, negative }: WeightToFeeCoefficient): BN => {
const w = bnToBn(weight).pow(degree);
const frac = coeffFrac.mul(w).div(BN_BILLION);
const integer = coeffInteger.mul(w);
if (negative.isTrue) {
acc.isub(frac);
acc.isub(integer);
} else {
acc.iadd(frac);
acc.iadd(integer);
}
return acc;
},
new BN(0)
)
: BN_ZERO,
[api, apiOverride, weight]
);
}