Skip to content

Commit

Permalink
Merge pull request #121 from mintlayer/dev
Browse files Browse the repository at this point in the history
Dev-28-02-2024-v-1-1-7
  • Loading branch information
owlsua authored Feb 28, 2024
2 parents bc77437 + c9a256c commit 2a243bb
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
REACT_APP_CONFIG_NAME=default
REACT_APP_WEBSITE_NAME=Mojito - A Mintlayer Wallet (default)
INLINE_RUNTIME_CHUNK=false
INLINE_RUNTIME_CHUNK=false
GENERATE_SOURCEMAP=false
MAINNET_ELECTRUM_SERVERS='https://blockstream.info/api'
TESTNET_ELECTRUM_SERVERS='http://51.158.172.176:3001, https://blockstream.info/testnet/api'
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "browser-extension",
"version": "1.1.6",
"version": "1.1.7",
"private": true,
"dependencies": {
"@mintlayer/entropy-generator": "^1.0.2",
Expand Down
2 changes: 1 addition & 1 deletion public/manifestDefault.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Mojito - A Mintlayer Wallet",
"version": "1.1.6",
"version": "1.1.7",
"short_name": "Mojito",
"description": "Mojito is a non-custodial decentralized crypto wallet that lets you send and receive BTC and ML from any other address.",
"homepage_url": "https://www.mintlayer.org/",
Expand Down
2 changes: 1 addition & 1 deletion public/manifestFirefox.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Mojito - A Mintlayer Wallet",
"version": "1.1.6",
"version": "1.1.7",
"short_name": "Mojito",
"description": "Mojito is a non-custodial decentralized crypto wallet that lets you send and receive BTC and ML from any other address.",
"homepage_url": "https://www.mintlayer.org/",
Expand Down
1 change: 1 addition & 0 deletions src/components/composed/Balance/Balance.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
margin-left: 17px;
position: relative;
overflow: visible;
width: 265px;
}

.balance-btc {
Expand Down
37 changes: 3 additions & 34 deletions src/hooks/UseWalletInfo/useMlWalletInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,10 @@ const useMlWalletInfo = (addresses) => {
...addresses.mlChangeAddresses,
]

// UTXO approach until api-server will provide both balances
const utxos = await Mintlayer.getWalletUtxos(addressList)
const balanceResult = await Mintlayer.getWalletBalance(addressList)

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

const availableAmount = parsedUtxos
.flatMap((utxo) => [...utxo])
.reduce((acc, utxo) => {
if (utxo.utxo.type === 'LockThenTransfer') {
if (utxo.utxo.lock.UntilTime.timestamp < Date.now() / 1000) {
return acc + Number(utxo.utxo.value.amount)
}
}
if (utxo.utxo.type === 'Transfer') {
return acc + Number(utxo.utxo.value.amount)
}
return acc
}, 0)

const lockedAmount = parsedUtxos
.flatMap((utxo) => [...utxo])
.reduce((acc, utxo) => {
if (utxo.utxo.type === 'LockThenTransfer') {
if (utxo.utxo.lock.UntilTime.timestamp > Date.now() / 1000) {
return acc + Number(utxo.utxo.value.amount)
}
}
return acc
}, 0)

// const balance = await Mintlayer.getWalletBalance(addressList)
const balance = { balanceInAtoms: availableAmount }
const balanceLocked = { balanceInAtoms: lockedAmount }
const balance = balanceResult.totalBalance
const balanceLocked = balanceResult.lockedBalance
const balanceInCoins = ML.getAmountInCoins(balance.balanceInAtoms)
const balanceLockedInCoins = ML.getAmountInCoins(
balanceLocked.balanceInAtoms,
Expand Down
24 changes: 20 additions & 4 deletions src/services/API/Mintlayer/Mintlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,16 @@ const getAddressBalance = async (address) => {
const balance = {
balanceInAtoms: data.coin_balance,
}
return balance
const balanceLocked = {
balanceInAtoms: data.locked_coin_balance || 0,
}
return { balance, balanceLocked }
} catch (error) {
console.warn(`Failed to get balance for address ${address}: `, error)
return { balanceInAtoms: 0 }
return {
balance: { balanceInAtoms: 0 },
balanceLocked: { balanceInAtoms: 0 },
}
}
}

Expand All @@ -96,12 +102,22 @@ export const getWalletBalance = async (addresses) => {
(acc, curr) => {
return {
balanceInAtoms:
+parseInt(acc.balanceInAtoms) + parseInt(curr.balanceInAtoms),
+parseInt(acc.balanceInAtoms) + parseInt(curr.balance.balanceInAtoms),
}
},
{ balanceInAtoms: 0 },
)
const lockedBalance = balances.reduce(
(acc, curr) => {
return {
balanceInAtoms:
+parseInt(acc.balanceInAtoms) +
parseInt(curr.balanceLocked.balanceInAtoms),
}
},
{ balanceInAtoms: 0 },
)
return totalBalance
return { totalBalance, lockedBalance }
}

const getAddressTransactionIds = async (address) => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/API/Mintlayer/Mintlayer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@ test('Mintlayer API request - getAdressTransactions', async () => {

test('Mintlayer API request - getAddressBalance', async () => {
const result = await getAddressBalance(TESTNET_WALLET)
expect(Number(result.balanceInAtoms)).toBeGreaterThan(0)
expect(Number(result.balance.balanceInAtoms)).toBeGreaterThan(0)
})
10 changes: 2 additions & 8 deletions src/utils/Helpers/ML/MLTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@ const getUtxoBalance = (utxo) => {
const getUtxoAvailable = (utxo) => {
const available = utxo
.flatMap((utxo) => [...utxo])
.filter((item) => item.utxo.value)
.reduce((acc, item) => {
if (item.utxo.type === 'Transfer') {
acc.push(item)
}
if (item.utxo.type === 'LockThenTransfer') {
if (item.utxo.lock.UntilTime.timestamp < Date.now() / 1000) {
acc.push(item)
}
}
acc.push(item)
return acc
}, [])

Expand Down

0 comments on commit 2a243bb

Please sign in to comment.