Skip to content

Commit

Permalink
Merge pull request #105 from mintlayer/dev
Browse files Browse the repository at this point in the history
* fix: make unconfirmed transaction specific to the network type

* add mainnet api server to the list

* feat: make ML mainnet wallet back, add ml exchage data from the API

* fix: exchange data, blockchain link
  • Loading branch information
owlsua authored Jan 28, 2024
2 parents e88ee0f + b0f06f3 commit e01ad75
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ GENERATE_SOURCEMAP=false
MAINNET_ELECTRUM_SERVERS='https://blockstream.info/api'
TESTNET_ELECTRUM_SERVERS='http://51.158.172.176:3001, https://blockstream.info/testnet/api'
TESTNET_MINTLAYER_SERVERS='https://api-server-lovelace.mintlayer.org'
MAINNET_MINTLAYER_SERVERS=''
MAINNET_MINTLAYER_SERVERS='https://api-server.mintlayer.org'
2 changes: 1 addition & 1 deletion .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ GENERATE_SOURCEMAP=false
MAINNET_ELECTRUM_SERVERS='https://blockstream.info/api'
TESTNET_ELECTRUM_SERVERS='http://51.158.172.176:3001, https://blockstream.info/testnet/api'
TESTNET_MINTLAYER_SERVERS='https://api-server-lovelace.mintlayer.org'
MAINNET_MINTLAYER_SERVERS=''
MAINNET_MINTLAYER_SERVERS='https://api-server.mintlayer.org'
2 changes: 1 addition & 1 deletion .env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ GENERATE_SOURCEMAP=true
MAINNET_ELECTRUM_SERVERS='https://blockstream.info/api'
TESTNET_ELECTRUM_SERVERS='http://51.158.172.176:3001, https://blockstream.info/testnet/api'
TESTNET_MINTLAYER_SERVERS='https://api-server-lovelace.mintlayer.org'
MAINNET_MINTLAYER_SERVERS=''
MAINNET_MINTLAYER_SERVERS='https://api-server.mintlayer.org'
143 changes: 68 additions & 75 deletions src/components/containers/Dashboard/CryptoList.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ import { SettingsContext, AccountContext } from '@Contexts'
import './CryptoList.css'

//TODO: remove this when mainnet is ready
const MainnetAddressItem = () => {
const { setOpenShowAddressTemp } = useContext(AccountContext)
const onItemClick = () => {
setOpenShowAddressTemp(true)
}
return (
<li
className="crypto-item coming-soon"
onClick={onItemClick}
>
<div className="mlt-logo">
<LogoRound />
</div>
<div className="name-values">
<h5>Mintlayer (ML)</h5>
<p className="show-address-text">
Click here to get your Mainnet address
</p>
</div>
</li>
)
}
// const MainnetAddressItem = () => {
// const { setOpenShowAddressTemp } = useContext(AccountContext)
// const onItemClick = () => {
// setOpenShowAddressTemp(true)
// }
// return (
// <li
// className="crypto-item coming-soon"
// onClick={onItemClick}
// >
// <div className="mlt-logo">
// <LogoRound />
// </div>
// <div className="name-values">
// <h5>Mintlayer (ML)</h5>
// <p className="show-address-text">
// Click here to get your Mainnet address
// </p>
// </div>
// </li>
// )
// }

export const CryptoItem = ({ colorList, onClickItem, item }) => {
const { balanceLoading } = useContext(AccountContext)
Expand All @@ -55,61 +55,54 @@ export const CryptoItem = ({ colorList, onClickItem, item }) => {
{balanceLoading ? (
<SkeletonLoader />
) : (
<>
{/* TODO: remove this when mainnet is ready */}
{item.name === 'Mintlayer' && !isTestnet ? (
<MainnetAddressItem />
) : (
<li
key={item.symbol}
className="crypto-item"
onClick={onClick}
data-testid="crypto-item"
>
{item.name === 'Mintlayer' ? <LogoRound /> : <BtcLogo />}
<div className="name-values">
<h5>
{item.name} ({symbol})
</h5>
<div className={`values ${bigValues ? 'big-values' : ''}`}>
<dl>
<dt>Value:</dt>
<dd>{balance}</dd>
{!isTestnet && (
<>
<dt>Price:</dt>
<dd>{item.exchangeRate.toFixed(2)}</dd>
</>
)}
</dl>
</div>
</div>
<div className="crypto-stats">
<div className="crypto-stats-numbers">
{Number(balance) > 0 && (
<>
<strong
className={item.change24h < 0 ? 'negative' : 'positive'}
>
{isTestnet ? 0 : item.change24h}%
</strong>
<span>24h</span>
</>
)}
</div>
<li
key={item.symbol}
className="crypto-item"
onClick={onClick}
data-testid="crypto-item"
>
{item.name === 'Mintlayer' ? <LogoRound /> : <BtcLogo />}
<div className="name-values">
<h5>
{item.name} ({symbol})
</h5>
<div className={`values ${bigValues ? 'big-values' : ''}`}>
<dl>
<dt>Value:</dt>
<dd>{balance}</dd>
{!isTestnet && (
<LineChart
points={data}
height="40px"
width="100%"
lineColor={color}
lineWidth="4px"
/>
<>
<dt>Price:</dt>
<dd>{item.exchangeRate.toFixed(2)}</dd>
</>
)}
</div>
</li>
)}
</>
</dl>
</div>
</div>
<div className="crypto-stats">
<div className="crypto-stats-numbers">
{Number(balance) > 0 && (
<>
<strong
className={item.change24h < 0 ? 'negative' : 'positive'}
>
{isTestnet ? 0 : item.change24h}%
</strong>
<span>24h</span>
</>
)}
</div>
{(!isTestnet || !data.length) && (
<LineChart
points={data}
height="40px"
width="100%"
lineColor={color}
lineWidth="4px"
/>
)}
</div>
</li>
)}
</>
)
Expand Down
6 changes: 3 additions & 3 deletions src/components/containers/Wallet/TransactionDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ const TransactionDetails = ({ transaction, getConfirmations }) => {
isTestnet ? '/testnet' : ''
}/tx/${transaction?.txid}`

const externalMlLink = `https://explorer.mintlayer.org${
isTestnet ? '/lovelace' : ''
}/tx/${transaction?.txid}`
const externalMlLink = `https://${
isTestnet ? 'lovelace.' : ''
}explorer.mintlayer.org/tx/${transaction?.txid}`

const explorerLink =
walletType.name === 'Mintlayer' ? externalMlLink : externalBtcLink
Expand Down
5 changes: 0 additions & 5 deletions src/contexts/AccountProvider/AccountProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ const AccountProvider = ({ value: propValue, children }) => {
const [transactionsLoading, setTransactionsLoading] = useState(false)
const [feeLoading, setFeeLoading] = useState(false)

//TODO: remove this after mainnet launch
const [openShowAddressTemp, setOpenShowAddressTemp] = useState(false)

const accountRegistryName = 'unlockedAccount'
const loginTimeoutInMinutes = 30

Expand Down Expand Up @@ -96,8 +93,6 @@ const AccountProvider = ({ value: propValue, children }) => {
setTransactionsLoading,
feeLoading,
setFeeLoading,
openShowAddressTemp,
setOpenShowAddressTemp,
}

useEffect(() => {
Expand Down
8 changes: 0 additions & 8 deletions src/hooks/UseExchangeRates/useExchangeRates.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@ import { useEffect, useState, useRef, useCallback } from 'react'

import { ExchangeRates } from '@APIs'

// TODO: Remove this mock
const ML_EXCHANGE_RATE_MOCK = 0.055

const useExchangeRates = (crypto, fiat) => {
const effectCalled = useRef(false)
const [exchangeRate, setExchangeRate] = useState(0)

const getRate = useCallback(async () => {
try {
// TODO: Remove this mock
if (crypto === 'ML' || crypto === 'ml') {
setExchangeRate(ML_EXCHANGE_RATE_MOCK)
return
}
const response = await ExchangeRates.getRate(crypto, fiat)
const rates = JSON.parse(response)[`${crypto}-${fiat}`]
setExchangeRate(rates)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@ import { useEffect, useState, useRef, useCallback } from 'react'

import { ExchangeRates } from '@APIs'

// TODO: Remove this mock
const ML_YESTERDAY_EXCHANGE_RATE_MOCK = 0.055

const useOneDayAgoExchangeRates = (crypto, fiat) => {
const effectCalled = useRef(false)
const [yesterdayExchangeRate, setYesterdayExchangeRate] = useState(0)

const getRate = useCallback(async () => {
try {
// TODO: Remove this mock
if (crypto === 'ML' || crypto === 'ml') {
setYesterdayExchangeRate(ML_YESTERDAY_EXCHANGE_RATE_MOCK)
return
}
const response = await ExchangeRates.getOneDayAgoRate(crypto, fiat)
const rates = JSON.parse(response)[`${crypto}-${fiat}`]
setYesterdayExchangeRate(rates)
Expand Down
60 changes: 35 additions & 25 deletions src/pages/Dashboard/Dashboard.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable max-params */
import { useContext, useState, useEffect } from 'react'
import { Header, PopUp, AddWallet } from '@ComposedComponents'
import { AccountContext, SettingsContext } from '@Contexts'
import { Account } from '@Entities'
import { Wallet } from '@ContainerComponents'

import {
useExchangeRates,
Expand All @@ -20,14 +20,8 @@ import { BTC } from '@Helpers'
import { AppInfo } from '@Constants'

const DashboardPage = () => {
const {
addresses,
accountName,
setWalletType,
accountID,
openShowAddressTemp,
setOpenShowAddressTemp,
} = useContext(AccountContext)
const { addresses, accountName, setWalletType, accountID } =
useContext(AccountContext)
const { networkType } = useContext(SettingsContext)
const currentBtcAddress =
networkType === AppInfo.NETWORK_TYPES.MAINNET
Expand All @@ -50,7 +44,8 @@ const DashboardPage = () => {
useOneDayAgoExchangeRates('btc', 'usd')
const { yesterdayExchangeRate: mlYesterdayExchangeRate } =
useOneDayAgoExchangeRates('ml', 'usd')
const { historyRates } = useOneDayAgoHist('btc', 'usd')
const { historyRates: btcHistoryRates } = useOneDayAgoHist('btc', 'usd')
const { historyRates: mlHistoryrates } = useOneDayAgoHist('ml', 'usd')
const navigate = useNavigate()

const yesterdayExchangeRateList = {
Expand Down Expand Up @@ -82,7 +77,7 @@ const DashboardPage = () => {
{
name: 'Bitcoin',
symbol: 'BTC',
balance: NumbersHelper.floatStringToNumber(btcBalance),
balance: 0,
exchangeRate: btcExchangeRate,
},
{
Expand All @@ -101,15 +96,21 @@ const DashboardPage = () => {
const getCryptoList = (addresses, network) => {
if (!addresses) return []
const cryptos = []
// eslint-disable-next-line max-params
const addCrypto = (name, symbol, balance, exchangeRate, change24h) => {
const addCrypto = (
name,
symbol,
balance,
exchangeRate,
change24h,
historyRates,
) => {
cryptos.push({
name,
symbol,
balance: NumbersHelper.floatStringToNumber(balance),
exchangeRate,
historyRates,
change24h,
historyRates,
})
}

Expand All @@ -121,13 +122,31 @@ const DashboardPage = () => {
network === AppInfo.NETWORK_TYPES.MAINNET
? Number((proportionDiffs.btc - 1) * 100).toFixed(2)
: 0
addCrypto('Bitcoin', 'BTC', btcBalance, btcExchangeRate, change24h)
addCrypto(
'Bitcoin',
'BTC',
btcBalance,
btcExchangeRate,
change24h,
btcHistoryRates,
)
}
const mlAddress = addresses.mlMainnetAddress
? addresses.mlTestnetAddresses.mlReceivingAddresses[0]
: false
if (mlAddress) {
addCrypto('Mintlayer', 'ML', mlBalance, mlExchangeRate, 0)
const change24h =
network === AppInfo.NETWORK_TYPES.MAINNET
? Number((proportionDiffs.ml - 1) * 100).toFixed(2)
: 0
addCrypto(
'Mintlayer',
'ML',
mlBalance,
mlExchangeRate,
change24h,
mlHistoryrates,
)
}

return cryptos
Expand Down Expand Up @@ -191,15 +210,6 @@ const DashboardPage = () => {
/>
</PopUp>
)}

{/* //TODO: remove this after mainnet launch */}
{openShowAddressTemp && (
<PopUp setOpen={setOpenShowAddressTemp}>
<Wallet.ShowAddress
address={currentMlAddresses.mlReceivingAddresses[0]}
></Wallet.ShowAddress>
</PopUp>
)}
</>
)
}
Expand Down
Loading

0 comments on commit e01ad75

Please sign in to comment.