Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A-1207660367546315 #174

Merged
merged 6 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions src/components/composed/Balance/Balance.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
bottom: -25px;
opacity: 0.2;
white-space: nowrap;
cursor: pointer;
}

.balance-locked:hover {
Expand Down
9 changes: 8 additions & 1 deletion src/components/composed/Balance/Balance.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useContext } from 'react'
import { useNavigate, useParams } from 'react-router-dom'

import { ReactComponent as BtcLogo } from '@Assets/images/btc-logo.svg'
import { LogoRound } from '@BasicComponents'
Expand All @@ -12,6 +13,8 @@ import TokenLogoRound from '../../basic/TokenLogoRound/TokenLogoRound'
const Balance = ({ balance, balanceLocked, exchangeRate, walletType }) => {
const { networkType } = useContext(SettingsContext)
const { tokenBalances } = useContext(NetworkContext)
const { coinType } = useParams()
const navigate = useNavigate()
// TODO Consider the correct format for 0,00 that might also be 0.00
const balanceInUSD =
networkType === AppInfo.NETWORK_TYPES.TESTNET
Expand Down Expand Up @@ -44,6 +47,10 @@ const Balance = ({ balance, balanceLocked, exchangeRate, walletType }) => {
)
}

const onLockedClick = () => {
navigate('/wallet/' + coinType + '/locked-balance')
}

return (
<div
className="balance-wrapper"
Expand All @@ -64,7 +71,7 @@ const Balance = ({ balance, balanceLocked, exchangeRate, walletType }) => {
<span>{Format.fiatValue(balanceInUSD)}</span> USD
</p>
{parseFloat(balanceLocked) > 0 ? (
<div className="balance-locked">
<div className="balance-locked" onClick={onLockedClick}>
Locked: {balanceLocked} {symbol()}
</div>
) : (
Expand Down
25 changes: 25 additions & 0 deletions src/components/composed/LockedBalanceList/LockedBalanceList.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.locked-table {
width: 100%;
}

.locked-table-wrapper {
display: flex;
justify-content: center;
height: 465px;
overflow: auto;
}

.locked-title {
text-align: left;
padding: 10px;
background: rgb(var(--color-green));
width: 50%;
color: rgb(var(--color-white));
}

.locked-loading-wrapper {
display: flex;
justify-content: center;
align-items: center;
height: 465px;
}
53 changes: 53 additions & 0 deletions src/components/composed/LockedBalanceList/LockedBalanceList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React, { useContext } from 'react'
import { NetworkContext } from '@Contexts'

import { Loading } from '@ComposedComponents'
import LockedBalanceListItem from './LockedBalanceListItem'
import './LockedBalanceList.css'

const LockedBalanceList = () => {
const { lockedUtxos, fetchingUtxos } = useContext(NetworkContext)

return (
<>
<div className="locked-table-wrapper">
{fetchingUtxos ? (
<div className='locked-loading-wrapper'>
<Loading />
</div>
) : (
<table
className="locked-table"
data-testid="locked-table"
>
<thead>
<tr>
<th
style={{ padding: '10px', textAlign: 'left' }}
className="locked-title"
>
Time
</th>
<th
style={{ padding: '10px', textAlign: 'left' }}
className="locked-title"
>
Amount
</th>
</tr>
</thead>
<tbody>
{lockedUtxos &&
lockedUtxos.map((utxo, index) => (
<LockedBalanceListItem index={index} utxo={utxo}/>
))}
</tbody>
</table>
)}
</div>
</>
)
}

export default LockedBalanceList

Empty file.
24 changes: 24 additions & 0 deletions src/components/composed/LockedBalanceList/LockedBalanceListItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { format } from 'date-fns'

import './LockedBalanceListItem.css'

const LockedBalanceListItem = ({ index, utxo }) => {
return (
<tr
key={index}
style={{
backgroundColor: index % 2 === 0 ? 'white' : 'rgb(247, 250, 250)',
}}
>
<td style={{ padding: '10px' }}>
{format(
new Date(utxo.utxo.lock.content.timestamp * 1000),
owlsua marked this conversation as resolved.
Show resolved Hide resolved
'dd/MM/yyyy HH:mm',
)}
</td>
<td style={{ padding: '10px' }}>{utxo.utxo.value.amount.decimal}</td>
</tr>
)
}

export default LockedBalanceListItem
2 changes: 2 additions & 0 deletions src/components/composed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import CurrentStaking from './CurrentStaking/CurrentStaking'
import HelpTooltip from './HelpTooltip/HelpTooltip'
import RestoreSeedField from './RestoreSeedField/RestoreSeedField'
import UpdateButton from './UpdateButton/UpdateButton'
import LockedBalanceList from './LockedBalanceList/LockedBalanceList'

export {
Balance,
Expand All @@ -44,4 +45,5 @@ export {
HelpTooltip,
RestoreSeedField,
UpdateButton,
LockedBalanceList,
}
37 changes: 25 additions & 12 deletions src/contexts/NetworkProvider/NetworkProvider.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import React, { createContext, useContext, useEffect, useState } from 'react'
import {
getAddressData,
getChainTip,
getTransactionData,
} from '../../services/API/Mintlayer/Mintlayer'

import { AccountContext, SettingsContext } from '@Contexts'
import { AppInfo } from '@Constants'
import { ML_ATOMS_PER_COIN } from '../../utils/Constants/AppInfo/AppInfo'
Expand Down Expand Up @@ -33,6 +29,7 @@ const NetworkProvider = ({ value: propValue, children }) => {
const [lockedBalance, setLockedBalance] = useState(0)
const [unusedAddresses, setUnusedAddresses] = useState({})
const [utxos, setUtxos] = useState([])
const [lockedUtxos, setLockedUtxos] = useState([])
const [transactions, setTransactions] = useState([])
const [feerate, setFeerate] = useState(0)

Expand Down Expand Up @@ -84,12 +81,12 @@ const NetworkProvider = ({ value: propValue, children }) => {

const addresses_data_receive = await Promise.all(
currentMlAddresses.mlReceivingAddresses.map((address) =>
getAddressData(address),
Mintlayer.getAddressData(address),
),
)
const addresses_data_change = await Promise.all(
currentMlAddresses.mlChangeAddresses.map((address) =>
getAddressData(address),
Mintlayer.getAddressData(address),
),
)
const addresses_data = [...addresses_data_receive, ...addresses_data_change]
Expand Down Expand Up @@ -143,7 +140,9 @@ const NetworkProvider = ({ value: propValue, children }) => {
setCurrentAccountId(accountID)

// fetch transactions data
const transactions = transaction_ids.map((txid) => getTransactionData(txid))
const transactions = transaction_ids.map((txid) =>
Mintlayer.getTransactionData(txid),
)
const transactions_data = await Promise.all(transactions)

const parsedTransactions = ML.getParsedTransactions(
Expand All @@ -160,11 +159,19 @@ const NetworkProvider = ({ value: propValue, children }) => {
const unconfirmedTransactions =
LocalStorageService.getItem(unconfirmedTransactionString) || []

const utxos = await Mintlayer.getWalletUtxos(addressList)
const parsedUtxos = utxos
const fetchedUtxos = await Mintlayer.getWalletUtxos(addressList)
const fetchedSpendableUtxos =
await Mintlayer.getWalletSpendableUtxos(addressList)

const parsedUtxos = fetchedUtxos
.map((utxo) => JSON.parse(utxo))
.filter((utxo) => utxo.length > 0)

const parsedSpendableUtxos = fetchedSpendableUtxos
.map((utxo) => JSON.parse(utxo))
.filter((utxo) => utxo.length > 0)
const available = parsedUtxos

const available = parsedSpendableUtxos
.flatMap((utxo) => [...utxo])
.filter((item) => item.utxo.value)
.filter((item) => {
Expand All @@ -189,7 +196,12 @@ const NetworkProvider = ({ value: propValue, children }) => {
setCurrentNetworkType(networkType)

const availableUtxos = available.map((item) => item)
const lockedUtxos = parsedUtxos
.flat()
.filter((obj) => obj.utxo.type === 'LockThenTransfer')

setUtxos(availableUtxos)
setLockedUtxos(lockedUtxos)

setFetchingUtxos(false)

Expand Down Expand Up @@ -305,7 +317,7 @@ const NetworkProvider = ({ value: propValue, children }) => {

useEffect(() => {
const getData = async () => {
const result = await getChainTip()
const result = await Mintlayer.getChainTip()
const { block_height } = JSON.parse(result)
setOnlineHeight(block_height)
}
Expand All @@ -321,6 +333,7 @@ const NetworkProvider = ({ value: propValue, children }) => {
tokenBalances,
// addresses,
utxos,
lockedUtxos,
transactions,
currentHeight,
onlineHeight,
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
CreateDelegationPage,
DelegationStakePage,
DelegationWithdrawPage,
LockedBalancePage,
} from '@Pages'

import {
Expand Down Expand Up @@ -232,6 +233,10 @@ const App = () => {
path="/wallet/:coinType/staking/create-delegation"
element={<CreateDelegationPage />}
/>
<Route
path="/wallet/:coinType/locked-balance"
element={<LockedBalancePage />}
/>
<Route
exact
path="/"
Expand Down
5 changes: 5 additions & 0 deletions src/pages/LockedBalance/LockedBalance.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.animate-list-accounts {
overflow: hidden;
transform: translateX(-200%);
transition: transform 1s ease-in-out;
}
14 changes: 14 additions & 0 deletions src/pages/LockedBalance/LockedBalance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { LockedBalanceList } from '@ComposedComponents'

import './LockedBalance.css'

const LockedBalancePage = () => {

return (
<>
<LockedBalanceList />
</>
)
}

export default LockedBalancePage
2 changes: 2 additions & 0 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ConnectionPage from './ConnectionPage/ConnectionPage'
import CreateDelegationPage from './CreateDelegation/CreateDelegation'
import DelegationStakePage from './DelegationStake/DelegationStake'
import DelegationWithdrawPage from './DelegationWithdraw/DelegationWithdraw'
import LockedBalancePage from './LockedBalance/LockedBalance'

export {
CreateAccountPage,
Expand All @@ -30,4 +31,5 @@ export {
CreateDelegationPage,
DelegationStakePage,
DelegationWithdrawPage,
LockedBalancePage
}
17 changes: 16 additions & 1 deletion src/services/API/Mintlayer/Mintlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const prefix = '/api/v2'
const MINTLAYER_ENDPOINTS = {
GET_ADDRESS_DATA: '/address/:address',
GET_TRANSACTION_DATA: '/transaction/:txid',
GET_ADDRESS_UTXO: '/address/:address/spendable-utxos',
GET_ADDRESS_UTXO: '/address/:address/all-utxos',
GET_ADDRESS_SPENDABLE_UTXO: '/address/:address/spendable-utxos',
POST_TRANSACTION: '/transaction',
GET_FEES_ESTIMATES: '/feerate',
GET_ADDRESS_DELEGATIONS: '/address/:address/delegations',
Expand Down Expand Up @@ -211,6 +212,18 @@ const getWalletUtxos = (addresses) => {
return Promise.all(utxosPromises)
}

const getAddressSpendableUtxo = (address) =>
tryServers(
MINTLAYER_ENDPOINTS.GET_ADDRESS_SPENDABLE_UTXO.replace(':address', address),
)

const getWalletSpendableUtxos = (addresses) => {
const utxosPromises = addresses.map((address) =>
getAddressSpendableUtxo(address),
)
return Promise.all(utxosPromises)
}

const getTokensData = async (tokens) => {
const tokensData = {}
tokens.forEach((token) => {
Expand Down Expand Up @@ -304,6 +317,8 @@ export {
requestMintlayer,
getAddressUtxo,
getWalletUtxos,
getAddressSpendableUtxo,
getWalletSpendableUtxos,
getAddressDelegations,
getWalletDelegations,
getDelegationDetails,
Expand Down
Loading