diff --git a/packages/blockchain-link-types/src/blockbook.ts b/packages/blockchain-link-types/src/blockbook.ts index d9c9b5587c..3510f5e928 100644 --- a/packages/blockchain-link-types/src/blockbook.ts +++ b/packages/blockchain-link-types/src/blockbook.ts @@ -1,20 +1,24 @@ -import type { RequiredKey } from '@trezor/type-utils'; +import type { OptionalKey, RequiredKey } from '@trezor/type-utils'; import type { - AddressAlias, + AvailableVsCurrencies, + Address as BlockbookAddress, + Block as BlockbookBlock, Token as BlockbookToken, TokenTransfer as BlockbookTokenTransfer, Tx as BlockbookTx, Utxo as BlockbookUtxo, - ContractInfo, + FiatTicker, MempoolTxidFilterEntries, - StakingPool, Vin, Vout, + WsAccountUtxoReq, WsBlockFilterReq, WsBlockFiltersBatchReq, WsBlockHashRes, + WsEstimateFeeRes, WsInfoRes, + WsMempoolFiltersReq, } from './blockbook-api'; import type { AccountBalanceHistory, FiatRatesBySymbol, TokenStandard } from './common'; import type { @@ -27,8 +31,6 @@ import type { RpcCallParams, } from './params'; -type OptionalKey = Omit & Partial>; - export type AccountUtxo = RequiredKey[]; export interface Subscribe { @@ -39,24 +41,26 @@ export type ServerInfo = WsInfoRes; export type BlockHash = WsBlockHashRes; -export interface Block { - page: number; - totalPages: number; - itemsOnPage: number; - hash: string; - height: number; +export type Block = Omit< + RequiredKey, + 'txs' | 'confirmations' | 'size' | 'version' | 'merkleRoot' | 'nonce' | 'bits' | 'difficulty' +> & { txCount: number; txs: Transaction[]; -} +}; -export interface FilterRequestParams { - scriptType: 'taproot' | 'taproot-noordinals'; - M?: number; -} +type ScriptType = 'taproot' | 'taproot-noordinals'; -export interface MempoolFiltersParams extends FilterRequestParams { - fromTimestamp?: number; -} +export type FilterRequestParams = Omit & { + scriptType: ScriptType; +}; + +export type MempoolFiltersParams = Omit< + OptionalKey, + 'scriptType' +> & { + scriptType: ScriptType; +}; export interface FilterResponse { P: number; @@ -114,60 +118,37 @@ export type BEP1155 = BaseERC & { standard: 'BEP1155'; } & Required>; -export interface AccountInfo { - address: string; - balance: string; - totalReceived: string; - totalSent: string; - txs: number; - addrTxCount?: number; - unconfirmedBalance: string; - unconfirmedTxs: number; - page?: number; - itemsOnPage: number; - totalPages: number; - nonTokenTxs?: number; - transactions?: Transaction[]; - nonce?: string; +export type AccountInfo = Omit< + RequiredKey, + 'tokens' | 'transactions' +> & { tokens?: (XPUBAddress | ERC20 | ERC721 | ERC1155 | BEP20 | BEP721 | BEP1155)[]; - contractInfo?: ContractInfo; - addressAliases?: { [key: string]: AddressAlias }; - stakingPools?: StakingPool[]; -} + transactions?: Transaction[]; +}; -export interface AccountUtxoParams { - descriptor: string; -} +export type AccountUtxoParams = WsAccountUtxoReq; export type VinVout = OptionalKey; -export interface Transaction extends BlockbookTx { - fees: string; // optional in Tx, seems to always be there +export type Transaction = Omit, 'tokenTransfers'> & { tokenTransfers?: (BlockbookTokenTransfer & { type: TokenStandard; // string in Tx, seems to always be ERC20 | ERC721 | ERC1155 standard: TokenStandard; })[]; -} +}; export interface Push { result: string; } -export type Fee = { - feePerUnit: string; - feePerTx?: string; - feeLimit?: string; -}[]; +export type Fee = Omit, 'eip1559'>[]; -export interface BlockNotification { - height: number; - hash: string; -} +export type BlockNotification = Pick; -export interface MempoolTransactionNotification extends Transaction { - confirmationETABlocks: number; - confirmationETASeconds: number; -} +export type MempoolTransactionNotification = RequiredKey< + Transaction, + 'confirmationETASeconds' | 'confirmationETABlocks' +>; export interface AddressNotification { address: string; @@ -178,19 +159,15 @@ export interface FiatRatesNotification { rates: FiatRatesBySymbol; } -export interface TimestampedFiatRates { - ts: number; +export type TimestampedFiatRates = Omit, 'error' | 'rates'> & { rates: FiatRatesBySymbol; -} +}; export interface FiatRatesForTimestamp { tickers: TimestampedFiatRates[]; } -export interface AvailableCurrencies { - ts: number; - available_currencies: string[]; -} +export type AvailableCurrencies = Omit, 'error'>; // eslint-disable-next-line @typescript-eslint/no-unused-vars declare function FSend(method: 'getInfo'): Promise; diff --git a/packages/blockchain-link-types/src/common.ts b/packages/blockchain-link-types/src/common.ts index 2ed30a29bb..b7c2b625c6 100644 --- a/packages/blockchain-link-types/src/common.ts +++ b/packages/blockchain-link-types/src/common.ts @@ -1,12 +1,16 @@ import type tls from 'tls'; +import type { OptionalKey, RequiredKey } from '@trezor/type-utils'; + import { BaseCurrencyCode } from './baseCurrency'; import type { Transaction as BlockbookTransaction, VinVout } from './blockbook'; import type { AddressAlias, + BalanceHistory, + Token as BlockbookToken, TokenTransfer as BlockbookTokenTransfer, + Utxo as BlockbookUtxo, ContractInfo, - MultiTokenValue, StakingPool, } from './blockbook-api'; import type { SolanaStakingAccount } from './solana'; @@ -126,14 +130,12 @@ export type FiatRatesBySymbol = { [K in BaseCurrencyCode]?: number | undefined; }; -export interface AccountBalanceHistory { - time: number; - txs: number; - received: string; - sent: string; - sentToSelf?: string; // should always be there for blockbook >= 0.3.3 +export type AccountBalanceHistory = Omit< + OptionalKey, + 'txid' | 'rates' +> & { rates: FiatRatesBySymbol; -} +}; export interface Transaction { type: 'sent' | 'recv' | 'self' | 'joint' | 'contract' | 'failed' | 'unknown'; @@ -206,41 +208,32 @@ export interface AccountAddresses { anonymitySet?: AnonymitySet; } -export interface Utxo { - txid: string; - vout: number; +export type Utxo = Omit< + RequiredKey, + 'value' | 'height' | 'lockTime' +> & { amount: string; blockHeight: number; - address: string; - path: string; - confirmations: number; - coinbase?: boolean; cardanoSpecific?: { unit: string; }; -} +}; export interface TokenAccount { publicKey: string; balance: string; } -export interface TokenInfo { - standard: TokenStandard; // token standard: ERC20... - contract: string; // token address, token unit for ADA - balance?: string; // token balance - name?: string; // token name - symbol?: string; // token symbol - decimals: number; // token decimals or 0 - accounts?: TokenAccount[]; // token accounts for solana - policyId?: string; // Cardano policy id - fingerprint?: string; // Cardano starting with "asset" - multiTokenValues?: MultiTokenValue[]; - ids?: string[]; - totalReceived?: string; - totalSent?: string; +export type TokenInfo = Omit< + RequiredKey, 'contract'>, + 'type' | 'standard' | 'path' | 'transfers' | 'baseValue' | 'secondaryValue' +> & { + standard: TokenStandard; + accounts?: TokenAccount[]; + policyId?: string; + fingerprint?: string; // transfers: number, // total transactions? -} +}; /** * This is Backend data for the account. Data can change over time as transactions happen. diff --git a/packages/type-utils/src/utils.ts b/packages/type-utils/src/utils.ts index 74091828e1..06b4708c60 100644 --- a/packages/type-utils/src/utils.ts +++ b/packages/type-utils/src/utils.ts @@ -20,6 +20,17 @@ export type UnionSubset = U; */ export type RequiredKey = Omit & Required>; +/** + * Make property of the object optional. + * + * Example: + * ``` + * type T = { a: number; b: number; }; + * const t: OptionalKey = { b: 0 }; // 'a' is optional + * ``` + */ +export type OptionalKey = Omit & Partial>; + /** * Get type of the object values. *