forked from LedgerHQ/ledger-live-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
currencies.js
92 lines (85 loc) · 2.83 KB
/
currencies.js
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
// @flow
export type Unit = {
// display name of a given unit (example: satoshi)
name: string,
// string to use when formatting the unit. like 'BTC' or 'USD'
code: string,
// number of digits after the '.'
magnitude: number,
// should it always print all digits even if they are 0 (usually: true for fiats, false for cryptos)
showAllDigits?: boolean,
// true if the code should prefix amount when formatting
prefixCode?: boolean,
};
type CurrencyCommon = {
// display name of a currency
name: string,
// the ticker name in exchanges / countervalue apis (e.g. BTC).
ticker: string,
// all units of a currency (e.g. Bitcoin have bitcoin, mBTC, bit, satoshi)
// by convention, [0] is the default and have "highest" magnitude
units: Unit[],
// a shorter version of code using the symbol of the currency. like Ƀ . not all cryptocurrencies have a symbol
symbol?: string,
// tells if countervalue need to be disabled (typically because colliding with other coins)
disableCountervalue?: boolean,
delisted?: boolean,
// some countervalue will have a ticker alias
countervalueTicker?: string,
};
export type TokenCurrency = CurrencyCommon & {
type: "TokenCurrency",
id: string,
ledgerSignature?: string,
contractAddress: string,
// the currency it belongs to. e.g. 'ethereum'
parentCurrency: CryptoCurrency,
// the type of token in the blockchain it belongs. e.g. 'erc20'
tokenType: string,
// indicates this is a compound token and it's "parent" erc20 have this id
compoundFor?: string,
};
export type FiatCurrency = CurrencyCommon & {
type: "FiatCurrency",
};
export type ExplorerView = {
tx?: string,
address?: string,
token?: string,
};
export type CryptoCurrency = CurrencyCommon & {
type: "CryptoCurrency",
// unique internal id of a crypto currency
id: string,
// define if a crypto is a fork from another coin. helps dealing with split/unsplit
forkedFrom?: string,
// name of the app as shown in the Manager
managerAppName: string,
// coin type according to slip44. THIS IS NOT GUARANTEED UNIQUE across currencies (e.g testnets,..)
coinType: number,
// the scheme name to use when formatting an URI (without the ':')
scheme: string,
// used for UI
color: string,
family: string,
blockAvgTime?: number, // in seconds
supportsSegwit?: boolean,
supportsNativeSegwit?: boolean,
// if defined this coin is a testnet for another crypto (id)};
isTestnetFor?: string,
// TODO later we could express union of types with mandatory bitcoinLikeInfo for "bitcoin" family...
bitcoinLikeInfo?: {
P2PKH: number,
P2SH: number,
hasTimestamp?: boolean,
},
ethereumLikeInfo?: {
chainId: number,
},
explorerViews: ExplorerView[],
terminated?: {
link: string,
},
deviceTicker?: string,
};
export type Currency = FiatCurrency | CryptoCurrency | TokenCurrency;