Skip to content

Commit 50922f2

Browse files
authored
A-1212979667742261: only ML wallet if BTC unavailable (#248)
1 parent 7a79c76 commit 50922f2

14 files changed

Lines changed: 116 additions & 51 deletions

File tree

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@
189189
"pretty-quick": "^4.2.2",
190190
"react-app-rewire-alias": "^1.1.7",
191191
"react-scripts": "5.0.1",
192-
"typescript": "^4.9.5",
192+
"typescript": "^5.9.3",
193193
"vm-browserify": "^1.1.2",
194194
"wallet-address-validator": "^0.2.4",
195195
"webextension-polyfill": "^0.12.0"

src/components/basic/Logo/Logo.css

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,16 @@
55
align-items: center;
66
line-height: 60px;
77
width: 190px;
8-
9-
@media screen and (min-width: 801px) {
10-
width: 200px;
11-
}
128
}
139

1410
.logoContainer .logo {
1511
width: 50px;
1612
height: 50px;
1713
margin: 0;
18-
19-
@media screen and (min-width: 801px) {
20-
width: 55px;
21-
height: 55px;
22-
}
2314
}
2415

2516
.logoContainer .mojitoLettering {
26-
font-size: 2.5rem;
17+
font-size: 2.4rem;
2718
color: rgb(var(--color-black));
2819
}
2920

src/components/composed/Balance/Balance.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ const Balance = ({ balance, balanceLocked, exchangeRate, walletType }) => {
5959
const { coinType } = useParams()
6060
const navigate = useNavigate()
6161

62+
const isToken =
63+
walletType.name !== 'Mintlayer' && walletType.name !== 'Bitcoin'
64+
6265
const balanceInUSD = isTestnet
6366
? '0,00'
6467
: new Decimal(NumbersHelper.floatStringToNumber(balance) || 0)
@@ -100,15 +103,15 @@ const Balance = ({ balance, balanceLocked, exchangeRate, walletType }) => {
100103
>
101104
<span>{Format.BTCValue(balance)}</span> {symbol()}
102105
</p>
103-
{!isTestnet && (
106+
{!isTestnet && !isToken && (
104107
<p
105108
className="balance-usd"
106109
data-testid="balance-paragraph"
107110
>
108111
<span>{Format.fiatValue(balanceInUSD)}</span> USD
109112
</p>
110113
)}
111-
{!isTestnet && (
114+
{!isTestnet && !isToken && (
112115
<span className="wallet-price">
113116
Price: {exchangeRate.toFixed(2)} $
114117
</span>

src/components/composed/Navigation/Navigation.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import { ReactComponent as SettingsImg } from '@Assets/images/settings.svg'
88
import { ReactComponent as LoginImg } from '@Assets/images/icon-login.svg'
99
import { ReactComponent as AddWalletImg } from '@Assets/images/icon-add-wallet.svg'
1010
import { ReactComponent as HomeImg } from '@Assets/images/icon-home.svg'
11-
import { ReactComponent as WalletIcon } from '@Assets/images/icon-wallet.svg'
11+
// import { ReactComponent as WalletIcon } from '@Assets/images/icon-wallet.svg'
1212
import { ReactComponent as TriangleIcon } from '@Assets/images/icon-triangle.svg'
1313

1414
import { APP_VERSION } from '@Version'
1515

1616
import { AccountContext, MintlayerContext } from '@Contexts'
17-
import { AppInfo } from '@Constants'
17+
// import { AppInfo } from '@Constants'
1818

1919
import NestedNavigation from './NestedNavigation'
2020

@@ -89,13 +89,13 @@ const Navigation = ({ customNavigation }) => {
8989
icon: <HomeImg />,
9090
link: '/dashboard',
9191
},
92-
{
93-
id: 2,
94-
label: 'Wallets',
95-
icon: <WalletIcon />,
96-
type: 'menu',
97-
content: AppInfo.WALLETS_NAVIGATION,
98-
},
92+
// {
93+
// id: 2,
94+
// label: 'Wallets',
95+
// icon: <WalletIcon />,
96+
// type: 'menu',
97+
// content: AppInfo.WALLETS_NAVIGATION,
98+
// },
9999
{
100100
id: 3,
101101
label: 'Settings',

src/components/containers/Dashboard/CryptoList.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
.crypto-network-mask-full {
2+
position: absolute;
3+
top: 0;
4+
left: 0;
5+
width: 100%;
6+
height: 100%;
7+
background: rgba(var(--color-gray), 0.85);
8+
z-index: 2;
9+
border-radius: 45px;
10+
display: flex;
11+
align-items: flex-start;
12+
justify-content: flex-end;
13+
align-items: center;
14+
padding: 0 3rem 0 0;
15+
pointer-events: all;
16+
}
17+
18+
.crypto-network-mask-text {
19+
color: rgb(var(--color-red));
20+
font-size: 1.1em;
21+
font-weight: bold;
22+
}
123
.crypto-list {
224
height: 240px;
325
overflow-y: auto;
@@ -11,6 +33,7 @@
1133
}
1234

1335
.crypto-item {
36+
position: relative;
1437
display: flex;
1538
justify-content: space-between;
1639
padding: 12px 30px 12px 18px;

src/components/containers/Dashboard/CryptoList.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import TokenLogoRound from '../../basic/TokenLogoRound/TokenLogoRound'
1111
export const CryptoItem = ({ onClickItem, item }) => {
1212
const { networkType } = useContext(SettingsContext)
1313
const fetchingBalances = item.fetchingBalances
14+
const isBtcUnavailable = item.disabled
1415
const { tokenBalances } = useContext(MintlayerContext)
1516
const isTestnet = networkType === AppInfo.NETWORK_TYPES.TESTNET
1617
const balance = item.balance
@@ -23,9 +24,12 @@ export const CryptoItem = ({ onClickItem, item }) => {
2324
Number(value),
2425
])
2526
const symbol = !isTestnet ? item.symbol : 'Testnet'
27+
const isToken = item.name !== 'Mintlayer' && item.name !== 'Bitcoin'
2628

2729
const onClick = () => {
28-
onClickItem(item)
30+
if (!isBtcUnavailable) {
31+
onClickItem(item)
32+
}
2933
}
3034

3135
const logoText =
@@ -55,10 +59,15 @@ export const CryptoItem = ({ onClickItem, item }) => {
5559
) : (
5660
<li
5761
key={item.symbol}
58-
className="crypto-item"
62+
className={`crypto-item ${isBtcUnavailable ? 'disabled' : ''}`}
5963
onClick={onClick}
6064
data-testid="crypto-item"
6165
>
66+
{isBtcUnavailable && (
67+
<div className="crypto-network-mask-full">
68+
<span className="crypto-network-mask-text">Offline</span>
69+
</div>
70+
)}
6271
<div className="logo-wrapper">
6372
{logo()}
6473
<div className="name-values">
@@ -67,7 +76,7 @@ export const CryptoItem = ({ onClickItem, item }) => {
6776
</h5>
6877
<div className={`values ${bigValues ? 'big-values' : ''}`}>
6978
<dl>
70-
{!isTestnet ? (
79+
{!isTestnet && !isToken ? (
7180
<>
7281
<dd>
7382
{balance} {symbol}
@@ -121,7 +130,6 @@ export const ConnectItem = ({ walletType, onClick }) => {
121130
</li>
122131
)
123132
}
124-
125133
const CryptoList = ({ cryptoList, onWalletItemClick, onConnectItemClick }) => {
126134
const missingWalletTypes = AppInfo.walletTypes.filter(
127135
(walletType) =>

src/contexts/BitcoinProvider/BitcoinProvider.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,15 @@ const BitcoinProvider = ({ value: propValue, children }) => {
2828
const [fetchingBalances, setFetchingBalances] = useState(false)
2929
const [fetchingTransactions, setFetchingTransactions] = useState(false)
3030
const [fetchingUtxos, setFetchingUtxos] = useState(false)
31+
const [btcApiAvailable, setBtcApiAvailable] = useState(true)
3132

3233
const fetchAllData = async (force) => {
34+
if (!btcApiAvailable) {
35+
console.log(
36+
'Bitcoin API is not available, skipping Bitcoin wallet loading',
37+
)
38+
return
39+
}
3340
if (
3441
!force &&
3542
currentBlockHeight === onlineHeight &&
@@ -267,8 +274,14 @@ const BitcoinProvider = ({ value: propValue, children }) => {
267274

268275
useEffect(() => {
269276
const getData = async () => {
270-
const result = await Electrum.getLastBlockHeight()
271-
setOnlineHeight(result)
277+
try {
278+
const result = await Electrum.getLastBlockHeight()
279+
setOnlineHeight(result)
280+
setBtcApiAvailable(true)
281+
} catch (error) {
282+
console.error('Bitcoin API is not available:', error)
283+
setBtcApiAvailable(false)
284+
}
272285
}
273286
getData()
274287
const data = setInterval(getData, AppInfo.REFRESH_INTERVAL)
@@ -296,6 +309,7 @@ const BitcoinProvider = ({ value: propValue, children }) => {
296309
setFetchingBalances,
297310
setFetchingTransactions,
298311
setFetchingUtxos,
312+
btcApiAvailable,
299313

300314
fetchAllData,
301315
}

src/hooks/UseWalletInfo/useBtcWalletInfo.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const useBtcWalletInfo = (address) => {
1414
setFetchingTransactions,
1515
setFetchingUtxos,
1616
unusedAddresses,
17+
btcApiAvailable,
1718
} = useContext(BitcoinContext)
1819

1920
return {
@@ -28,6 +29,7 @@ const useBtcWalletInfo = (address) => {
2829
setFetchingTransactions,
2930
setFetchingUtxos,
3031
unusedAddresses,
32+
btcApiAvailable,
3133
}
3234
}
3335

src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
useLocation,
99
useNavigate,
1010
} from 'react-router'
11-
import { Electrum, ExchangeRates } from '@APIs'
11+
import { Mintlayer, ExchangeRates } from '@APIs'
1212
import { ConnectionErrorPopup, Header, PopUp } from '@ComposedComponents'
1313
import { DeleteAccount } from '@ContainerComponents'
1414
import { Client } from '@mintlayer/sdk'
@@ -97,9 +97,9 @@ const App = () => {
9797

9898
const isConnectionAvailable = async (accountUnlocked) => {
9999
try {
100-
const electrumResponse = await Electrum.getLastBlockHash()
101-
const exchangeResponse = await ExchangeRates.getRate('btc', 'usd')
102-
return !!electrumResponse && !!exchangeResponse
100+
const mintlayerResponse = await Mintlayer.getChainTip()
101+
const exchangeResponse = await ExchangeRates.getRate('ml', 'usd')
102+
return !!mintlayerResponse && !!exchangeResponse
103103
} catch (error) {
104104
if (accountUnlocked) {
105105
console.log(error)

0 commit comments

Comments
 (0)