@rango-dev/wallets-react 0.46.0 → 0.46.1-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,186 +0,0 @@
1
- import type {
2
- Asset,
3
- Explorer,
4
- FeeToken,
5
- StakingToken,
6
- } from '@chain-registry/types';
7
- import type {
8
- CosmosAssetList,
9
- CosmosChain,
10
- } from '@rango-dev/wallets-core/namespaces/cosmos';
11
- import type { CosmosBlockchainMeta, CosmosChainInfo } from 'rango-types';
12
-
13
- export interface ConversionResult {
14
- chain: CosmosChain;
15
- assetList: CosmosAssetList;
16
- }
17
-
18
- /**
19
- * Converts CosmosBlockchainMeta to Chain and AssetList formats
20
- */
21
- export function convertCosmosMetaToChainRegistry(
22
- meta: CosmosBlockchainMeta
23
- ): ConversionResult {
24
- const info = meta.info;
25
-
26
- if (!info) {
27
- throw new Error('CosmosChainInfo is required for conversion');
28
- }
29
-
30
- const chain = convertToChain(meta, info);
31
- const assetList = convertToAssetList(info);
32
-
33
- return { chain, assetList };
34
- }
35
-
36
- function convertToChain(
37
- meta: CosmosBlockchainMeta,
38
- info: CosmosChainInfo
39
- ): CosmosChain {
40
- const chain: CosmosChain = {
41
- chainName: info.chainName,
42
- chainType: 'cosmos',
43
- chainId: meta.chainId || undefined,
44
- prettyName: meta.displayName,
45
- status: meta.enabled ? 'live' : 'killed',
46
- networkType: 'mainnet',
47
- bech32Prefix: info.bech32Config.bech32PrefixAccAddr,
48
- bech32Config: {
49
- bech32PrefixAccAddr: info.bech32Config.bech32PrefixAccAddr,
50
- bech32PrefixAccPub: info.bech32Config.bech32PrefixAccPub,
51
- bech32PrefixValAddr: info.bech32Config.bech32PrefixValAddr,
52
- bech32PrefixValPub: info.bech32Config.bech32PrefixValPub,
53
- bech32PrefixConsAddr: info.bech32Config.bech32PrefixConsAddr,
54
- bech32PrefixConsPub: info.bech32Config.bech32PrefixConsPub,
55
- },
56
- slip44: info.bip44.coinType,
57
- fees: {
58
- feeTokens: convertFeeTokens(info),
59
- },
60
- staking: {
61
- stakingTokens: convertStakingTokens(info),
62
- },
63
- apis: {
64
- rpc: info.rpc ? [{ address: info.rpc }] : undefined,
65
- rest: info.rest ? [{ address: info.rest }] : undefined,
66
- },
67
- explorers: convertExplorers(info),
68
- logoURIs: meta.logo
69
- ? { png: window.location.origin + meta.logo }
70
- : undefined,
71
- keywords: info.experimental ? ['experimental'] : undefined,
72
- };
73
-
74
- return chain;
75
- }
76
-
77
- function convertFeeTokens(info: CosmosChainInfo): FeeToken[] {
78
- return info.feeCurrencies.map((currency) => {
79
- const feeToken: FeeToken = {
80
- denom: currency.coinMinimalDenom,
81
- };
82
-
83
- if (info.gasPriceStep) {
84
- feeToken.lowGasPrice = info.gasPriceStep.low;
85
- feeToken.averageGasPrice = info.gasPriceStep.average;
86
- feeToken.highGasPrice = info.gasPriceStep.high;
87
- }
88
-
89
- return feeToken;
90
- });
91
- }
92
-
93
- function convertStakingTokens(info: CosmosChainInfo): StakingToken[] {
94
- return [
95
- {
96
- denom: info.stakeCurrency.coinMinimalDenom,
97
- },
98
- ];
99
- }
100
-
101
- function convertExplorers(info: CosmosChainInfo): Explorer[] | undefined {
102
- const explorers: Explorer[] = [];
103
-
104
- if (info.explorerUrlToTx) {
105
- const baseUrl = info.explorerUrlToTx.split('/tx/')[0];
106
- explorers.push({
107
- url: baseUrl,
108
- txPage: info.explorerUrlToTx.replace(
109
- /\{txHash\}|\$\{txHash\}/g,
110
- '${txHash}'
111
- ),
112
- });
113
- }
114
-
115
- if (info.blockExplorerUrls && info.blockExplorerUrls.length > 0) {
116
- info.blockExplorerUrls.forEach((url) => {
117
- if (!explorers.some((e) => e.url === url)) {
118
- explorers.push({ url });
119
- }
120
- });
121
- }
122
-
123
- return explorers.length > 0 ? explorers : undefined;
124
- }
125
-
126
- function convertToAssetList(info: CosmosChainInfo): CosmosAssetList {
127
- const assets: Asset[] = [];
128
-
129
- // Add staking currency
130
- assets.push({
131
- denomUnits: [
132
- {
133
- denom: info.stakeCurrency.coinMinimalDenom,
134
- exponent: 0,
135
- },
136
- {
137
- denom: info.stakeCurrency.coinDenom.toLowerCase(),
138
- exponent: info.stakeCurrency.coinDecimals,
139
- },
140
- ],
141
- base: info.stakeCurrency.coinMinimalDenom,
142
- name: info.stakeCurrency.coinDenom,
143
- display: info.stakeCurrency.coinDenom.toLowerCase(),
144
- symbol: info.stakeCurrency.coinDenom,
145
- typeAsset: 'sdk.coin',
146
- logoURIs: info.stakeCurrency.coinImageUrl
147
- ? { png: window.location.origin + info.stakeCurrency.coinImageUrl }
148
- : undefined,
149
- coingeckoId: info.stakeCurrency.coinGeckoId || undefined,
150
- });
151
-
152
- // Add other currencies
153
- info.currencies.forEach((currency) => {
154
- // Skip if already added as staking currency
155
- if (currency.coinMinimalDenom === info.stakeCurrency.coinMinimalDenom) {
156
- return;
157
- }
158
-
159
- assets.push({
160
- denomUnits: [
161
- {
162
- denom: currency.coinMinimalDenom,
163
- exponent: 0,
164
- },
165
- {
166
- denom: currency.coinDenom.toLowerCase(),
167
- exponent: currency.coinDecimals,
168
- },
169
- ],
170
- base: currency.coinMinimalDenom,
171
- name: currency.coinDenom,
172
- display: currency.coinDenom.toLowerCase(),
173
- symbol: currency.coinDenom,
174
- typeAsset: 'sdk.coin',
175
- logoURIs: currency.coinImageUrl
176
- ? { png: window.location.origin + currency.coinImageUrl }
177
- : undefined,
178
- coingeckoId: currency.coinGeckoId || undefined,
179
- });
180
- });
181
-
182
- return {
183
- chainName: info.chainName,
184
- assets,
185
- };
186
- }