@polkadot/types/interfaces#StakingLedger TypeScript Examples

The following examples show how to use @polkadot/types/interfaces#StakingLedger. 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: useOwnStashes.ts    From crust-apps with Apache License 2.0 6 votes vote down vote up
function getStashes (allAccounts: string[], ownBonded: Option<AccountId>[], ownLedger: Option<StakingLedger>[]): [string, IsInKeyring][] {
  const result: [string, IsInKeyring][] = [];

  ownBonded.forEach((value, index): void => {
    value.isSome && result.push([allAccounts[index], true]);
  });

  ownLedger.forEach((ledger): void => {
    if (ledger.isSome) {
      const stashId = ledger.unwrap().stash.toString();

      !result.some(([accountId]) => accountId === stashId) && result.push([stashId, false]);
    }
  });

  return result;
}
Example #2
Source File: useOwnStashes.ts    From crust-apps with Apache License 2.0 6 votes vote down vote up
export function useOwnStashes (): [string, IsInKeyring][] | undefined {
  const { allAccounts, hasAccounts } = useAccounts();
  const { api } = useApi();
  const ownBonded = useCall<Option<AccountId>[]>(hasAccounts && api.query.staking?.bonded.multi, [allAccounts]);
  const ownLedger = useCall<Option<StakingLedger>[]>(hasAccounts && api.query.staking?.ledger.multi, [allAccounts]);

  return useMemo(
    () => hasAccounts
      ? ownBonded && ownLedger
        ? getStashes(allAccounts, ownBonded, ownLedger)
        : undefined
      : [],
    [allAccounts, hasAccounts, ownBonded, ownLedger]
  );
}
Example #3
Source File: Bonded.tsx    From crust-apps with Apache License 2.0 6 votes vote down vote up
function BondedDisplay ({ children, className = '', label, params }: Props): React.ReactElement<Props> {
  const { api } = useApi();
  const controllerId = useCall<AccountId | null>(api.query.staking?.bonded, [params], transformController);
  const stakingLedger = useCall<StakingLedger | null>(controllerId && api.query.staking?.ledger, [controllerId], transformLedger);

  return (
    <FormatBalance
      className={className}
      label={label}
      value={stakingLedger?.active}
    >
      {children}
    </FormatBalance>
  );
}
Example #4
Source File: useOwnStashes.ts    From subscan-multisig-react with Apache License 2.0 6 votes vote down vote up
function getStashes(
  allAccounts: string[],
  ownBonded: Option<AccountId>[],
  ownLedger: Option<StakingLedger>[]
): [string, IsInKeyring][] {
  const result: [string, IsInKeyring][] = [];

  ownBonded.forEach((value, index): void => {
    // eslint-disable-next-line
    value.isSome && result.push([allAccounts[index], true]);
  });

  ownLedger.forEach((ledger): void => {
    if (ledger.isSome) {
      const stashId = ledger.unwrap().stash.toString();

      // eslint-disable-next-line
      !result.some(([accountId]) => accountId === stashId) && result.push([stashId, false]);
    }
  });

  return result;
}
Example #5
Source File: useOwnStashes.ts    From subscan-multisig-react with Apache License 2.0 6 votes vote down vote up
export function useOwnStashes(): [string, IsInKeyring][] | undefined {
  const { allAccounts, hasAccounts } = useAccounts();
  const { api } = useApi();
  const ownBonded = useCall<Option<AccountId>[]>(hasAccounts && api.query.staking?.bonded.multi, [allAccounts]);
  const ownLedger = useCall<Option<StakingLedger>[]>(hasAccounts && api.query.staking?.ledger.multi, [allAccounts]);

  return useMemo(
    () => (hasAccounts ? (ownBonded && ownLedger ? getStashes(allAccounts, ownBonded, ownLedger) : undefined) : []),
    [allAccounts, hasAccounts, ownBonded, ownLedger]
  );
}
Example #6
Source File: Bonded.tsx    From subscan-multisig-react with Apache License 2.0 6 votes vote down vote up
function BondedDisplay({ children, className = '', label, params }: Props): React.ReactElement<Props> {
  const { api } = useApi();
  const controllerId = useCall<AccountId | null>(api.query.staking?.bonded, [params], transformController);
  const stakingLedger = useCall<StakingLedger | null>(
    controllerId && api.query.staking?.ledger,
    [controllerId],
    transformLedger
  );

  return (
    <FormatBalance className={className} label={label} value={stakingLedger?.active}>
      {children}
    </FormatBalance>
  );
}
Example #7
Source File: InputValidationController.tsx    From crust-apps with Apache License 2.0 5 votes vote down vote up
transformStash = {
  transform: (value: Option<StakingLedger>): string | null =>
    value.isSome
      ? value.unwrap().stash.toString()
      : null
}
Example #8
Source File: Guaranteeable.tsx    From crust-apps with Apache License 2.0 5 votes vote down vote up
transformLedger = {
  transform: (value: Option<StakingLedger>): Balance | null =>
    value.isSome
      ? value.unwrap().active.unwrap()
      : null
}
Example #9
Source File: index.tsx    From crust-apps with Apache License 2.0 5 votes vote down vote up
transformLedger = {
  transform: (value: Option<StakingLedger>): Balance | null =>
    value.isSome
      ? value.unwrap().active.unwrap()
      : null
}
Example #10
Source File: Bonded.tsx    From crust-apps with Apache License 2.0 5 votes vote down vote up
transformLedger = {
  transform: (value: Option<StakingLedger>) => value.unwrapOr(null)
}
Example #11
Source File: Bonded.tsx    From subscan-multisig-react with Apache License 2.0 5 votes vote down vote up
transformLedger = {
  transform: (value: Option<StakingLedger>) => value.unwrapOr(null),
}