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

Issue 1987/add stagenet #2000

Merged
merged 12 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@ REACT_APP_CHAINS_ENABLED=THOR,BNB,BTC,LTC,BCH,ETH

# Midgard
REACT_APP_MIDGARD_TESTNET_URL=https://testnet.midgard.thorchain.info
REACT_APP_MIDGARD_STAGENET_URL=https://stagenet-midgard.ninerealms.com
REACT_APP_MIDGARD_MAINNET_URL=https://midgard.thorchain.info

# THORnode
REACT_APP_TESTNET_THORNODE_API=https://testnet.thornode.thorchain.info
REACT_APP_STAGENET_THORNODE_API=https://stagenet-thornode.ninerealms.com
REACT_APP_MAINNET_THORNODE_API=https://thornode.thorchain.info
REACT_APP_STAGENET_THORNODE_RPC=https://stagenet-rpc.ninerealms.com
REACT_APP_TESTNET_THORNODE_RPC=https://testnet.rpc.thorchain.info
REACT_APP_MAINNET_THORNODE_RPC=https://rpc.thorchain.info

# BCH
REACT_APP_HASKOIN_TESTNET_URL=https://api.haskoin.com/bchtest
REACT_APP_HASKOIN_MAINNET_URL='https://api.haskoin.com/bch'
REACT_APP_HASKOIN_BCH_TESTNET_URL=https://api.haskoin.com/bchtest
REACT_APP_HASKOIN_BCH_MAINNET_URL=https://api.haskoin.com/bch
REACT_APP_BCH_NODE_TESTNET_URL=https://testnet.bch.thorchain.info
REACT_APP_BCH_NODE_MAINNET_URL=https://mainnet.bch.thorchain.info
REACT_APP_BCH_NODE_USERNAME=XXX
REACT_APP_BCH_NODE_PASSWORD=XXX

# BTC
REACT_APP_SOCHAIN_URL=https://sochain.com/api/v2
REACT_APP_HASKOIN_BTC_TESTNET_URL=https://api.haskoin.com/btctest
REACT_APP_HASKOIN_BTC_MAINNET_URL=https://api.haskoin.com/btc

# BNB
REACT_APP_BINANCE_MAINNET_WS_URI=wss://dex.binance.org/api/ws
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@
"@thorchain/asgardex-util": "^0.9.1",
"@thorchain/ledger-thorchain": "^0.1.0-alpha.2",
"@types/electron-devtools-installer": "^2.2.0",
"@xchainjs/xchain-binance": "^5.3.1",
"@xchainjs/xchain-bitcoin": "0.15.12",
"@xchainjs/xchain-bitcoincash": "0.11.9",
"@xchainjs/xchain-client": "^0.10.3",
"@xchainjs/xchain-cosmos": "^0.13.8",
"@xchainjs/xchain-binance": "^5.4.0",
"@xchainjs/xchain-bitcoin": "^0.17.0",
"@xchainjs/xchain-bitcoincash": "^0.12.0",
"@xchainjs/xchain-client": "^0.11.0",
"@xchainjs/xchain-cosmos": "^0.15.0",
"@xchainjs/xchain-crypto": "^0.2.6",
"@xchainjs/xchain-ethereum": "^0.22.5",
"@xchainjs/xchain-litecoin": "^0.6.10",
"@xchainjs/xchain-thorchain": "^0.19.3",
"@xchainjs/xchain-ethereum": "^0.23.1",
"@xchainjs/xchain-litecoin": "^0.7.0",
"@xchainjs/xchain-thorchain": "^0.20.0",
"@xchainjs/xchain-util": "^0.3.1",
"antd": "^4.16.13",
"axios": "^0.23.0",
Expand Down
8 changes: 6 additions & 2 deletions src/main/api/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ const EXTERNALS_WHITELIST = [
'ltc.bitaps.com',
'www.blockchain.com',
'testnet.thorswap.finance',
'testnet.thorswap.finance',
'stagenet.thorswap.finance',
'app.thorswap.finance',
'viewblock.io',
'midgard.thorchain.info',
'testnet.midgard.thorchain.info',
'stagenet-midgard.ninerealms.com',
'thornode.thorchain.info',
'testnet.thornode.thorchain.info'
'testnet.thornode.thorchain.info',
'stagenet-thornode.ninerealms.com',
'stagenet-rpc.ninerealms.com'
]
polaris-9r marked this conversation as resolved.
Show resolved Hide resolved

const openExternal = (target: string) => {
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/components/app/AppSettings.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export const NetworkLabel = styled(Text)<{ network: Network }>`
switch (network) {
case 'mainnet':
return palette('primary', 0)
case 'stagenet':
return palette('danger', 1)
case 'testnet':
return palette('warning', 0)
default:
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/app/AppSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const AppSettings: React.FC<Props> = (props): JSX.Element => {
)

// TODO asgdx-team: Remove `networkLabel` if we go live with mainnet
const networkLabel = (network: Network) => (network === 'mainnet' ? 'chaosnet' : 'testnet')
const networkLabel = (network: Network) => (network === 'mainnet' ? 'chaosnet' : network)

const networkMenu = useMemo(
() => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const meta: Meta<Args> = {
name: 'Network',
control: {
type: 'select',
options: ['mainnet', 'testnet']
options: ['mainnet', 'stagenet', 'testnet']
},
defaultValue: 'mainnet'
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const meta: Meta<Args> = {
name: 'Network',
control: {
type: 'select',
options: ['mainnet', 'testnet']
options: ['mainnet', 'stagenet', 'testnet']
},
defaultValue: 'mainnet'
},
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/components/header/HeaderComponent.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export const NetworkLabel = styled(Text)<{ network: Network }>`
switch (network) {
case 'mainnet':
return palette('primary', 0)
case 'stagenet':
return palette('danger', 1)
case 'testnet':
return palette('warning', 0)
default:
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/header/HeaderComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export const HeaderComponent: React.FC<Props> = (props): JSX.Element => {
)

// TODO asgdx-team: Remove `networkLabel` if we go live with mainnet
const networkLabel = (network: Network) => (network === 'mainnet' ? 'chaosnet' : 'testnet')
const networkLabel = (network: Network) => (network === 'mainnet' ? 'chaosnet' : network)

const renderLogo = useMemo(
() => (
Expand Down
23 changes: 13 additions & 10 deletions src/renderer/components/wallet/settings/WalletSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { AssetIcon } from '../../../components/uielements/assets/assetIcon/Asset
import { QRCodeModal } from '../../../components/uielements/qrCodeModal/QRCodeModal'
import { PhraseCopyModal } from '../../../components/wallet/phrase/PhraseCopyModal'
import { getChainAsset, isBnbChain, isThorChain } from '../../../helpers/chainHelper'
import { isEnabledWallet } from '../../../helpers/walletHelper'
import { ValidatePasswordHandler, WalletAccounts, WalletAddressAsync } from '../../../services/wallet/types'
import { walletTypeToI18n } from '../../../services/wallet/util'
import { InfoIcon } from '../../uielements/info'
Expand Down Expand Up @@ -264,15 +265,17 @@ export const WalletSettings: React.FC<Props> = (props): JSX.Element => {
<AssetIcon asset={getChainAsset(chain)} size={'small'} network="mainnet" />
<Styled.AccountTitle>{chain}</Styled.AccountTitle>
</Styled.AccountTitleWrapper>
{accounts.map((account, j) => {
const { type } = account
return (
<Styled.AccountAddressWrapper key={type}>
<Styled.WalletTypeLabel>{walletTypeToI18n(type, intl)}</Styled.WalletTypeLabel>
<Styled.AccountContent key={j}>{renderAddress(chain, account)}</Styled.AccountContent>
</Styled.AccountAddressWrapper>
)
})}
{accounts
.filter((account) => isEnabledWallet(chain, selectedNetwork, account.type))
.map((account, j) => {
const { type } = account
return (
<Styled.AccountAddressWrapper key={type}>
<Styled.WalletTypeLabel>{walletTypeToI18n(type, intl)}</Styled.WalletTypeLabel>
<Styled.AccountContent key={j}>{renderAddress(chain, account)}</Styled.AccountContent>
</Styled.AccountAddressWrapper>
)
})}
</Styled.ListItem>
)}
/>
Expand All @@ -281,7 +284,7 @@ export const WalletSettings: React.FC<Props> = (props): JSX.Element => {
)),
O.getOrElse(() => <></>)
),
[oWalletAccounts, intl, renderAddress]
[oWalletAccounts, intl, renderAddress, selectedNetwork]
)

return (
Expand Down
8 changes: 7 additions & 1 deletion src/renderer/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ export const AssetUniH: Asset = {

// Black listed BNB assets
// For now `RUNE-67C` is blacklisted on `mainnet` only, see https://explorer.binance.org/asset/RUNE-67C
export const BinanceBlackList: Record<Network, Array<Asset>> = { mainnet: [AssetRune67C], testnet: [] }
export const BinanceBlackList: Record<Network, Array<Asset>> = {
mainnet: [AssetRune67C],
stagenet: [AssetRune67C],
testnet: []
}

//
// All of following assets are needed for pricing USD
Expand Down Expand Up @@ -235,11 +239,13 @@ export const ASGARDEX_SWAP_IDENTIFIER = 999

export const RECOVERY_TOOL_URL: Record<Network, string> = {
testnet: 'https://testnet.thorswap.finance/pending',
stagenet: 'https://stagenet.thorswap.finance/pending',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@veado Wanted confirmation as to whether this should be stagenet specific or the mainnet value.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems https://stagenet.thorswap.finance/pending is accessible, so let's use it.

mainnet: 'https://app.thorswap.finance/pending'
}

export const ASYM_DEPOSIT_TOOL_URL: Record<Network, string> = {
testnet: 'https://testnet.thorswap.finance/',
stagenet: 'https://stagenet.thorswap.finance/',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@veado See above

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mainnet: 'https://app.thorswap.finance/'
}

Expand Down
1 change: 1 addition & 0 deletions src/renderer/helpers/fp/eq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export const eqLedgerAddressRD = RD.getEq<LedgerError, WalletAddress>(eqLedgerEr

export const eqLedgerAddressMap = Eq.struct<LedgerAddressMap>({
testnet: eqLedgerAddressRD,
stagenet: eqLedgerAddressRD,
mainnet: eqLedgerAddressRD
})

Expand Down
14 changes: 12 additions & 2 deletions src/renderer/helpers/walletHelper.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assetToBase, AssetRuneNative, AssetBNB, AssetLTC, assetAmount } from '@xchainjs/xchain-util'
import { assetToBase, AssetRuneNative, AssetBNB, AssetLTC, assetAmount, Chain } from '@xchainjs/xchain-util'
import * as FP from 'fp-ts/lib/function'
import * as NEA from 'fp-ts/lib/NonEmptyArray'
import * as O from 'fp-ts/lib/Option'
Expand All @@ -16,7 +16,8 @@ import {
getLtcAmountFromBalances,
getWalletBalanceByAsset,
getWalletByAddress,
hasLedgerInBalancesByAsset
hasLedgerInBalancesByAsset,
isEnabledWallet
} from './walletHelper'

describe('walletHelper', () => {
Expand Down Expand Up @@ -183,4 +184,13 @@ describe('walletHelper', () => {
expect(result).toBeFalsy()
})
})

describe('isEnabledWallet', () => {
it('THOR stagenet ledger wallet -> false', () => {
expect(isEnabledWallet(Chain.THORChain, 'stagenet', 'ledger')).toBe(false)
})
it('All other wallets -> true', () => {
expect(isEnabledWallet(Chain.THORChain, 'mainnet', 'ledger')).toBe(true)
})
})
})
9 changes: 9 additions & 0 deletions src/renderer/helpers/walletHelper.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { Address } from '@xchainjs/xchain-client'
import { Asset, AssetAmount, baseToAsset } from '@xchainjs/xchain-util'
import { Chain } from '@xchainjs/xchain-util'
import * as A from 'fp-ts/Array'
import * as FP from 'fp-ts/function'
import * as O from 'fp-ts/Option'

import { Network } from '../../shared/api/types'
import { isLedgerWallet } from '../../shared/utils/guard'
import { WalletAddress, WalletType } from '../../shared/wallet/types'
import { ZERO_ASSET_AMOUNT } from '../const'
import { WalletBalances } from '../services/clients'
import { NonEmptyWalletBalances, WalletBalance } from '../services/wallet/types'
import { isBnbAsset, isEthAsset, isLtcAsset, isRuneNativeAsset } from './assetHelper'
import { isThorChain } from './chainHelper'
import { eqAddress, eqAsset, eqWalletType } from './fp/eq'

/**
Expand Down Expand Up @@ -147,3 +150,9 @@ export const getWalletByAddress = (walletBalances: WalletBalances, address: Addr
walletBalances,
A.findFirst(({ walletAddress }) => eqAddress.equals(walletAddress, address))
)

export const isEnabledWallet = (chain: Chain, network: Network, walletType: WalletType) => {
// Disable THORChain ledger wallets in stagenet
if (isThorChain(chain) && network === 'stagenet' && isLedgerWallet(walletType)) return false
return true
}
17 changes: 15 additions & 2 deletions src/renderer/services/bitcoin/common.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
import * as RD from '@devexperts/remote-data-ts'
import { Client as BitcoinClient } from '@xchainjs/xchain-bitcoin'
import { Client as BitcoinClient, ClientUrl } from '@xchainjs/xchain-bitcoin'
import { BTCChain } from '@xchainjs/xchain-util'
import * as FP from 'fp-ts/lib/function'
import * as O from 'fp-ts/lib/Option'
import * as Rx from 'rxjs'
import { Observable } from 'rxjs'
import * as RxOp from 'rxjs/operators'

import { envOrDefault } from '../../../shared/utils/env'
import { isError } from '../../../shared/utils/guard'
import { clientNetwork$ } from '../app/service'
import * as C from '../clients'
import { keystoreService } from '../wallet/keystore'
import { getPhrase } from '../wallet/util'
import { ClientState, ClientState$ } from './types'

const APP_HASKOIN_MAINNET_URL = envOrDefault(
process.env.REACT_APP_HASKOIN_BTC_MAINNET_URL,
'https://api.haskoin.com/btc'
)

const HASKOIN_API_URL: ClientUrl = {
testnet: envOrDefault(process.env.REACT_APP_HASKOIN_BTC_TESTNET_URL, 'https://api.haskoin.com/btctest'),
stagenet: APP_HASKOIN_MAINNET_URL,
mainnet: APP_HASKOIN_MAINNET_URL
}

/**
* Stream to create an observable BitcoinClient depending on existing phrase in keystore
*
Expand All @@ -32,7 +44,8 @@ const clientState$: ClientState$ = FP.pipe(
try {
const client = new BitcoinClient({
network,
phrase
phrase,
haskoinUrl: HASKOIN_API_URL
})
return RD.success(client)
} catch (error) {
Expand Down
11 changes: 9 additions & 2 deletions src/renderer/services/bitcoincash/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ import { keystoreService } from '../wallet/keystore'
import { getPhrase } from '../wallet/util'
import { ClientState, ClientState$ } from './types'

const APP_HASKOIN_BCH_MAINNET_URL = envOrDefault(
process.env.REACT_APP_HASKOIN_BCH_MAINNET_URL,
'https://haskoin.ninerealms.com/bch'
)

const HASKOIN_API_URL: ClientUrl = {
testnet: envOrDefault(process.env.REACT_APP_HASKOIN_TESTNET_URL, 'https://haskoin.ninerealms.com/bchtest'),
mainnet: envOrDefault(process.env.REACT_APP_HASKOIN_MAINNET_URL, 'https://haskoin.ninerealms.com/bch')
testnet: envOrDefault(process.env.REACT_APP_HASKOIN_BCH_TESTNET_URL, 'https://haskoin.ninerealms.com/bchtest'),
stagenet: APP_HASKOIN_BCH_MAINNET_URL,
mainnet: APP_HASKOIN_BCH_MAINNET_URL
}

const NODE_URL: ClientUrl = {
testnet: envOrDefault(process.env.REACT_APP_BCH_NODE_TESTNET_URL, 'https://testnet.bch.thorchain.info'),
stagenet: envOrDefault(process.env.REACT_APP_BCH_NODE_STAGENET_URL, 'https://bch.thorchain.info'),
mainnet: envOrDefault(process.env.REACT_APP_BCH_NODE_MAINNET_URL, 'https://bch.thorchain.info')
}

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/services/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const DEFAULT_NETWORK: Network =
process.env.NODE_ENV !== 'production' && process.env.REACT_APP_DEFAULT_NETWORK === 'testnet' ? 'testnet' : 'mainnet'
export const DEFAULT_SLIP_TOLERANCE: SlipTolerance = 5
export const DEFAULT_CLIENT_NETWORK: Client.Network = Client.Network.Mainnet
export const AVAILABLE_NETWORKS: Network[] = ['testnet', 'mainnet']
export const AVAILABLE_NETWORKS: Network[] = ['testnet', 'stagenet', 'mainnet']
export const ENABLED_CHAINS: Chain[] = envOrDefault(process.env.REACT_APP_CHAINS_ENABLED, 'THOR,BNB,BTC,LTC,BCH,ETH')
.replace(/\s/g, '')
.split(',')
Expand Down
21 changes: 19 additions & 2 deletions src/renderer/services/midgard/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const MIDGARD_TESTNET_URL = envOrDefault(
'https://testnet.midgard.thorchain.info'
)

const MIDGARD_STAGENET_URL = envOrDefault(
process.env.REACT_APP_MIDGARD_STAGENET_URL,
'https://stagenet-midgard.ninerealms.com'
)

const MIDGARD_MAINNET_URL = envOrDefault(process.env.REACT_APP_MIDGARD_MAINNET_URL, 'https://midgard.thorchain.info')

/**
Expand All @@ -50,10 +55,22 @@ const { stream$: reloadByzantine$, trigger: reloadByzantine } = triggerStream()
const nextByzantine$: (n: Network) => LiveData<Error, string> = fromPromise$<RD.RemoteData<Error, string>, Network>(
(network: Network) => {
// option to set Midgard url (for testnet + development only)
if (network === 'testnet') return Promise.resolve(RD.success(MIDGARD_TESTNET_URL))
let midgardURL
switch (network) {
case 'mainnet':
midgardURL = MIDGARD_MAINNET_URL
break
case 'stagenet':
midgardURL = MIDGARD_STAGENET_URL
break
case 'testnet':
midgardURL = MIDGARD_TESTNET_URL
break
}

// Byzantine module is disabled temporary
// return midgard(network, true).then(RD.success)
return Promise.resolve(RD.success(MIDGARD_MAINNET_URL))
return Promise.resolve(RD.success(midgardURL))
},
RD.pending,
RD.failure
Expand Down
Loading