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

Commit

Permalink
Fix: lcd-cosmos.cosmosstation.io api is down - pt2 (#2382)
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
veado authored Aug 28, 2022
1 parent a03295e commit acb581e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ REACT_APP_LTC_NODE_USERNAME=XXX
REACT_APP_LTC_NODE_PASSWORD=XXX

# COSMOS
REACT_APP_COSMOS_MAINNET_LCD = https://lcd-cosmoshub.keplr.app
REACT_APP_COSMOS_MAINNET_LCD = https://cosmos-lcd.quickapi.com
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
- Use 9R Midgard by default [#2363](https://github.com/thorchain/asgardex-electron/pull/2363)
- Fix deprecated usage of Antd.Menu children [#2372](https://github.com/thorchain/asgardex-electron/pull/2372)
- [Ledger] Fix/extend HD pathes for ETH [#2344](https://github.com/thorchain/asgardex-electron/issues/2344)
- Fix: lcd-cosmos.cosmosstation.io api is down [#2375](https://github.com/thorchain/asgardex-electron/pull/2375)
- Fix: lcd-cosmos.cosmosstation.io api is down - pt2 [#2382](https://github.com/thorchain/asgardex-electron/pull/2382)

## Remove

Expand Down
7 changes: 2 additions & 5 deletions src/main/api/ledger/cosmos/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import {
protoFee,
protoAuthInfo,
protoMsgSend,
protoTxBody,
getDefaultChainIds
protoTxBody
} from '@xchainjs/xchain-cosmos'
import { Asset, assetToString, BaseAmount } from '@xchainjs/xchain-util'
import BigNumber from 'bignumber.js'
Expand Down Expand Up @@ -77,9 +76,7 @@ export const send = async ({
const fee = protoFee({ denom, amount: feeAmount, gasLimit })

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

const app = new CosmosApp(transport)
const path = getDerivationPath(walletIndex)
Expand Down
68 changes: 33 additions & 35 deletions src/renderer/services/cosmos/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as RD from '@devexperts/remote-data-ts'
import { Client, getChainId, getDefaultChainIds } from '@xchainjs/xchain-cosmos'
import { Client, getChainId } from '@xchainjs/xchain-cosmos'
import { CosmosChain } from '@xchainjs/xchain-util'
import * as FP from 'fp-ts/lib/function'
import * as O from 'fp-ts/lib/Option'
Expand All @@ -23,41 +23,39 @@ import type { Client$, ClientState, ClientState$ } from './types'
*/
const clientState$: ClientState$ = FP.pipe(
Rx.combineLatest([keystoreService.keystoreState$, clientNetwork$, Rx.of(getClientUrls())]),
RxOp.switchMap(([keystore, network, clientUrls]): ClientState$ => {
console.log('network:', network)
return FP.pipe(
// request chain id (for testnet only, cosmoshub.keplr.app does not an endpoint for it)
Rx.of(network === 'testnet' ? getChainId(clientUrls[network]) : getDefaultChainIds()[network]),
RxOp.switchMap((chainId) => {
console.log('chainId:', chainId)
console.log('clientUrls:', clientUrls[network])
return Rx.of(
FP.pipe(
getPhrase(keystore),
O.map<string, ClientState>((phrase) => {
try {
const client = new Client({
network,
phrase,
clientUrls: getClientUrls(),
chainIds: { ...INITIAL_CHAIN_IDS, [network]: chainId }
})
return RD.success(client)
} catch (error) {
return RD.failure<Error>(isError(error) ? error : new Error('Failed to create Cosmos client'))
}
}),
// Set back to `initial` if no phrase is available (locked wallet)
O.getOrElse<ClientState>(() => RD.initial)
RxOp.switchMap(
([keystore, network, clientUrls]): ClientState$ =>
FP.pipe(
// request chain id whenever network or keystore are changed
Rx.from(getChainId(clientUrls[network])),
RxOp.switchMap((chainId) =>
Rx.of(
FP.pipe(
getPhrase(keystore),
O.map<string, ClientState>((phrase) => {
try {
const client = new Client({
network,
phrase,
clientUrls: getClientUrls(),
chainIds: { ...INITIAL_CHAIN_IDS, [network]: chainId }
})
return RD.success(client)
} catch (error) {
return RD.failure<Error>(isError(error) ? error : new Error('Failed to create Cosmos client'))
}
}),
// Set back to `initial` if no phrase is available (locked wallet)
O.getOrElse<ClientState>(() => RD.initial)
)
)
)
}),
RxOp.catchError((error) =>
Rx.of(RD.failure<Error>(new Error(`Failed to get Cosmos' chain id (${error?.msg ?? error.toString()})`)))
),
RxOp.startWith(RD.pending)
)
}),
),
RxOp.catchError((error) =>
Rx.of(RD.failure<Error>(new Error(`Failed to get Cosmos' chain id (${error?.msg ?? error.toString()})`)))
),
RxOp.startWith(RD.pending)
)
),
RxOp.startWith(RD.initial),
RxOp.shareReplay(1)
)
Expand Down
7 changes: 3 additions & 4 deletions src/shared/cosmos/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@ import { envOrDefault } from '../utils/env'
// expose env (needed to access ENVs by `envOrDefault`) in `main` thread)
require('dotenv').config()

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

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

const mainChainId = 'cosmoshub-4'
/**
* Default Cosmos' chain ids
*
* Note: All 'unknown' will be fetched from Cosmos `node_info`` endpoint
* just before initializing a `xchain-cosmos` client
*/
export const INITIAL_CHAIN_IDS: ChainIds = {
[Network.Mainnet]: mainChainId, // can't be fetched for `lcd-cosmoshub.keplr.app`
[Network.Stagenet]: mainChainId, // can't be fetched for `lcd-cosmoshub.keplr.app`
[Network.Mainnet]: 'unkown-mainnet-chain-id', // will be fetched
[Network.Stagenet]: 'unkown-mainnet-chain-id', // will be fetched
[Network.Testnet]: 'unkown-testnet-chain-id' // will be fetched
}

0 comments on commit acb581e

Please sign in to comment.