@keplr-wallet/background 0.13.13 → 0.13.15-rc.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.
Files changed (92) hide show
  1. package/build/chains/convert.d.ts +7 -0
  2. package/build/chains/convert.js +109 -0
  3. package/build/chains/convert.js.map +1 -0
  4. package/build/chains/handler.js +1 -1
  5. package/build/chains/handler.js.map +1 -1
  6. package/build/chains/index.d.ts +1 -0
  7. package/build/chains/index.js +1 -0
  8. package/build/chains/index.js.map +1 -1
  9. package/build/chains/messages.d.ts +1 -1
  10. package/build/chains/service.d.ts +3 -9
  11. package/build/chains/service.js +45 -79
  12. package/build/chains/service.js.map +1 -1
  13. package/build/chains-ui/service.d.ts +2 -2
  14. package/build/chains-ui/service.js +5 -6
  15. package/build/chains-ui/service.js.map +1 -1
  16. package/build/chains-update/service.js +2 -2
  17. package/build/chains-update/service.js.map +1 -1
  18. package/build/keyring/handler.js +21 -15
  19. package/build/keyring/handler.js.map +1 -1
  20. package/build/keyring/service.d.ts +0 -1
  21. package/build/keyring/service.js +103 -78
  22. package/build/keyring/service.js.map +1 -1
  23. package/build/keyring-bitcoin/service.js +2 -2
  24. package/build/keyring-bitcoin/service.js.map +1 -1
  25. package/build/keyring-cosmos/service.js +31 -18
  26. package/build/keyring-cosmos/service.js.map +1 -1
  27. package/build/keyring-ethereum/service.js +19 -19
  28. package/build/keyring-ethereum/service.js.map +1 -1
  29. package/build/keyring-ledger/service.js +8 -7
  30. package/build/keyring-ledger/service.js.map +1 -1
  31. package/build/keyring-starknet/service.js +7 -7
  32. package/build/keyring-starknet/service.js.map +1 -1
  33. package/build/manage-view-asset-token/service.d.ts +1 -2
  34. package/build/manage-view-asset-token/service.js +2 -2
  35. package/build/manage-view-asset-token/service.js.map +1 -1
  36. package/build/permission/service.d.ts +1 -2
  37. package/build/permission/service.js +2 -2
  38. package/build/permission/service.js.map +1 -1
  39. package/build/recent-send-history/service.d.ts +4 -4
  40. package/build/recent-send-history/service.js +101 -73
  41. package/build/recent-send-history/service.js.map +1 -1
  42. package/build/secret-wasm/service.d.ts +3 -3
  43. package/build/secret-wasm/service.js +29 -29
  44. package/build/secret-wasm/service.js.map +1 -1
  45. package/build/token-cw20/service.d.ts +6 -6
  46. package/build/token-cw20/service.js +28 -21
  47. package/build/token-cw20/service.js.map +1 -1
  48. package/build/token-erc20/service.d.ts +2 -3
  49. package/build/token-erc20/service.js +10 -15
  50. package/build/token-erc20/service.js.map +1 -1
  51. package/build/token-scan/service.js +27 -23
  52. package/build/token-scan/service.js.map +1 -1
  53. package/build/tx/service.d.ts +1 -0
  54. package/build/tx/service.js +41 -10
  55. package/build/tx/service.js.map +1 -1
  56. package/build/tx-ethereum/service.js +5 -9
  57. package/build/tx-ethereum/service.js.map +1 -1
  58. package/build/tx-executor/service.js +2 -7
  59. package/build/tx-executor/service.js.map +1 -1
  60. package/build/tx-executor/types.d.ts +7 -1
  61. package/build/tx-executor/types.js.map +1 -1
  62. package/build/tx-executor/utils/evm.d.ts +2 -2
  63. package/build/tx-executor/utils/evm.js +75 -26
  64. package/build/tx-executor/utils/evm.js.map +1 -1
  65. package/package.json +13 -13
  66. package/src/chains/convert.ts +126 -0
  67. package/src/chains/handler.ts +1 -1
  68. package/src/chains/index.ts +1 -0
  69. package/src/chains/messages.ts +1 -1
  70. package/src/chains/service.ts +64 -97
  71. package/src/chains-ui/service.ts +8 -7
  72. package/src/chains-update/service.ts +2 -2
  73. package/src/keyring/handler.ts +34 -19
  74. package/src/keyring/service.ts +137 -96
  75. package/src/keyring-bitcoin/service.ts +2 -2
  76. package/src/keyring-cosmos/service.ts +46 -18
  77. package/src/keyring-ethereum/service.ts +24 -17
  78. package/src/keyring-ledger/service.ts +10 -10
  79. package/src/keyring-starknet/service.ts +7 -7
  80. package/src/manage-view-asset-token/service.ts +2 -3
  81. package/src/permission/service.ts +3 -7
  82. package/src/recent-send-history/service.ts +141 -95
  83. package/src/secret-wasm/service.ts +39 -45
  84. package/src/token-cw20/service.ts +36 -30
  85. package/src/token-erc20/service.ts +15 -18
  86. package/src/token-scan/service.ts +34 -21
  87. package/src/tx/service.ts +60 -12
  88. package/src/tx-ethereum/service.ts +8 -8
  89. package/src/tx-executor/service.ts +4 -6
  90. package/src/tx-executor/types.ts +9 -1
  91. package/src/tx-executor/utils/evm.ts +92 -32
  92. package/tsconfig.check.json +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keplr-wallet/background",
3
- "version": "0.13.13",
3
+ "version": "0.13.15-rc.0",
4
4
  "main": "build/index.js",
5
5
  "author": "chainapsis",
6
6
  "license": "Apache-2.0",
@@ -33,17 +33,17 @@
33
33
  "@ethersproject/hash": "^5.7.0",
34
34
  "@ethersproject/transactions": "^5.7.0",
35
35
  "@ethersproject/wallet": "^5.7.0",
36
- "@keplr-wallet/chain-validator": "0.13.13",
37
- "@keplr-wallet/common": "0.13.13",
38
- "@keplr-wallet/cosmos": "0.13.13",
39
- "@keplr-wallet/crypto": "0.13.13",
40
- "@keplr-wallet/ledger-cosmos": "0.13.13",
41
- "@keplr-wallet/popup": "0.13.13",
42
- "@keplr-wallet/proto-types": "0.13.13",
43
- "@keplr-wallet/router": "0.13.13",
44
- "@keplr-wallet/simple-fetch": "0.13.13",
45
- "@keplr-wallet/types": "0.13.13",
46
- "@keplr-wallet/unit": "0.13.13",
36
+ "@keplr-wallet/chain-validator": "0.13.15-rc.0",
37
+ "@keplr-wallet/common": "0.13.15-rc.0",
38
+ "@keplr-wallet/cosmos": "0.13.15-rc.0",
39
+ "@keplr-wallet/crypto": "0.13.15-rc.0",
40
+ "@keplr-wallet/ledger-cosmos": "0.13.15-rc.0",
41
+ "@keplr-wallet/popup": "0.13.15-rc.0",
42
+ "@keplr-wallet/proto-types": "0.13.15-rc.0",
43
+ "@keplr-wallet/router": "0.13.15-rc.0",
44
+ "@keplr-wallet/simple-fetch": "0.13.15-rc.0",
45
+ "@keplr-wallet/types": "0.13.15-rc.0",
46
+ "@keplr-wallet/unit": "0.13.15-rc.0",
47
47
  "@ledgerhq/hw-app-eth": "6.42.8",
48
48
  "@ledgerhq/hw-app-starknet": "^3.0.1",
49
49
  "@ledgerhq/hw-transport": "^6.31.4",
@@ -70,5 +70,5 @@
70
70
  "mobx-utils": "^6",
71
71
  "starknet": "^7"
72
72
  },
73
- "gitHead": "d806e87af06491dd189d849f69614a8b06c627bc"
73
+ "gitHead": "5a3e0763e91ef98e83059cb7340074b5967cf897"
74
74
  }
@@ -0,0 +1,126 @@
1
+ import {
2
+ AppCurrency,
3
+ ChainInfo,
4
+ ERC20Currency,
5
+ EvmChainInfo,
6
+ ModularChainInfo,
7
+ } from "@keplr-wallet/types";
8
+ import { DenomHelper } from "@keplr-wallet/common";
9
+
10
+ function toERC20Currency(currency: AppCurrency): ERC20Currency {
11
+ if (
12
+ "type" in currency &&
13
+ currency.type === "erc20" &&
14
+ "contractAddress" in currency
15
+ ) {
16
+ return currency as ERC20Currency;
17
+ }
18
+ const denomHelper = new DenomHelper(currency.coinMinimalDenom);
19
+ return {
20
+ ...currency,
21
+ type: "erc20" as const,
22
+ contractAddress: denomHelper.contractAddress,
23
+ };
24
+ }
25
+
26
+ export function convertChainInfoToModularChainInfo(
27
+ chainInfo: ChainInfo
28
+ ): ModularChainInfo {
29
+ const common = {
30
+ isV2: true as const,
31
+ chainId: chainInfo.chainId,
32
+ chainName: chainInfo.chainName,
33
+ chainSymbolImageUrl: chainInfo.chainSymbolImageUrl,
34
+ isTestnet: chainInfo.isTestnet,
35
+ hideInUI: chainInfo.hideInUI,
36
+ };
37
+
38
+ if (chainInfo.evm) {
39
+ const erc20Tokens: ERC20Currency[] = [];
40
+ const nonERC20Currencies: AppCurrency[] = [];
41
+ for (const currency of chainInfo.currencies) {
42
+ const denomHelper = new DenomHelper(currency.coinMinimalDenom);
43
+ if (denomHelper.type === "erc20") {
44
+ erc20Tokens.push(toERC20Currency(currency));
45
+ } else {
46
+ nonERC20Currencies.push(currency);
47
+ }
48
+ }
49
+
50
+ const nativeCurrency =
51
+ nonERC20Currencies.find((cur) => {
52
+ const dh = new DenomHelper(cur.coinMinimalDenom);
53
+ return dh.type === "native";
54
+ }) ?? nonERC20Currencies[0];
55
+
56
+ if (!nativeCurrency) {
57
+ throw new Error(
58
+ `Chain ${chainInfo.chainId} has evm module but no non-ERC20 native currency`
59
+ );
60
+ }
61
+
62
+ const evm: EvmChainInfo = {
63
+ chainId: chainInfo.evm.chainId,
64
+ rpc: chainInfo.evm.rpc,
65
+ websocket: chainInfo.evm.websocket,
66
+ nativeCurrency: nativeCurrency,
67
+ tokens: erc20Tokens,
68
+ features: chainInfo.features,
69
+ };
70
+
71
+ if (chainInfo.chainId.startsWith("eip155:")) {
72
+ return { ...common, type: "evm", evm };
73
+ }
74
+
75
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
76
+ const { evm: _, ...cosmosWithoutEvm } = chainInfo;
77
+ return { ...common, type: "ethermint", cosmos: cosmosWithoutEvm, evm };
78
+ }
79
+
80
+ return { ...common, type: "cosmos" as const, cosmos: chainInfo };
81
+ }
82
+
83
+ /**
84
+ * ModularChainInfo를 ChainInfo로 역변환한다.
85
+ * cosmos, ethermint, evm 타입만 변환 가능. starknet/bitcoin은 undefined 반환.
86
+ */
87
+ export function convertModularChainInfoToChainInfo(
88
+ m: ModularChainInfo
89
+ ): ChainInfo | undefined {
90
+ if (m.type === "cosmos") {
91
+ return m.cosmos as ChainInfo;
92
+ }
93
+
94
+ if (m.type === "ethermint") {
95
+ return {
96
+ ...m.cosmos,
97
+ evm: {
98
+ chainId: m.evm.chainId,
99
+ rpc: m.evm.rpc,
100
+ websocket: m.evm.websocket,
101
+ },
102
+ } as ChainInfo;
103
+ }
104
+
105
+ if (m.type === "evm") {
106
+ return {
107
+ rpc: m.evm.rpc,
108
+ rest: m.evm.rpc,
109
+ chainId: m.chainId,
110
+ chainName: m.chainName,
111
+ chainSymbolImageUrl: m.chainSymbolImageUrl,
112
+ isTestnet: m.isTestnet,
113
+ bip44: { coinType: 60 },
114
+ currencies: [m.evm.nativeCurrency, ...m.evm.tokens],
115
+ feeCurrencies: [m.evm.nativeCurrency],
116
+ features: m.evm.features,
117
+ evm: {
118
+ chainId: m.evm.chainId,
119
+ rpc: m.evm.rpc,
120
+ websocket: m.evm.websocket,
121
+ },
122
+ };
123
+ }
124
+
125
+ return undefined;
126
+ }
@@ -107,7 +107,7 @@ const handleGetInfosWithCoreTypesMsg: (
107
107
  return () => {
108
108
  return {
109
109
  chainInfos: service.getChainInfosWithCoreTypes(),
110
- modulrChainInfos: service.getModularChainInfos(),
110
+ modularChainInfos: service.getModularChainInfos(),
111
111
  };
112
112
  };
113
113
  };
@@ -1,3 +1,4 @@
1
1
  export * from "./service";
2
2
  export * from "./messages";
3
3
  export * from "./types";
4
+ export * from "./convert";
@@ -31,7 +31,7 @@ export class PingMsg extends Message<void> {
31
31
 
32
32
  export class GetChainInfosWithCoreTypesMsg extends Message<{
33
33
  chainInfos: ChainInfoWithCoreTypes[];
34
- modulrChainInfos: ModularChainInfo[];
34
+ modularChainInfos: ModularChainInfo[];
35
35
  }> {
36
36
  public static type() {
37
37
  return "get-chain-infos-with-core-types";
@@ -32,10 +32,11 @@ import { InteractionService } from "../interaction";
32
32
  import { Env } from "@keplr-wallet/router";
33
33
  import { SuggestChainInfoMsg } from "./messages";
34
34
  import { ChainInfoWithCoreTypes, ChainInfoWithSuggestedOptions } from "./types";
35
+ import { convertChainInfoToModularChainInfo } from "./convert";
35
36
  import { AnalyticsService } from "../analytics";
36
37
  import { runIfOnlyAppStart } from "../utils";
37
38
 
38
- type ChainRemovedHandler = (chainInfo: ChainInfo) => void;
39
+ type ChainRemovedHandler = (chainId: string) => void;
39
40
  type ChainSuggestedHandler = (
40
41
  chainInfo: ChainInfo,
41
42
  options?: Record<string, any>
@@ -104,31 +105,15 @@ export class ChainsService {
104
105
  ) {
105
106
  this.modularChainInfos = embedModularChainInfos.map((modularChainInfo) => {
106
107
  if ("currencies" in modularChainInfo) {
107
- return {
108
- chainId: modularChainInfo.chainId,
109
- chainName: modularChainInfo.chainName,
110
- chainSymbolImageUrl: modularChainInfo.chainSymbolImageUrl,
111
- cosmos: modularChainInfo,
112
- };
108
+ return convertChainInfoToModularChainInfo(modularChainInfo);
113
109
  }
110
+ // Already ModularChainInfo
114
111
  return modularChainInfo;
115
112
  });
116
- this.embedChainInfos = embedModularChainInfos
117
- .filter(
118
- (modularChainInfo) =>
119
- "currencies" in modularChainInfo || "cosmos" in modularChainInfo
120
- )
121
- .map((modularChainInfo) => {
122
- if ("currencies" in modularChainInfo) {
123
- return modularChainInfo;
124
- }
125
- if (!("cosmos" in modularChainInfo)) {
126
- throw new Error("Can't be happen");
127
- }
128
- return {
129
- ...modularChainInfo.cosmos,
130
- };
131
- });
113
+ this.embedChainInfos = embedModularChainInfos.filter(
114
+ (modularChainInfo): modularChainInfo is ChainInfoWithCoreTypes =>
115
+ "currencies" in modularChainInfo
116
+ );
132
117
 
133
118
  this.updatedChainInfoKVStore = new PrefixKVStore(
134
119
  kvStore,
@@ -941,7 +926,7 @@ export class ChainsService {
941
926
  this.suggestedChainInfos
942
927
  );
943
928
  const starknetChainInfos = this.modularChainInfos.reduce((acc, cur) => {
944
- if ("starknet" in cur) {
929
+ if (cur.type === "starknet") {
945
930
  acc.push(cur.starknet);
946
931
  }
947
932
  return acc;
@@ -1150,31 +1135,31 @@ export class ChainsService {
1150
1135
  protected mergeModularChainInfosWithDynamics(
1151
1136
  modularChainInfos: ModularChainInfo[]
1152
1137
  ): ModularChainInfo[] {
1153
- return modularChainInfos.map((modularChainInfo) => {
1154
- if (this.hasChainInfo(modularChainInfo.chainId)) {
1155
- const cosmos = this.getChainInfoOrThrow(modularChainInfo.chainId);
1138
+ return modularChainInfos.map((m) => {
1139
+ if (
1140
+ (m.type === "cosmos" || m.type === "ethermint" || m.type === "evm") &&
1141
+ this.hasChainInfo(m.chainId)
1142
+ ) {
1143
+ const merged = this.getChainInfoOrThrow(m.chainId);
1156
1144
  return {
1157
- chainId: cosmos.chainId,
1158
- chainName: cosmos.chainName,
1159
- chainSymbolImageUrl: cosmos.chainSymbolImageUrl,
1160
- isTestnet: cosmos.isTestnet,
1161
- cosmos: this.mergeChainInfosWithDynamics([cosmos])[0],
1145
+ ...m,
1146
+ ...convertChainInfoToModularChainInfo(merged),
1162
1147
  };
1163
1148
  }
1164
1149
 
1165
- if ("starknet" in modularChainInfo) {
1166
- const endpoint = this.getEndpoint(modularChainInfo.chainId);
1150
+ if (m.type === "starknet") {
1151
+ const endpoint = this.getEndpoint(m.chainId);
1167
1152
  return {
1168
- ...modularChainInfo,
1153
+ ...m,
1169
1154
  starknet: {
1170
- ...modularChainInfo.starknet,
1171
- rpc: endpoint?.rpc || modularChainInfo.starknet.rpc,
1155
+ ...m.starknet,
1156
+ rpc: endpoint?.rpc || m.starknet.rpc,
1172
1157
  },
1173
1158
  };
1174
1159
  }
1175
1160
 
1176
1161
  // TODO: 나머지 모듈러 체인 정보들에 대해서도 적용하기
1177
- return modularChainInfo;
1162
+ return m;
1178
1163
  });
1179
1164
  }
1180
1165
 
@@ -1229,7 +1214,7 @@ export class ChainsService {
1229
1214
  }
1230
1215
 
1231
1216
  for (const handler of this.onChainRemovedHandlers) {
1232
- handler(updated);
1217
+ handler(updated.chainId);
1233
1218
  }
1234
1219
  }
1235
1220
 
@@ -1237,7 +1222,7 @@ export class ChainsService {
1237
1222
  this.onChainRemovedHandlers.push(handler);
1238
1223
  }
1239
1224
 
1240
- addChainSuggestedHandler(handler: ChainRemovedHandler) {
1225
+ addChainSuggestedHandler(handler: ChainSuggestedHandler) {
1241
1226
  this.onChainSuggestedHandlers.push(handler);
1242
1227
  }
1243
1228
 
@@ -1251,28 +1236,24 @@ export class ChainsService {
1251
1236
  }
1252
1237
 
1253
1238
  getEVMInfoOrThrow(chainId: string): EVMInfo {
1254
- const chainInfo = this.getChainInfoOrThrow(chainId);
1255
- if (chainInfo.evm === undefined) {
1239
+ const modularChainInfo = this.getModularChainInfoOrThrow(chainId);
1240
+ if (
1241
+ modularChainInfo.type !== "evm" &&
1242
+ modularChainInfo.type !== "ethermint"
1243
+ ) {
1256
1244
  throw new Error(`There is no EVM info for ${chainId}`);
1257
1245
  }
1258
1246
 
1259
- return chainInfo.evm;
1247
+ return modularChainInfo.evm;
1260
1248
  }
1261
1249
 
1262
1250
  getModularChainInfos = computedFn(
1263
1251
  (): ModularChainInfo[] => {
1264
1252
  return this.mergeModularChainInfosWithDynamics(
1265
- this.modularChainInfos.slice()
1253
+ this.modularChainInfos.map((m) => ({ ...m, isBuiltInChain: true }))
1266
1254
  ).concat(
1267
1255
  this.mergeChainInfosWithDynamics(this.suggestedChainInfos).map(
1268
- (chainInfo) => {
1269
- return {
1270
- chainId: chainInfo.chainId,
1271
- chainName: chainInfo.chainName,
1272
- chainSymbolImageUrl: chainInfo.chainSymbolImageUrl,
1273
- cosmos: chainInfo,
1274
- };
1275
- }
1256
+ (chainInfo) => convertChainInfoToModularChainInfo(chainInfo)
1276
1257
  )
1277
1258
  );
1278
1259
  },
@@ -1283,8 +1264,8 @@ export class ChainsService {
1283
1264
 
1284
1265
  hasModularChainInfo = computedFn((chainId: string): boolean => {
1285
1266
  return this.getModularChainInfos().some(
1286
- (modularChainInfo) =>
1287
- ChainIdHelper.parse(modularChainInfo.chainId).identifier ===
1267
+ (m) =>
1268
+ ChainIdHelper.parse(m.chainId).identifier ===
1288
1269
  ChainIdHelper.parse(chainId).identifier
1289
1270
  );
1290
1271
  });
@@ -1292,36 +1273,40 @@ export class ChainsService {
1292
1273
  getModularChainInfo = computedFn(
1293
1274
  (chainId: string): ModularChainInfo | undefined => {
1294
1275
  return this.getModularChainInfos().find(
1295
- (modularChainInfo) =>
1296
- ChainIdHelper.parse(modularChainInfo.chainId).identifier ===
1276
+ (m) =>
1277
+ ChainIdHelper.parse(m.chainId).identifier ===
1297
1278
  ChainIdHelper.parse(chainId).identifier
1298
1279
  );
1299
1280
  }
1300
1281
  );
1301
1282
 
1283
+ getModularChainInfoOrThrow(chainId: string): ModularChainInfo {
1284
+ const m = this.getModularChainInfo(chainId);
1285
+ if (!m) {
1286
+ throw new Error(`There is no modular chain info for ${chainId}`);
1287
+ }
1288
+ return m;
1289
+ }
1290
+
1302
1291
  getModularChainInfoWithLinkedChainKey = computedFn(
1303
1292
  (chainId: string): ModularChainInfo[] => {
1304
1293
  const res: ModularChainInfo[] = [];
1305
1294
 
1306
1295
  let linkedChainKey: string | undefined;
1307
1296
  if (this.hasModularChainInfo(chainId)) {
1308
- const modularChainInfo = this.getModularChainInfoOrThrow(chainId);
1309
- if ("linkedChainKey" in modularChainInfo) {
1310
- linkedChainKey = modularChainInfo.linkedChainKey;
1311
- }
1312
- res.push(modularChainInfo);
1297
+ const m = this.getModularChainInfoOrThrow(chainId);
1298
+ linkedChainKey = m.linkedChainKey;
1299
+ res.push(m);
1313
1300
  }
1314
1301
 
1315
1302
  if (linkedChainKey) {
1316
1303
  const chainIdentifier = ChainIdHelper.parse(chainId).identifier;
1317
- for (const modularChainInfo of this.modularChainInfos) {
1304
+ for (const m of this.getModularChainInfos()) {
1318
1305
  if (
1319
- ChainIdHelper.parse(modularChainInfo.chainId).identifier !==
1320
- chainIdentifier &&
1321
- "linkedChainKey" in modularChainInfo &&
1322
- modularChainInfo.linkedChainKey === linkedChainKey
1306
+ ChainIdHelper.parse(m.chainId).identifier !== chainIdentifier &&
1307
+ m.linkedChainKey === linkedChainKey
1323
1308
  ) {
1324
- res.push(modularChainInfo);
1309
+ res.push(m);
1325
1310
  }
1326
1311
  }
1327
1312
  }
@@ -1330,30 +1315,21 @@ export class ChainsService {
1330
1315
  }
1331
1316
  );
1332
1317
 
1333
- getModularChainInfoOrThrow(chainId: string): ModularChainInfo {
1334
- const modularChainInfo = this.getModularChainInfo(chainId);
1335
- if (!modularChainInfo) {
1336
- throw new Error(`There is no modular chain info for ${chainId}`);
1337
- }
1338
-
1339
- return modularChainInfo;
1340
- }
1341
-
1342
1318
  hasStarknetChainInfo(chainId: string): boolean {
1343
- const modularChainInfo = this.getModularChainInfo(chainId);
1344
- if (!modularChainInfo) {
1319
+ const m = this.getModularChainInfo(chainId);
1320
+ if (!m) {
1345
1321
  return false;
1346
1322
  }
1347
- return "starknet" in modularChainInfo;
1323
+ return m.type === "starknet";
1348
1324
  }
1349
1325
 
1350
1326
  getStarknetChainInfo(chainId: string): StarknetChainInfo | undefined {
1351
- const modularChainInfo = this.getModularChainInfo(chainId);
1352
- if (!modularChainInfo) {
1327
+ const m = this.getModularChainInfo(chainId);
1328
+ if (!m) {
1353
1329
  return undefined;
1354
1330
  }
1355
- if ("starknet" in modularChainInfo) {
1356
- return modularChainInfo.starknet;
1331
+ if (m.type === "starknet") {
1332
+ return m.starknet;
1357
1333
  }
1358
1334
  }
1359
1335
 
@@ -1362,7 +1338,6 @@ export class ChainsService {
1362
1338
  if (!starknetChainInfo) {
1363
1339
  throw new Error(`There is no starknet chain info for ${chainId}`);
1364
1340
  }
1365
-
1366
1341
  return starknetChainInfo;
1367
1342
  }
1368
1343
 
@@ -1372,14 +1347,14 @@ export class ChainsService {
1372
1347
  const directMatch = modularChainInfos.find(
1373
1348
  (info) => info.chainId === chainId
1374
1349
  );
1375
- if (directMatch && "bitcoin" in directMatch) {
1350
+ if (directMatch && directMatch.type === "bitcoin") {
1376
1351
  return directMatch.bitcoin;
1377
1352
  }
1378
1353
 
1379
1354
  const baseChainMatch = modularChainInfos.find(
1380
- (info) => "bitcoin" in info && info.bitcoin.chainId === chainId
1355
+ (info) => info.type === "bitcoin" && info.bitcoin.chainId === chainId
1381
1356
  );
1382
- if (baseChainMatch && "bitcoin" in baseChainMatch) {
1357
+ if (baseChainMatch && baseChainMatch.type === "bitcoin") {
1383
1358
  return baseChainMatch.bitcoin;
1384
1359
  }
1385
1360
  }
@@ -1389,16 +1364,9 @@ export class ChainsService {
1389
1364
  if (!bitcoinChainInfo) {
1390
1365
  throw new Error(`There is no bitcoin chain info for ${chainId}`);
1391
1366
  }
1392
-
1393
1367
  return bitcoinChainInfo;
1394
1368
  }
1395
1369
 
1396
- /**
1397
- * 여러 주소 체계가 존재하는 체인의 경우, chainId에서 주소 체계를 제외한 공통된 부분을 사용하여 하나의 체인으로 취급해야 한다.
1398
- * 예를 들어, Bitcoin의 경우 `bip122:123456:taproot`와 `bip122:123456:native-segwit`를 사용해
1399
- * 각 주소 체계를 구분하고 있지만, 공통된 `bip122:123456`을 사용하여 하나의 체인으로 취급되어야 한다.
1400
- * TODO: 비트 코인 외에도 여러 주소 체계가 존재하는 체인이 추가될 경우, 이 메서드의 부분적인 수정이 필요하다.
1401
- */
1402
1370
  getBaseChainId(chainId: string): string | undefined {
1403
1371
  chainId = ChainIdHelper.parse(chainId).identifier;
1404
1372
 
@@ -1408,14 +1376,14 @@ export class ChainsService {
1408
1376
  (info) => ChainIdHelper.parse(info.chainId).identifier === chainId
1409
1377
  );
1410
1378
  if (directMatch) {
1411
- if ("bitcoin" in directMatch) {
1379
+ if (directMatch.type === "bitcoin") {
1412
1380
  return directMatch.bitcoin.chainId;
1413
1381
  }
1414
1382
  return chainId;
1415
1383
  }
1416
1384
 
1417
1385
  const baseChainMatch = modularChainInfos.find(
1418
- (info) => "bitcoin" in info && info.bitcoin.chainId === chainId
1386
+ (info) => info.type === "bitcoin" && info.bitcoin.chainId === chainId
1419
1387
  );
1420
1388
  if (baseChainMatch) {
1421
1389
  return chainId;
@@ -1429,7 +1397,6 @@ export class ChainsService {
1429
1397
  if (!baseChainId) {
1430
1398
  throw new Error(`There is no modular chain info for ${chainId}`);
1431
1399
  }
1432
-
1433
1400
  return baseChainId;
1434
1401
  }
1435
1402
  }
@@ -9,7 +9,7 @@ import {
9
9
  toJS,
10
10
  } from "mobx";
11
11
  import { KVStore } from "@keplr-wallet/common";
12
- import { ChainInfo, ModularChainInfo } from "@keplr-wallet/types";
12
+ import { ModularChainInfo } from "@keplr-wallet/types";
13
13
  import { ChainIdHelper } from "@keplr-wallet/cosmos";
14
14
  import { computedFn } from "mobx-utils";
15
15
  import { VaultService } from "../vault";
@@ -76,8 +76,9 @@ export class ChainsUIService {
76
76
  if (chainIdentifiers.length === 0) {
77
77
  // Should be enabled at least one chain.
78
78
  return [
79
- ChainIdHelper.parse(this.chainsService.getChainInfos()[0].chainId)
80
- .identifier,
79
+ ChainIdHelper.parse(
80
+ this.chainsService.getModularChainInfos()[0].chainId
81
+ ).identifier,
81
82
  ];
82
83
  } else {
83
84
  return chainIdentifiers;
@@ -140,7 +141,7 @@ export class ChainsUIService {
140
141
  return ChainIdHelper.parse(chainId).identifier;
141
142
  })
142
143
  .filter((chainIdentifier) => {
143
- return this.chainsService.hasChainInfo(chainIdentifier);
144
+ return this.chainsService.hasModularChainInfo(chainIdentifier);
144
145
  });
145
146
 
146
147
  const identifierMap = this.enabledChainIdentifierMapForVault(vaultId);
@@ -253,7 +254,7 @@ export class ChainsUIService {
253
254
  }
254
255
  }
255
256
  return Array.from(set).filter((chainIdentifier) => {
256
- return this.chainsService.hasChainInfo(chainIdentifier);
257
+ return this.chainsService.hasModularChainInfo(chainIdentifier);
257
258
  });
258
259
  }
259
260
 
@@ -261,9 +262,9 @@ export class ChainsUIService {
261
262
  this.onChainUIEnabledChangedHandlers.push(handler);
262
263
  }
263
264
 
264
- protected readonly onChainRemoved = (chainInfo: ChainInfo) => {
265
+ protected readonly onChainRemoved = (chainId: string) => {
265
266
  runInAction(() => {
266
- const identifier = ChainIdHelper.parse(chainInfo.chainId).identifier;
267
+ const identifier = ChainIdHelper.parse(chainId).identifier;
267
268
  const vaultIds = this.enabledChainIdentifiersMap.keys();
268
269
  for (const vaultId of vaultIds) {
269
270
  const map = (() => {
@@ -68,8 +68,8 @@ export class ChainsUpdateService {
68
68
  });
69
69
  });
70
70
 
71
- this.chainsService.addChainRemovedHandler((chainInfo) => {
72
- this.updateChainInfo(chainInfo.chainId).catch((e) => {
71
+ this.chainsService.addChainRemovedHandler((chainId) => {
72
+ this.updateChainInfo(chainId).catch((e) => {
73
73
  console.log(e);
74
74
  });
75
75
  });
@@ -523,28 +523,43 @@ const handleGetAllWalletsMsg: (
523
523
  const modularChainInfo =
524
524
  chainsService.getModularChainInfoOrThrow(chainIdentifier);
525
525
 
526
- if ("cosmos" in modularChainInfo) {
527
- const key = await keyRingCosmosService.getKey(
528
- keyInfo.id,
529
- modularChainInfo.chainId
530
- );
531
- const chainInfo = modularChainInfo.cosmos;
532
- const isEthermintLike = KeyRingService.isEthermintLike(chainInfo);
533
- const evmInfo = ChainsService.getEVMInfo(chainInfo);
534
-
535
- if (isEthermintLike || evmInfo !== undefined) {
536
- addresses[modularChainInfo.chainId] = key.ethereumHexAddress;
537
- } else {
526
+ switch (modularChainInfo.type) {
527
+ case "cosmos": {
528
+ const key = await keyRingCosmosService.getKey(
529
+ keyInfo.id,
530
+ modularChainInfo.chainId
531
+ );
538
532
  addresses[modularChainInfo.chainId] = key.bech32Address;
533
+ break;
534
+ }
535
+ case "ethermint": {
536
+ const key = await keyRingCosmosService.getKey(
537
+ keyInfo.id,
538
+ modularChainInfo.chainId
539
+ );
540
+ addresses[modularChainInfo.chainId] = key.ethereumHexAddress;
541
+ break;
542
+ }
543
+ case "evm": {
544
+ const key = await keyRingCosmosService.getKey(
545
+ keyInfo.id,
546
+ modularChainInfo.chainId
547
+ );
548
+ addresses[modularChainInfo.chainId] = key.ethereumHexAddress;
549
+ break;
550
+ }
551
+ case "starknet": {
552
+ const starknetKey = await keyRingStarknetService.getStarknetKey(
553
+ keyInfo.id,
554
+ modularChainInfo.chainId
555
+ );
556
+ addresses[modularChainInfo.chainId] = starknetKey.hexAddress;
557
+ break;
539
558
  }
540
- } else if ("starknet" in modularChainInfo) {
541
- const starknetKey = await keyRingStarknetService.getStarknetKey(
542
- keyInfo.id,
543
- modularChainInfo.chainId
544
- );
545
- addresses[modularChainInfo.chainId] = starknetKey.hexAddress;
559
+ case "bitcoin":
560
+ // Bitcoin: skip (out of scope)
561
+ break;
546
562
  }
547
- // Bitcoin: skip (out of scope)
548
563
  } catch (e) {
549
564
  console.log(e);
550
565
  continue;