-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathtypes.ts
More file actions
567 lines (503 loc) · 13.3 KB
/
Copy pathtypes.ts
File metadata and controls
567 lines (503 loc) · 13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
import BigNumber from "bignumber.js";
import { AssetType as SdkAssetType, Horizon } from "stellar-sdk";
import Blockaid from "@blockaid/client";
import {
SERVICE_TYPES,
EXTERNAL_SERVICE_TYPES,
} from "../../constants/services";
import { APPLICATION_STATE } from "../../constants/applicationState";
import { WalletType } from "../../constants/hardwareWallet";
import { NetworkDetails } from "../../constants/stellar";
import {
AssetsLists,
AssetsListItem,
} from "../../constants/soroban/asset-list";
import { AutoLockTimeoutMinutes } from "../../constants/autoLock";
export enum ActionStatus {
IDLE = "IDLE",
PENDING = "PENDING",
SUCCESS = "SUCCESS",
ERROR = "ERROR",
}
export interface UserInfo {
publicKey: string;
}
export type MigratableAccount = Account & { keyIdIndex: number };
export type IssuerKey = string; // {assetCode}:{issuer/contract ID} issuer pub key for classic, contract ID for tokens
export type CollectibleKey = string; // {collectionAddress}:{tokenId}
export type AssetVisibility = "visible" | "hidden";
export interface AllowList {
[networkName: string]: {
[publicKey: string]: string[];
};
}
export interface Response {
error: string;
apiError: FreighterApiError;
messagedId: number;
applicationState: APPLICATION_STATE;
publicKey: string;
privateKey: string;
hasPrivateKey: boolean;
mnemonicPhrase: string;
isCorrectPhrase: boolean;
confirmedPassword: boolean;
password: string;
mnemonicPhraseToConfirm: string;
recoverMnemonic: string;
transaction: {
sign: (sourceKeys: {}) => void;
};
transactionXDR: string;
signerAddress: string;
signedTransaction: string;
signedPayload: string | Buffer;
signedBlob: string | null;
signedAuthEntry: string | null;
source: string;
type: SERVICE_TYPES;
url: string;
isDataSharingAllowed: boolean;
isTestnet: boolean;
isMemoValidationEnabled: boolean;
isSafetyValidationEnabled: boolean;
isValidatingSafeAssetsEnabled: boolean;
isExperimentalModeEnabled: boolean;
isHashSigningEnabled: boolean;
isSorobanPublicEnabled: boolean;
isRpcHealthy: boolean;
userNotification: UserNotification;
assetsLists: AssetsLists;
assetsList: AssetsListItem;
isDeleteAssetsList: boolean;
settingsState: SettingsState;
experimentalFeaturesState: SettingsState;
networkDetails: NetworkDetails;
sorobanRpcUrl: string;
networksList: NetworkDetails[];
allAccounts: Account[];
migratedAccounts: MigratedAccount[];
accountName: string;
assetCode: string;
assetCanonical: string;
icons: {};
iconUrl: string;
network: string;
networkIndex: number;
networkName: string;
recentAddresses: string[];
lastUsedAccount: string;
hardwareWalletType: WalletType;
bipPath: string;
memoRequiredAccounts: MemoRequiredAccount[];
assetDomain: string;
contractId: string;
tokenId: string;
tokenIdList: string[];
isConnected: boolean;
isAllowed: boolean;
userInfo: UserInfo;
domain: string;
allowList: AllowList;
migratableAccounts: MigratableAccount[];
balancesToMigrate: BalanceToMigrate[];
isMergeSelected: boolean;
recommendedFee: string;
isNonSSLEnabled: boolean;
isHideDustEnabled: boolean;
isOpenSidebarByDefault: boolean;
activePublicKey: string;
isAccountMismatch: boolean;
assetVisibility: {
issuer: IssuerKey;
visibility: AssetVisibility;
};
hiddenAssets: Record<IssuerKey, AssetVisibility>;
collectibleVisibility: {
collectible: CollectibleKey;
visibility: AssetVisibility;
};
hiddenCollectibles: Record<CollectibleKey, AssetVisibility>;
isOverwritingAccount: boolean;
isDismissed: boolean;
collectiblesList: CollectibleContract[];
overriddenBlockaidResponse: string | null;
recentProtocols: RecentProtocolEntry[];
hasSeenDiscoverWelcome: boolean;
}
export interface MemoRequiredAccount {
address: string;
name: string;
domain: string | null;
tags: string[];
}
export interface ExternalRequestBase {
accountToSign?: string;
address?: string;
networkPassphrase?: string;
type: EXTERNAL_SERVICE_TYPES;
}
export interface ExternalRequestToken extends ExternalRequestBase {
contractId: string;
}
export interface ExternalRequestTx extends ExternalRequestBase {
transactionXdr: string;
network?: string;
}
export interface ExternalRequestBlob extends ExternalRequestBase {
apiVersion: string;
blob: string;
}
export interface ExternalRequestAuthEntry extends ExternalRequestBase {
apiVersion: string;
entryXdr: string;
}
export type ExternalRequest =
| ExternalRequestToken
| ExternalRequestTx
| ExternalRequestBlob
| ExternalRequestAuthEntry;
export interface Account {
publicKey: string;
name: string;
imported: boolean;
hardwareWalletType?: WalletType;
}
export enum AccountType {
HW = "HW",
IMPORTED = "IMPORTED",
FREIGHTER = "FREIGHTER",
}
export interface Preferences {
isDataSharingAllowed: boolean;
isMemoValidationEnabled: boolean;
networksList: NetworkDetails[];
isHideDustEnabled: boolean;
isOpenSidebarByDefault: boolean;
autoLockTimeoutMinutes: AutoLockTimeoutMinutes;
error: string;
}
export interface ExperimentalFeatures {
isExperimentalModeEnabled: boolean;
isHashSigningEnabled: boolean;
isNonSSLEnabled: boolean;
networkDetails: NetworkDetails;
networksList: NetworkDetails[];
experimentalFeaturesState: SettingsState;
}
export enum SettingsState {
IDLE = "IDLE",
LOADING = "LOADING",
ERROR = "ERROR",
SUCCESS = "SUCCESS",
}
export interface UserNotification {
enabled: boolean;
message: string;
}
export interface IndexerSettings {
settingsState: SettingsState;
isSorobanPublicEnabled: boolean;
isRpcHealthy: boolean;
userNotification: UserNotification;
}
export type SaveSettingsResponse = {
allowList: AllowList;
isDataSharingAllowed: boolean;
isMemoValidationEnabled: boolean;
networkDetails: NetworkDetails;
networksList: NetworkDetails[];
isRpcHealthy: boolean;
isSorobanPublicEnabled: boolean;
isNonSSLEnabled: boolean;
isHideDustEnabled: boolean;
isOpenSidebarByDefault: boolean;
autoLockTimeoutMinutes: AutoLockTimeoutMinutes;
};
export type Settings = {
allowList: AllowList;
networkDetails: NetworkDetails;
networksList: NetworkDetails[];
error: string;
} & Preferences;
export interface AssetIcons {
[code: string]: string | null;
}
export interface AssetDomains {
[code: string]: string;
}
export interface SoroswapToken {
code: string;
contract: string;
decimals: number;
icon: string;
name: string;
}
export interface NativeToken {
type: SdkAssetType;
code: string;
}
export interface Issuer {
key: string;
name?: string;
url?: string;
hostName?: string;
}
export interface AssetToken {
type: SdkAssetType;
code: string;
issuer: Issuer;
anchorAsset?: string;
numAccounts?: BigNumber;
amount?: BigNumber;
bidCount?: BigNumber;
askCount?: BigNumber;
spread?: BigNumber;
}
export type Token = NativeToken | AssetToken;
export interface Balance {
token: Token;
// for non-native tokens, this should be total - sellingLiabilities
// for native, it should also subtract the minimumBalance
available: BigNumber;
total: BigNumber;
buyingLiabilities: string;
sellingLiabilities: string;
liquidityPoolId?: string;
reserves?: Horizon.HorizonApi.Reserve[];
contractId?: string;
blockaidData: BlockAidScanAssetResult;
}
export type BlockAidScanAssetResult = Blockaid.TokenScanResponse;
export type BlockAidScanSiteResult = Blockaid.SiteScanResponse;
export type BlockAidScanTxResult = Blockaid.StellarTransactionScanResponse & {
request_id: string;
};
export type BlockAidBulkScanAssetResult = Blockaid.TokenBulkScanResponse;
export type BlockaidAssetDiff =
| Blockaid.StellarTransactionScanResponse.StellarSimulationResult.StellarLegacyAssetDiff
| Blockaid.StellarTransactionScanResponse.StellarSimulationResult.StellarNativeAssetDiff
| Blockaid.StellarTransactionScanResponse.StellarSimulationResult.StellarContractAssetDiff;
export interface AssetBalance extends Balance {
limit: BigNumber;
token: AssetToken;
sponsor?: string;
}
export interface NativeBalance extends Balance {
token: NativeToken;
minimumBalance: BigNumber;
}
export interface TokenBalance extends AssetBalance {
name: string;
symbol: string;
decimals: number;
total: BigNumber;
}
export interface SorobanBalance {
contractId: string;
total: BigNumber;
name: string;
symbol: string;
decimals: number;
token?: { code: string; issuer: { key: string } };
}
export type TokenBalances = SorobanBalance[];
export interface AssetBalanceChange {
asset_type: string;
asset_code?: string;
asset_issuer?: string;
type: string;
from: string;
to: string;
amount: string;
}
export type HorizonOperation = Horizon.ServerApi.OperationRecord & {
asset_balance_changes?: AssetBalanceChange[];
account: string;
amount?: string;
starting_balance?: string;
asset_code?: string;
asset_issuer?: string;
asset_type?: string;
transaction_attr: Horizon.ServerApi.TransactionRecord & {
contractId?: string;
fnName: string;
args: {
[key: string]: any;
};
};
to_muxed?: string;
to?: string;
from?: string;
};
export interface AccountHistoryInterface {
operations: Array<HorizonOperation> | [];
}
export interface ErrorMessage {
errorMessage: string;
response?: Horizon.HorizonApi.ErrorResponseData.TransactionFailed;
}
export interface BalanceToMigrate {
publicKey: string;
name: string;
minBalance: string;
xlmBalance: string;
trustlineBalances: Horizon.HorizonApi.BalanceLine[];
keyIdIndex: number;
}
export type MigratedAccount = BalanceToMigrate & {
newPublicKey: string;
isMigrated: boolean;
};
declare global {
interface Window {
freighter: boolean;
freighterApi: { [key: string]: any };
}
}
export interface FreighterApiError {
code: number;
message: string;
ext?: string[];
}
export interface ApiTokenPrice {
currentPrice: string;
percentagePriceChange24h?: string;
}
export interface ApiTokenPrices {
[key: string]: ApiTokenPrice | null;
}
export interface ProtocolEntry {
description: string;
iconUrl: string;
name: string;
websiteUrl: string;
tags: string[];
isBlacklisted: boolean;
backgroundUrl?: string;
isTrending: boolean;
}
export interface RecentProtocolEntry {
websiteUrl: string;
lastAccessed: number;
}
export type DiscoverData = ProtocolEntry[];
export interface LedgerKeyAccount {
account_id: string;
balance: string;
seq_num: number;
num_sub_entries: number;
inflation_dest: string;
flags: number;
home_domain: string;
thresholds: string;
signers: { key: string; weight: number }[];
sequence_number: number;
}
export interface LedgerKeyAccounts {
ledger_key_accounts: {
[key: string]: LedgerKeyAccount;
};
}
export interface AccountCollectionTrait {
name: string;
value: string;
}
export interface AccountCollectionItem {
collectionAddress: string;
collectionName: string;
tokenId: string;
name: string;
image: string;
description: string;
externalUrl: string;
traits: AccountCollectionTrait[];
}
export interface CollectibleResponse {
owner: string;
token_id: string;
token_uri: string;
metadata: CollectibleMetadata | null;
}
/**
* Represents a single collectible tracked by the wallet.
*
* @property {boolean} [isUserStored] - Indicates how this collectible entered the
* wallet. Set to `true` when the collectible was explicitly added or pinned by
* the user (for example, via an "Add collectible" action). Leave undefined or
* `false` when the collectible is only present because it was discovered or
* cached from transaction history or external scans.
*/
export interface Collectible {
isUserStored?: boolean;
collectionAddress: string;
collectionName: string;
owner: string;
tokenId: string;
tokenUri: string;
metadata: CollectibleMetadata | null;
}
/**
* Represents the JSON NFT metadata of a collectible
* @see https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0050.md#notes-on-name-symbol-and-token_uri
*
* @property {string} name - The name of the collectible
* @property {string} description - The description of the collectible
* @property {string} image - The image of the collectible
* @property {string} external_url - The external URL of the collectible
* @property {Object[]} attributes - The attributes of the collectible
*/
export type CollectibleMetadataResponse = {
name?: string;
description?: string;
image?: string;
external_url?: string;
attributes?: {
trait_type?: string;
value?: string | number;
}[];
};
export type CollectibleMetadata = {
name?: string;
description?: string;
image?: string;
externalUrl?: string;
attributes?: {
traitType?: string;
value?: string | number;
}[];
};
export interface CollectionResponse {
collection?: {
address: string;
name: string;
symbol: string;
collectibles: CollectibleResponse[];
};
error?: {
collection_address: string;
error_message: string;
};
}
export interface Collection {
collection?: {
address: string;
name: string;
symbol: string;
collectibles: Collectible[];
};
error?: {
collectionAddress: string;
errorMessage: string;
};
}
export interface CollectiblesResponse {
collections: CollectionResponse[];
}
export interface Collectibles {
collections: Collection[];
}
export interface CollectibleContract {
id: string;
tokenIds: string[];
}