Skip to content
This repository was archived by the owner on Oct 10, 2023. It is now read-only.

Commit acb581e

Browse files
authored
Fix: lcd-cosmos.cosmosstation.io api is down - pt2 (#2382)
`https://lcd-cosmoshub.keplr.app` api is lacking in case of tx history + `node_info` - that's why previous fix #2375 was not that successful. Use `https://cosmos-lcd.quickapi.com` instead.
1 parent a03295e commit acb581e

File tree

5 files changed

+40
-46
lines changed

5 files changed

+40
-46
lines changed

.env.sample

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ REACT_APP_LTC_NODE_USERNAME=XXX
4949
REACT_APP_LTC_NODE_PASSWORD=XXX
5050

5151
# COSMOS
52-
REACT_APP_COSMOS_MAINNET_LCD = https://lcd-cosmoshub.keplr.app
52+
REACT_APP_COSMOS_MAINNET_LCD = https://cosmos-lcd.quickapi.com

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
- Use 9R Midgard by default [#2363](https://github.com/thorchain/asgardex-electron/pull/2363)
2222
- Fix deprecated usage of Antd.Menu children [#2372](https://github.com/thorchain/asgardex-electron/pull/2372)
2323
- [Ledger] Fix/extend HD pathes for ETH [#2344](https://github.com/thorchain/asgardex-electron/issues/2344)
24-
- Fix: lcd-cosmos.cosmosstation.io api is down [#2375](https://github.com/thorchain/asgardex-electron/pull/2375)
24+
- Fix: lcd-cosmos.cosmosstation.io api is down - pt2 [#2382](https://github.com/thorchain/asgardex-electron/pull/2382)
2525

2626
## Remove
2727

src/main/api/ledger/cosmos/transaction.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import {
1111
protoFee,
1212
protoAuthInfo,
1313
protoMsgSend,
14-
protoTxBody,
15-
getDefaultChainIds
14+
protoTxBody
1615
} from '@xchainjs/xchain-cosmos'
1716
import { Asset, assetToString, BaseAmount } from '@xchainjs/xchain-util'
1817
import BigNumber from 'bignumber.js'
@@ -77,9 +76,7 @@ export const send = async ({
7776
const fee = protoFee({ denom, amount: feeAmount, gasLimit })
7877

7978
const clientUrls = getClientUrls()
80-
const chainId =
81-
// request chain id (for testnet only, cosmoshub.keplr.app does not an endpoint for it)
82-
network === 'testnet' ? await getChainId(clientUrls[clientNetwork]) : getDefaultChainIds()[network]
79+
const chainId = await getChainId(clientUrls[clientNetwork])
8380

8481
const app = new CosmosApp(transport)
8582
const path = getDerivationPath(walletIndex)

src/renderer/services/cosmos/common.ts

+33-35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as RD from '@devexperts/remote-data-ts'
2-
import { Client, getChainId, getDefaultChainIds } from '@xchainjs/xchain-cosmos'
2+
import { Client, getChainId } from '@xchainjs/xchain-cosmos'
33
import { CosmosChain } from '@xchainjs/xchain-util'
44
import * as FP from 'fp-ts/lib/function'
55
import * as O from 'fp-ts/lib/Option'
@@ -23,41 +23,39 @@ import type { Client$, ClientState, ClientState$ } from './types'
2323
*/
2424
const clientState$: ClientState$ = FP.pipe(
2525
Rx.combineLatest([keystoreService.keystoreState$, clientNetwork$, Rx.of(getClientUrls())]),
26-
RxOp.switchMap(([keystore, network, clientUrls]): ClientState$ => {
27-
console.log('network:', network)
28-
return FP.pipe(
29-
// request chain id (for testnet only, cosmoshub.keplr.app does not an endpoint for it)
30-
Rx.of(network === 'testnet' ? getChainId(clientUrls[network]) : getDefaultChainIds()[network]),
31-
RxOp.switchMap((chainId) => {
32-
console.log('chainId:', chainId)
33-
console.log('clientUrls:', clientUrls[network])
34-
return Rx.of(
35-
FP.pipe(
36-
getPhrase(keystore),
37-
O.map<string, ClientState>((phrase) => {
38-
try {
39-
const client = new Client({
40-
network,
41-
phrase,
42-
clientUrls: getClientUrls(),
43-
chainIds: { ...INITIAL_CHAIN_IDS, [network]: chainId }
44-
})
45-
return RD.success(client)
46-
} catch (error) {
47-
return RD.failure<Error>(isError(error) ? error : new Error('Failed to create Cosmos client'))
48-
}
49-
}),
50-
// Set back to `initial` if no phrase is available (locked wallet)
51-
O.getOrElse<ClientState>(() => RD.initial)
26+
RxOp.switchMap(
27+
([keystore, network, clientUrls]): ClientState$ =>
28+
FP.pipe(
29+
// request chain id whenever network or keystore are changed
30+
Rx.from(getChainId(clientUrls[network])),
31+
RxOp.switchMap((chainId) =>
32+
Rx.of(
33+
FP.pipe(
34+
getPhrase(keystore),
35+
O.map<string, ClientState>((phrase) => {
36+
try {
37+
const client = new Client({
38+
network,
39+
phrase,
40+
clientUrls: getClientUrls(),
41+
chainIds: { ...INITIAL_CHAIN_IDS, [network]: chainId }
42+
})
43+
return RD.success(client)
44+
} catch (error) {
45+
return RD.failure<Error>(isError(error) ? error : new Error('Failed to create Cosmos client'))
46+
}
47+
}),
48+
// Set back to `initial` if no phrase is available (locked wallet)
49+
O.getOrElse<ClientState>(() => RD.initial)
50+
)
5251
)
53-
)
54-
}),
55-
RxOp.catchError((error) =>
56-
Rx.of(RD.failure<Error>(new Error(`Failed to get Cosmos' chain id (${error?.msg ?? error.toString()})`)))
57-
),
58-
RxOp.startWith(RD.pending)
59-
)
60-
}),
52+
),
53+
RxOp.catchError((error) =>
54+
Rx.of(RD.failure<Error>(new Error(`Failed to get Cosmos' chain id (${error?.msg ?? error.toString()})`)))
55+
),
56+
RxOp.startWith(RD.pending)
57+
)
58+
),
6159
RxOp.startWith(RD.initial),
6260
RxOp.shareReplay(1)
6361
)

src/shared/cosmos/client.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,22 @@ import { envOrDefault } from '../utils/env'
66
// expose env (needed to access ENVs by `envOrDefault`) in `main` thread)
77
require('dotenv').config()
88

9-
const MAINNET_LCD = envOrDefault(process.env.REACT_APP_COSMOS_MAINNET_LCD, 'https://lcd-cosmoshub.keplr.app')
9+
const MAINNET_LCD = envOrDefault(process.env.REACT_APP_COSMOS_MAINNET_LCD, 'https://cosmos-lcd.quickapi.com')
1010

1111
export const getClientUrls = (): ClientUrls => ({
1212
[Network.Stagenet]: MAINNET_LCD,
1313
[Network.Mainnet]: MAINNET_LCD,
1414
[Network.Testnet]: 'https://rest.sentry-01.theta-testnet.polypore.xyz'
1515
})
1616

17-
const mainChainId = 'cosmoshub-4'
1817
/**
1918
* Default Cosmos' chain ids
2019
*
2120
* Note: All 'unknown' will be fetched from Cosmos `node_info`` endpoint
2221
* just before initializing a `xchain-cosmos` client
2322
*/
2423
export const INITIAL_CHAIN_IDS: ChainIds = {
25-
[Network.Mainnet]: mainChainId, // can't be fetched for `lcd-cosmoshub.keplr.app`
26-
[Network.Stagenet]: mainChainId, // can't be fetched for `lcd-cosmoshub.keplr.app`
24+
[Network.Mainnet]: 'unkown-mainnet-chain-id', // will be fetched
25+
[Network.Stagenet]: 'unkown-mainnet-chain-id', // will be fetched
2726
[Network.Testnet]: 'unkown-testnet-chain-id' // will be fetched
2827
}

0 commit comments

Comments
 (0)