Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import order everywhere #15264

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ module.exports = {
rules: {
'@typescript-eslint/no-shadow': 'off',
'import/no-default-export': 'off',
'import/order': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'no-console': 'off',
'react/jsx-no-undef': 'off',
Expand Down
3 changes: 2 additions & 1 deletion packages/analytics/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { Environment } from '@trezor/env-utils';
import type { App, Event as AnalyticsEvent } from './types';
import { getWeakRandomId } from '@trezor/utils';

import type { App, Event as AnalyticsEvent } from './types';

export const getTrackingRandomId = () => getWeakRandomId(10);

export const getRandomId = () => getWeakRandomId(10);
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain-link/src/workers/baseWebsocket.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import WebSocket from 'ws';
import { createDeferred, createDeferredManager, TypedEmitter } from '@trezor/utils';

import { createDeferred, createDeferredManager, TypedEmitter } from '@trezor/utils';
import { CustomError } from '@trezor/blockchain-link-types/src/constants/errors';

interface Subscription<T> {
Expand Down
6 changes: 4 additions & 2 deletions packages/blockchain-link/src/workers/baseWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
// new BlockchainLink({ worker: () => new BlockchainLinkModule() });

import { SocksProxyAgent } from 'socks-proxy-agent';

import { CustomError } from '@trezor/blockchain-link-types/src/constants/errors';
import { WorkerState } from './state';
import { prioritizeEndpoints } from './utils';
import { MESSAGES, RESPONSES } from '@trezor/blockchain-link-types/src/constants';
import type { Response, BlockchainSettings } from '@trezor/blockchain-link-types';
import type { Message } from '@trezor/blockchain-link-types/src/messages';

import { prioritizeEndpoints } from './utils';
import { WorkerState } from './state';

// self is not declared in TS Webworker lib typings
declare const self: { postMessage: (...args: any[]) => any };

Expand Down
5 changes: 3 additions & 2 deletions packages/blockchain-link/src/workers/blockbook/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { CustomError } from '@trezor/blockchain-link-types/src/constants/errors';
import { MESSAGES, RESPONSES } from '@trezor/blockchain-link-types/src/constants';
import { BaseWorker, CONTEXT, ContextType } from '../baseWorker';
import { BlockbookAPI } from './websocket';
import * as utils from '@trezor/blockchain-link-utils/src/blockbook';
import type { Response, SubscriptionAccountInfo } from '@trezor/blockchain-link-types';
import type {
Expand All @@ -12,6 +10,9 @@ import type {
} from '@trezor/blockchain-link-types/src/blockbook';
import type * as MessageTypes from '@trezor/blockchain-link-types/src/messages';

import { BlockbookAPI } from './websocket';
import { BaseWorker, CONTEXT, ContextType } from '../baseWorker';

type Context = ContextType<BlockbookAPI>;
type Request<T> = T & Context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import type {
AccountBalanceHistoryParams,
RpcCallParams,
} from '@trezor/blockchain-link-types/src/params';
import { getSuiteVersion } from '@trezor/env-utils';

import { BaseWebsocket } from '../baseWebsocket';
import { getSuiteVersion } from '@trezor/env-utils';

interface BlockbookEvents {
block: BlockNotification;
Expand Down
5 changes: 3 additions & 2 deletions packages/blockchain-link/src/workers/blockfrost/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { CustomError } from '@trezor/blockchain-link-types/src/constants/errors';
import { MESSAGES, RESPONSES } from '@trezor/blockchain-link-types/src/constants';
import { BaseWorker, CONTEXT, ContextType } from '../baseWorker';
import { BlockfrostAPI } from './websocket';
import {
transformUtxos,
transformAccountInfo,
Expand All @@ -15,6 +13,9 @@ import type {
} from '@trezor/blockchain-link-types/src/blockfrost';
import type * as MessageTypes from '@trezor/blockchain-link-types/src/messages';

import { BlockfrostAPI } from './websocket';
import { BaseWorker, CONTEXT, ContextType } from '../baseWorker';

type Context = ContextType<BlockfrostAPI>;
type Request<T> = T & Context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import type {
EstimateFeeParams,
AccountBalanceHistoryParams,
} from '@trezor/blockchain-link-types/src/params';
import { getSuiteVersion } from '@trezor/env-utils';

import { BaseWebsocket } from '../baseWebsocket';
import { getSuiteVersion } from '@trezor/env-utils';

interface BlockfrostEvents {
block: BlockContent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ElectrumClient } from './electrum';
import { Status } from '@trezor/blockchain-link-types/src/electrum';

import { ElectrumClient } from './electrum';

type Cache = {
[descriptor: string]: [Status, any];
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Network, networks } from '@trezor/utxo-lib';
import { ElectrumAPI, BlockHeader, Version } from '@trezor/blockchain-link-types/src/electrum';

import { JsonRpcClientOptions } from './json-rpc';
import { BatchingJsonRpcClient } from './batching';
import type { ISocket } from '../sockets/interface';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { EventEmitter } from 'events';

import { throwError } from '@trezor/utils';

import type { ISocket } from '../sockets/interface';

type Callback = (error: any, result?: any) => void;
Expand Down
3 changes: 2 additions & 1 deletion packages/blockchain-link/src/workers/electrum/devrun.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// @ts-nocheck
/// <reference path="../../../../suite/global.d.ts" />

import ElectrumWorker from './index';
import { createSocket } from './sockets';
import type { Message, Response } from '../../types';

import ElectrumWorker from './index';

const TOR_ADDRESS = '127.0.0.1:9050';

const LOCALHOST_CONFIG = 'localhost:50001:t';
Expand Down
5 changes: 3 additions & 2 deletions packages/blockchain-link/src/workers/electrum/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { CustomError } from '@trezor/blockchain-link-types/src/constants/errors';
import { MESSAGES, RESPONSES } from '@trezor/blockchain-link-types/src/constants';
import type { Response } from '@trezor/blockchain-link-types';
import { Message } from '@trezor/blockchain-link-types/src/messages';

import { BaseWorker, CONTEXT, ContextType } from '../baseWorker';
import * as M from './methods';
import * as L from './listeners';
import { createSocket } from './sockets';
import { CachingElectrumClient } from './client/caching';
import type { ElectrumClient } from './client/electrum';
import type { Response } from '@trezor/blockchain-link-types';
import { Message } from '@trezor/blockchain-link-types/src/messages';

type BlockListener = ReturnType<typeof L.blockListener>;
type TxListener = ReturnType<typeof L.txListener>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { throwError } from '@trezor/utils';
import { RESPONSES } from '@trezor/blockchain-link-types/src/constants';
import type { BlockHeader, ElectrumAPI } from '@trezor/blockchain-link-types/src/electrum';

import { blockheaderToBlockhash } from '../utils';
import type { BaseWorker } from '../../baseWorker';
import type { BlockHeader, ElectrumAPI } from '@trezor/blockchain-link-types/src/electrum';

export const blockListener = (worker: BaseWorker<ElectrumAPI>) => {
const { state } = worker;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { throwError } from '@trezor/utils';
import { RESPONSES } from '@trezor/blockchain-link-types/src/constants';
import { createAddressManager, getTransactions } from '../utils';
import { transformTransaction } from '@trezor/blockchain-link-utils/src/blockbook';
import type { BaseWorker } from '../../baseWorker';
import type {
ElectrumAPI,
HistoryTx,
StatusChange,
} from '@trezor/blockchain-link-types/src/electrum';
import type { Subscribe, Unsubscribe } from '@trezor/blockchain-link-types/src/messages';

import type { BaseWorker } from '../../baseWorker';
import { createAddressManager, getTransactions } from '../utils';

type Payload<T extends { type: string; payload: any }> = Extract<
T['payload'],
{ type: 'addresses' | 'accounts' }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Api, btcToSat } from '../utils';
import type { EstimateFee as Req } from '@trezor/blockchain-link-types/src/messages';
import type { EstimateFee as Res } from '@trezor/blockchain-link-types/src/responses';

import { Api, btcToSat } from '../utils';

const estimateFee: Api<Req, Res> = (client, payload) =>
Promise.all(
(payload.blocks || []).map(num =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { BigNumber } from '@trezor/utils/src/bigNumber';
import { discovery } from '@trezor/utxo-lib';
import { sumVinVout } from '@trezor/blockchain-link-utils';
import { Api, tryGetScripthash, getTransactions, discoverAddress, AddressHistory } from '../utils';
import { transformTransaction } from '@trezor/blockchain-link-utils/src/blockbook';
import type { GetAccountBalanceHistory as Req } from '@trezor/blockchain-link-types/src/messages';
import type { GetAccountBalanceHistory as Res } from '@trezor/blockchain-link-types/src/responses';
import type { AccountAddresses, Transaction } from '@trezor/blockchain-link-types/src/common';
import type { HistoryTx } from '@trezor/blockchain-link-types/src/electrum';

import { Api, tryGetScripthash, getTransactions, discoverAddress, AddressHistory } from '../utils';

const transformAddress = (addr: AddressHistory) => ({
address: addr.address,
path: addr.path,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { discovery } from '@trezor/utxo-lib';
import { sortTxsFromLatest } from '@trezor/blockchain-link-utils';
import { Api, tryGetScripthash, discoverAddress, AddressHistory, getTransactions } from '../utils';
import { transformTransaction } from '@trezor/blockchain-link-utils/src/blockbook';
import type { ElectrumAPI } from '@trezor/blockchain-link-types/src/electrum';
import type { GetAccountInfo as Req } from '@trezor/blockchain-link-types/src/messages';
import type { GetAccountInfo as Res } from '@trezor/blockchain-link-types/src/responses';
import type { VinVout } from '@trezor/blockchain-link-types/src/blockbook';
import type { Address, Transaction } from '@trezor/blockchain-link-types';

import { Api, tryGetScripthash, discoverAddress, AddressHistory, getTransactions } from '../utils';

// const PAGE_DEFAULT = 0;
const PAGE_SIZE_DEFAULT = 25;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { throwError } from '@trezor/utils';
import { discovery } from '@trezor/utxo-lib';
import { Api, tryGetScripthash, discoverAddress } from '../utils';
import type { GetAccountUtxo as Req } from '@trezor/blockchain-link-types/src/messages';
import type { GetAccountUtxo as Res } from '@trezor/blockchain-link-types/src/responses';
import type { Utxo } from '@trezor/blockchain-link-types/src/electrum';

import { Api, tryGetScripthash, discoverAddress } from '../utils';

const transformUtxo =
(currentHeight: number, addressInfo: { address?: string; path?: string } = {}) =>
({ height, tx_hash, tx_pos, value }: Utxo): Res['payload'][number] => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Api, blockheaderToBlockhash } from '../utils';
import type { GetBlockHash as Req } from '@trezor/blockchain-link-types/src/messages';
import type { GetBlockHash as Res } from '@trezor/blockchain-link-types/src/responses';

import { Api, blockheaderToBlockhash } from '../utils';

const getBlockHash: Api<Req, Res> = async (client, payload) => {
const blockheader = await client.request('blockchain.block.header', payload);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { throwError } from '@trezor/utils';
import { Api, blockheaderToBlockhash } from '../utils';
import type { GetInfo as Req } from '@trezor/blockchain-link-types/src/messages';
import type { GetInfo as Res } from '@trezor/blockchain-link-types/src/responses';

import { Api, blockheaderToBlockhash } from '../utils';

const getInfo: Api<Req, Res> = client => {
const {
url,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Api, getTransactions } from '../utils';
import { transformTransaction } from '@trezor/blockchain-link-utils/src/blockbook';
import type { GetTransaction as Req } from '@trezor/blockchain-link-types/src/messages';
import type { GetTransaction as Res } from '@trezor/blockchain-link-types/src/responses';

import { Api, getTransactions } from '../utils';

const getTransaction: Api<Req, Res> = async (client, payload) => {
const [tx] = await getTransactions(client, [{ tx_hash: payload, height: -1 }]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Api } from '../utils';
import type { PushTransaction as Req } from '@trezor/blockchain-link-types/src/messages';
import type { PushTransaction as Res } from '@trezor/blockchain-link-types/src/responses';

import { Api } from '../utils';

const pushTransaction: Api<Req, Res> = async (client, payload) => {
const res = await client.request('blockchain.transaction.broadcast', payload);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Socket as TCPSocket } from 'net';
import type { TLSSocket } from 'tls';
import type { SocksProxyAgent } from 'socks-proxy-agent';

import type { ISocket, SocketListener } from './interface';

const TIMEOUT = 10000;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { parseElectrumUrl } from '@trezor/utils';
import { CustomError } from '@trezor/blockchain-link-types/src/constants/errors';

import { TcpSocket } from './tcp';
import { TlsSocket } from './tls';
import { TorSocket } from './tor';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Socket as TCPSocket } from 'net';

import { SocketBase } from './base';
import type { SocketListener } from './interface';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TLSSocket } from 'tls';

import { SocketBase } from './base';
import type { SocketListener } from './interface';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SocketBase, SocketConfig } from './base';
import type { SocksProxyAgent } from 'socks-proxy-agent';

import { SocketBase, SocketConfig } from './base';
import type { SocketListener } from './interface';

type TorSocketConfig = SocketConfig & {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { isNotUndefined, arrayDistinct, objectPartition } from '@trezor/utils';
import { addressToScripthash } from './transform';
import type { Network } from '@trezor/utxo-lib';
import type { AccountAddresses, SubscriptionAccountInfo } from '@trezor/blockchain-link-types/src';

import { addressToScripthash } from './transform';

type AddressMap = { [address: string]: string };
type AccountMap = { [descriptor: string]: AccountAddresses };

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { addressToScripthash } from './transform';
import type { ElectrumAPI, HistoryTx } from '@trezor/blockchain-link-types/src/electrum';

import { addressToScripthash } from './transform';

export type AddressHistory = {
address: string;
scripthash: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { arrayToDictionary, arrayDistinct } from '@trezor/utils';
import { btcToSat } from './transform';
import type { Transaction as BlockbookTransaction } from '@trezor/blockchain-link-types/src/blockbook';
import type {
ElectrumAPI,
Expand All @@ -10,6 +9,8 @@ import type {
HistoryTx,
} from '@trezor/blockchain-link-types/src/electrum';

import { btcToSat } from './transform';

const transformOpReturn = (hex: string) => {
const [, _len, data] = hex.match(/^6a(?:4c)?([0-9a-f]{2})([0-9a-f]*)$/i) ?? [];

Expand Down
4 changes: 3 additions & 1 deletion packages/blockchain-link/src/workers/ripple/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { RippleAPI, APIOptions } from 'ripple-lib';
import { RippleError } from 'ripple-lib/dist/npm/common/errors';

import { BigNumber } from '@trezor/utils/src/bigNumber';
import { CustomError } from '@trezor/blockchain-link-types/src/constants/errors';
import { MESSAGES, RESPONSES } from '@trezor/blockchain-link-types/src/constants';
import { BaseWorker, CONTEXT, ContextType } from '../baseWorker';
import * as utils from '@trezor/blockchain-link-utils/src/ripple';
import type { Response, SubscriptionAccountInfo, AccountInfo } from '@trezor/blockchain-link-types';
import type * as MessageTypes from '@trezor/blockchain-link-types/src/messages';

import { BaseWorker, CONTEXT, ContextType } from '../baseWorker';

type Context = ContextType<RippleAPI>;
type Request<T> = T & Context;

Expand Down
1 change: 1 addition & 0 deletions packages/blockchain-link/src/workers/solana/fee.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Connection, Message, PublicKey } from '@solana/web3.js';

import { BigNumber } from '@trezor/utils/src/bigNumber';

const COMPUTE_BUDGET_PROGRAM_ID = 'ComputeBudget111111111111111111111111111111';
Expand Down
Loading
Loading