ramda#o JavaScript Examples

The following examples show how to use ramda#o. 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: staking_payouts.js    From sdk with MIT License 6 votes vote down vote up
{
  FullNodeEndpoint,
  StakingPayoutsAlarmEmailTo,
  InitiatorAccountURI,
  BatchSize,
  ConcurrentRequestsLimit,
  ConcurrentTxLimit,
  RetryTimeout,
  MaxCommission,
  AlarmBalance,
  TxFinalizationTimeout,
  IterationTimeout,
  FinalizeTx,
} = envObj({
  // Address of the node RPC.
  FullNodeEndpoint: notNilAnd(String),
  // List of email addresses separated by comma to send alarm email to.
  StakingPayoutsAlarmEmailTo: notNilAnd(split(",")),
  // Account to send transactions from.
  InitiatorAccountURI: notNilAnd(String),
  // Max batch size.
  BatchSize: o(finiteNumber, defaultTo(5)),
  // Max amount of concurrent requests.
  ConcurrentRequestsLimit: o(finiteNumber, defaultTo(10)),
  // Max amount of concurrent transactions.
  ConcurrentTxLimit: o(finiteNumber, defaultTo(5)),
  // Timeout to wait before retry transaction. In ms.
  RetryTimeout: o(finiteNumber, defaultTo(5e3)),
  // Max commission allowed to be set for validators. Default to 5%.
  MaxCommission: o((val) => new BN(val), defaultTo("50000000")),
  // Min account balance to ring alarm.
  AlarmBalance: notNilAnd((val) => new BN(val)),
  // Time to wait for transaction to be finalized. In ms.
  TxFinalizationTimeout: o(finiteNumber, defaultTo(3e4)),
  // Time to wait for all payments to be sent in an iteration before returning with an error. In ms.
  IterationTimeout: o(finiteNumber, defaultTo(4e5)),
  // Finalize the transaction or just wait for it to be included in the block.
  FinalizeTx: either(equals("true"), o(Boolean, Number)),
})
Example #2
Source File: staking_payouts.js    From sdk with MIT License 6 votes vote down vote up
fetchErasInfo = async (api) => {
  const eras = await api.derive.staking.erasHistoric();
  const indexByEra = indexBy(o((era) => era.toString(), prop("era")));

  const [pointsByEra, rewardsByEra, prefsByEra] = await Promise.all([
    api.derive.staking._erasPoints(eras),
    api.derive.staking._erasRewards(eras),
    api.derive.staking._erasPrefs(eras),
  ]).then(map(indexByEra));

  return {
    eras,
    pointsByEra,
    rewardsByEra,
    prefsByEra,
  };
}
Example #3
Source File: Accordion.js    From lundium with MIT License 6 votes vote down vote up
Accordion = forwardRef(({ openItemIndex, className, children }, ref) => {
	const [indexOpen, setIndexOpen] = useState(openItemIndex);

	useEffect(() => {
		if (!isNaN(openItemIndex)) {
			setIndexOpen(openItemIndex);
		}
	}, [openItemIndex]);

	useImperativeHandle(ref, () => ({ setActiveIndex: setIndexOpen }));

	return (
		<Box className={cx('accordion', className)}>
			{Children.map(children, (child, index) =>
				cond([
					[
						o(equals(AccordionItem), prop('type')),
						clone({ index, indexOpen, setIndexOpen }),
					],
					[T, identity],
				])(child),
			)}
		</Box>
	);
})
Example #4
Source File: helpers.js    From sdk with MIT License 5 votes vote down vote up
finiteNumber = o(
  unless(isFinite, (value) => {
    throw new Error(`Invalid number provided: ${value}`);
  }),
  Number
)
Example #5
Source File: helpers.js    From sdk with MIT License 5 votes vote down vote up
notNilAnd = o(__, assertNotNil)
Example #6
Source File: staking_payouts.js    From sdk with MIT License 5 votes vote down vote up
buildValidatorRewards = curry(
  ({ pointsByEra, rewardsByEra, prefsByEra }, validatorEras) => {
    const stashErasReducer = (acc, { eras, stashId }) => {
      const eraReducer = (acc, era) => {
        const eraKey = era.toString();
        const eraPoints = pointsByEra[eraKey];
        const eraRewards = rewardsByEra[eraKey];
        const eraPrefs = prefsByEra[eraKey];

        if (
          // Points must be greater than 0
          eraPoints?.eraPoints.gt(new BN(0)) &&
          // We must have a stash as a validator in the given era
          eraPoints?.validators[stashId] &&
          // Era rewards should be defined
          eraRewards &&
          // Validator commission in the given era should be acceptable
          eraPrefs.validators[stashId]?.commission?.toBn().lte(MaxCommission)
        ) {
          const reward = eraPoints.validators[stashId]
            .mul(eraRewards.eraReward)
            .div(eraPoints.eraPoints);

          if (!reward.isZero())
            return acc.concat({
              era,
              reward,
            });
        }

        return acc;
      };

      return eras.reduce(eraReducer, acc);
    };

    return o(
      // Filter out stashes with no rewards
      reject(isEmpty),
      // Reduce given stash eras by the stash id
      reduceBy(stashErasReducer, [], prop("stashId"))
    )(validatorEras);
  }
)
Example #7
Source File: Grid.js    From lundium with MIT License 5 votes vote down vote up
shouldSetFlexAutomagically = o(
	isNotEmpty,
	pick(['alignItems', 'alignSelf', 'justifyContent', 'flexDirection']),
)
Example #8
Source File: splitByComma.js    From lundium with MIT License 5 votes vote down vote up
splitByCommaSafe = o(splitByComma, defaultToEmptyString)