{"size": 2055, "ext": "js", "max_stars_repo_path": "src/bot/types.js", "max_stars_repo_name": "xdvlabs/ledger-live-common", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/bot/types.js", "max_issues_repo_name": "xdvlabs/ledger-live-common", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/bot/types.js", "max_forks_repo_name": "xdvlabs/ledger-live-common", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.8953488372, "max_line_length": 64, "alphanum_fraction": 0.6924574209}
// @flow
import { BigNumber } from "bignumber.js";
import type Transport from "@ledgerhq/hw-transport";
import type {
  Account,
  AccountBridge,
  Transaction,
  TransactionStatus,
  SignedOperation,
  Operation,
  CryptoCurrency,
} from "../types";
import type { DeviceModelId } from "@ledgerhq/devices";
import type { AppCandidate } from "../load/speculos";

export type { AppCandidate };

type DeviceActionEvent = { text: string, x: number, y: number };

export type DeviceActionArg<T, S> = {
  appCandidate: AppCandidate,
  transaction: T,
  transport: Transport<*> & { button: (string) => void },
  event: DeviceActionEvent,
  state: S,
};

export type DeviceAction<T, S> = (DeviceActionArg<T, S>) => ?S;

export type MutationSpec<T: Transaction> = {
  name: string,
  transaction: ({
    appCandidate: AppCandidate,
    account: Account,
    siblings: Account[],
    bridge: AccountBridge<T>,
    maxSpendable: BigNumber,
  }) => ?T,
  deviceAction?: DeviceAction<T, any>,
  maxRun?: number,
  test?: ({
    account: Account,
    accountBeforeTransaction: Account,
    transaction: T,
    status: TransactionStatus,
    optimisticOperation: Operation,
    operation: Operation,
  }) => void,
};

export type AppSpec<T: Transaction> = {
  name: string,
  currency: CryptoCurrency,
  dependency?: string,
  appQuery: {
    model?: DeviceModelId,
    appName?: string,
    firmware?: string,
    appVersion?: string,
  },
  mutations: MutationSpec<T>[],
};

export type MutationReport<T: Transaction> = {
  syncAllAccountsTime: number,
  spec: AppSpec<T>,
  appCandidate: AppCandidate,
  account?: Account,
  maxSpendable?: BigNumber,
  unavailableMutationReasons?: string[],
  mutation?: MutationSpec<T>,
  destination?: Account,
  transaction?: T,
  transactionTime?: number,
  status?: TransactionStatus,
  statusTime?: number,
  signedOperation?: SignedOperation,
  signedTime?: number,
  optimisticOperation?: Operation,
  broadcastedTime?: number,
  operation?: Operation,
  confirmedTime?: number,
  finalAccount?: Account,
  error?: Error,
};
