Skip to content

Commit

Permalink
Merge pull request #110 from mintlayer/dev
Browse files Browse the repository at this point in the history
Dev-17-02-2024-v-1-1-5
  • Loading branch information
owlsua authored Feb 17, 2024
2 parents 2c71956 + b959b99 commit 7841f5d
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 19 deletions.
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.4",
"version": "1.1.5",
"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.4",
"version": "1.1.5",
"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.4",
"version": "1.1.5",
"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 src/components/containers/Login/SetPassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const SetPassword = ({ onChangePassword, onSubmit, checkPassword }) => {
<Header />
<div className="content">
<CenteredLayout>
<form>
<form onSubmit={doLogin}>
<VerticalGroup bigGap>
{!unlockingAccount ? (
<>
Expand Down
39 changes: 32 additions & 7 deletions src/components/containers/SendTransaction/SendTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import AmountField from './AmountField'
import FeesField from './FeesField'

import './SendTransaction.css'
import { Error } from '@BasicComponents'

const SendTransaction = ({
totalFeeFiat: totalFeeFiatParent,
Expand Down Expand Up @@ -44,6 +45,7 @@ const SendTransaction = ({
const [passValidity, setPassValidity] = useState(false)
const [passPristinity, setPassPristinity] = useState(true)
const [passErrorMessage, setPassErrorMessage] = useState('')
const [txErrorMessage, setTxErrorMessage] = useState('')
const [sendingTransaction, setSendingTransaction] = useState(false)
const [transactionTxid, setTransactionTxid] = useState(false)
const [allowClosing, setAllowClosing] = useState(true)
Expand All @@ -62,6 +64,7 @@ const SendTransaction = ({
setPassValidity(false)
setPass('')
setPassErrorMessage('')
// setTxErrorMessage('')
setOpenSendFundConfirmation(state)
}

Expand Down Expand Up @@ -90,14 +93,26 @@ const SendTransaction = ({
setTransactionTxid(txid)
setPassValidity(true)
setPassErrorMessage('')
setTxErrorMessage('')
setAskPassword(false)
} catch (e) {
console.error(e)
setPassPristinity(false)
setPassValidity(false)
setPass('')
setPassErrorMessage('Incorrect password. Account could not be unlocked')
setAllowClosing(true)
if (e.address === '') {
// password is not correct
setPassErrorMessage('Incorrect password')
setPassPristinity(false)
setPassValidity(false)
setPass('')
setAllowClosing(true)
} else {
// handle other errors
setAskPassword(false)
setPassPristinity(false)
setPassValidity(false)
setPass('')
setTxErrorMessage(e.message)
setAllowClosing(true)
setPopupState(false)
}
} finally {
setSendingTransaction(false)
}
Expand Down Expand Up @@ -230,12 +245,21 @@ const SendTransaction = ({
totalFeeInCrypto={totalFeeCrypto}
/>

{/* TODO style error from transaction */}
<FeesField
feeChanged={feeChanged}
value="norm"
setFeeValidity={setFeeValidity}
/>

{txErrorMessage ? (
<>
<Error error={txErrorMessage} />
</>
) : (
<></>
)}

<CenteredLayout>
<Button
extraStyleClasses={['send-transaction-button']}
Expand All @@ -256,7 +280,7 @@ const SendTransaction = ({
{!transactionTxid ? (
sendingTransaction ? (
<VerticalGroup bigGap>
<h2>Your transaction is being created and sent.</h2>
<h2>Your transaction broadcasting to network.</h2>
<div className="loading-center">
<Loading />
</div>
Expand All @@ -270,6 +294,7 @@ const SendTransaction = ({
fiatName={fiatName}
totalFeeFiat={totalFeeFiat}
totalFeeCrypto={totalFeeCrypto}
// txErrorMessage={txErrorMessage} // TODO move update on confirmation stage
fee={fee}
onConfirm={handleConfirm}
onCancel={handleCancel}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext } from 'react'
import { Button } from '@BasicComponents'
import React, { useContext } from 'react'
import { Button, Error } from '@BasicComponents'
import { CenteredLayout, VerticalGroup } from '@LayoutComponents'
import { AccountContext, SettingsContext } from '@Contexts'
import { AppInfo } from '@Constants'
Expand All @@ -12,6 +12,7 @@ const SendFundConfirmation = ({
amountInCrypto,
cryptoName,
fiatName,
txErrorMessage,
totalFeeFiat,
totalFeeCrypto,
fee,
Expand Down Expand Up @@ -62,6 +63,8 @@ const SendFundConfirmation = ({
</dl>

<VerticalGroup>
{txErrorMessage ? <Error error={txErrorMessage} /> : <></>}

<Button onClickHandle={onConfirm}>Confirm</Button>
<Button
dark
Expand Down
19 changes: 18 additions & 1 deletion src/services/API/Mintlayer/Mintlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,24 @@ const requestMintlayer = async (url, body = null, request = fetch) => {

try {
const result = await request(url, { method, body })
if (!result.ok) throw new Error('Request not successful')
if (!result.ok) {
const error = await result.json()
if (error.error === 'Address not found') {
return Promise.resolve(
JSON.stringify({ coin_balance: 0, transaction_history: [] }),
)
}

// handle RPC error
if (error.error.includes('Mempool error:')) {
const errorMessage = error.error
.split('Mempool error: ')[1]
.split('(')[0]
throw new Error(errorMessage)
}

throw new Error('Request not successful')
}
const content = await result.text()
return Promise.resolve(content)
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions src/services/API/Mintlayer/Mintlayer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const FIRST_TX_ID =
test('getAddressData', async () => {
const result = await getAddressData(TESTNET_WALLET)
const data = JSON.parse(result)
expect(data.coin_balance).toBeGreaterThan(0)
expect(Number(data.coin_balance)).toBeGreaterThan(0)
const firstTransactionId =
data.transaction_history[data.transaction_history.length - 1]
expect(data.transaction_history.length).toBeGreaterThan(0)
Expand All @@ -95,5 +95,5 @@ test('Mintlayer API request - getAdressTransactions', async () => {

test('Mintlayer API request - getAddressBalance', async () => {
const result = await getAddressBalance(TESTNET_WALLET)
expect(result.balanceInAtoms).toBeGreaterThan(0)
expect(Number(result.balanceInAtoms)).toBeGreaterThan(0)
})
2 changes: 1 addition & 1 deletion src/utils/Helpers/ML/MLTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const calculateFee = async (
)
const feeEstimatesResponse = await Mintlayer.getFeesEstimates()
const feeEstimates = JSON.parse(feeEstimatesResponse)
const fee = (Number(feeEstimates) / 1000) * size
const fee = Math.ceil((Number(feeEstimates) / 1000) * size)

return fee
}
Expand Down

0 comments on commit 7841f5d

Please sign in to comment.