Skip to content

Commit

Permalink
Merge pull request #127 from mintlayer/dev
Browse files Browse the repository at this point in the history
* A-1206811020024239: fix transaction list (#124)

* A-1206811020024239: fix transaction list

* add icon

* A-1206478979914858 (#125)

* feat: update Mintlayer library and crypto srvices

* feat: add new endpoints to Mintlayer API services

* feat: add version number to the index page

* feat: add Transaction context

* feat: improves Mintlayer helpers to support delegations

* feat: add Staking component

* feat: add delegation item

* feat: add delegation details

* feat: add list of delegations

* feat: update existing components to work with new data

* feat: upate address field

* feat: improvements for the mlWalletInfo hook

* test: add unit tests

* style: styles improvments

* feat: uopdate Mintlayer library

* fix: delegation fee estimates

* feat: change block exlorer link title

* feat: add tooltip with staking guide

* remove date from delegation

* feat: delegation item improvements

* test: fix delegation test

* feat: add pool id to the delegation details

* feat: add pool list link

* fix: back button click handler

* feat: remove amout field if delegation transaction

* feat: update delegation with action buttons

* feat: update transaction result message, styles improvements

* fix: spending from delegation max value

* increase varsion to 1.2.0

* feat: add delegation description

* feat: change send transaction button title if delegation mode

* A-1206823923357146: explorer integration

* +

* +

* update routes

* feat: add unconfirmed delegation, refactorng and improvements

* change button title if delegation

* navigate to staking page if delegation transaction

* feat: routing improvements

* feat: button title

* fix: fix dev env

* autoupdate staking page

* fix: unconfirmed transaction appearance

* chore: remove console.log

---------

Co-authored-by: Sergey Chystiakov <[email protected]>

---------

Co-authored-by: Sergey <[email protected]>
  • Loading branch information
owlsua and anyxem authored Mar 20, 2024
2 parents b0ea208 + a18a973 commit c3ff1aa
Show file tree
Hide file tree
Showing 78 changed files with 5,883 additions and 687 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/create-transaction.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe(
expect(text.toString().trim()).contains(_amount)
})

cy.contains('button', 'Open In Blockchain').should('be.visible')
cy.contains('button', 'Open In Block Explorer').should('be.visible')
cy.get('button[class="btn popupCloseButton alternate"]').click()
})
},
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/view-transaction-detail.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('View transaction detail page', () => {
cy.contains('Date:').should('be.visible')
cy.contains('Amount:').should('be.visible')
cy.contains('Tx:').should('be.visible')
cy.contains('button', 'Open In Blockchain').should('be.visible')
cy.contains('button', 'Open In Block Explorer').should('be.visible')

cy.get('button[class="btn popupCloseButton alternate"]').click()
})
Expand All @@ -43,7 +43,7 @@ describe('View transaction detail page', () => {
cy.contains('Date:').should('be.visible')
cy.contains('Amount:').should('be.visible')
cy.contains('Tx:').should('be.visible')
cy.contains('button', 'Open In Blockchain').should('be.visible')
cy.contains('button', 'Open In Block Explorer').should('be.visible')

cy.get('button[class="btn popupCloseButton alternate"]').click()
})
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/view-transactions.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('View transactions page', () => {
.click()
.then(() => {
cy.wait(1000)
cy.contains('button', 'Open In Blockchain').should('be.visible')
cy.contains('button', 'Open In Block Explorer').should('be.visible')
cy.get('button.btn.popupCloseButton.alternate').click()
})
})
Expand Down
19 changes: 16 additions & 3 deletions package-lock.json

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

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "browser-extension",
"version": "1.1.8",
"version": "1.2.0",
"private": true,
"dependencies": {
"@mintlayer/entropy-generator": "^1.0.2",
Expand Down Expand Up @@ -118,6 +118,7 @@
"@Assets/(.*)": "<rootDir>/src/assets/$1",
"@BasicComponents": "<rootDir>/src/components/basic/index.js",
"@ComposedComponents": "<rootDir>/src/components/composed/index.js",
"@ContainerComponents": "<rootDir>/src/components/containers/index.js",
"@LayoutComponents": "<rootDir>/src/components/layouts/index.js",
"@Constants": "<rootDir>/src/utils/Constants/index.js",
"@Helpers": "<rootDir>/src/utils/Helpers/index.js",
Expand All @@ -130,7 +131,7 @@
"@APIs": "<rootDir>/src/services/API/index.js",
"d3": "<rootDir>/node_modules/d3/dist/d3.min.js",
"@Storage": "<rootDir>/src/services/Storage/index.js",
".*wasm_crypto.js": "<rootDir>/src/tests/mock/wasmCrypro/wasmCrypto.js"
".*wasm_wrappers.js": "<rootDir>/src/tests/mock/wasmCrypro/wasmCrypto.js"
},
"collectCoverageFrom": [
"!src/pages",
Expand Down Expand Up @@ -200,6 +201,7 @@
"pretty-quick": "^3.1.3",
"react-app-rewire-alias": "^1.1.7",
"react-scripts": "5.0.1",
"wallet-address-validator": "^0.2.4"
"wallet-address-validator": "^0.2.4",
"webextension-polyfill": "^0.10.0"
}
}
119 changes: 119 additions & 0 deletions public/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/* global chrome */

var popupWindowId = false
var connectWindowId = false

chrome.runtime.onMessageExternal.addListener(function (
request,
sender,
sendResponse,
) {
if (request) {
if (request.message) {
if (request.message === 'version') {
sendResponse({ version: chrome.runtime.getManifest().version })
}

if (request.message === 'connect') {
if (connectWindowId === false) {
popupWindowId = true
chrome.windows.create(
{
url: chrome.runtime.getURL('index.html'),
type: 'popup',
width: 800,
height: 600,
focused: true,
},
function (win) {
connectWindowId = win.id
setTimeout(function () {
chrome.runtime.sendMessage(
{
action: 'connect',
},
function (response) {
sendResponse(response)
},
)
}, 1000)
},
)
} else if (typeof popupWindowId === 'number') {
//The window is open, and the user clicked the button.
// Focus the window.
chrome.windows.update(popupWindowId, { focused: true })
}
}

if (request.message === 'delegate') {
if (popupWindowId === false) {
popupWindowId = true
chrome.windows.create(
{
url: chrome.runtime.getURL('index.html'),
type: 'popup',
width: 800,
height: 600,
focused: true,
},
function (win) {
popupWindowId = win.id
setTimeout(function () {
chrome.runtime.sendMessage({
action: 'createDelegate',
data: { pool_id: request.pool_id },
})
}, 1000)
},
)
} else if (typeof popupWindowId === 'number') {
//The window is open, and the user clicked the button.
// Focus the window.
chrome.windows.update(popupWindowId, { focused: true })
}
}

if (request.message === 'stake') {
if (popupWindowId === false) {
popupWindowId = true
chrome.windows.create(
{
url: chrome.runtime.getURL('index.html'),
type: 'popup',
width: 800,
height: 600,
focused: true,
},
function (win) {
popupWindowId = win.id
setTimeout(function () {
chrome.runtime.sendMessage({
action: 'addStake',
data: {
delegation_id: request.delegation_id,
amount: request.amount,
},
})
}, 1000)
},
)
} else if (typeof popupWindowId === 'number') {
//The window is open, and the user clicked the button.
// Focus the window.
chrome.windows.update(popupWindowId, { focused: true })
}
}
}
}
return true
})

chrome.windows.onRemoved.addListener(function (winId) {
if (popupWindowId === winId) {
popupWindowId = false
}
if (connectWindowId === winId) {
connectWindowId = false
}
})
13 changes: 13 additions & 0 deletions public/explorer/content-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function start() {
window.addEventListener('InitWalletRequest', function (evt) {
var content = {
type: 'MOJITO_INIT',
version: chrome.runtime.getManifest().version,
extension_id: chrome.runtime.id,
}
var event = new CustomEvent('InitWalletResponse', { detail: content })
window.dispatchEvent(event)
})
}

start()
28 changes: 26 additions & 2 deletions 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.8",
"version": "1.2.0",
"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 All @@ -20,5 +20,29 @@
"default_icon": "logo192.png",
"default_title": "Mojito",
"default_popup": "index.html"
}
},
"background": {
"service_worker": "background.js",
"type": "module"
},
"externally_connectable": {
"matches": [
"*://localhost/*",
"*://explorer.mintlayer.org/*",
"*://lovelace.explorer.mintlayer.org/*",
"*://blockexplorer-staging.mintlayer.org/*"
]
},
"permissions": ["externally_connectable"],
"content_scripts": [
{
"matches": [
"*://localhost/*",
"*://explorer.mintlayer.org/*",
"*://lovelace.explorer.mintlayer.org/*",
"*://blockexplorer-staging.mintlayer.org/*"
],
"js": ["explorer/content-script.js"]
}
]
}
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.8",
"version": "1.2.0",
"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
6 changes: 4 additions & 2 deletions src/components/basic/Arc/Arc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const createTooltip = () =>
d3
.select('body')
.append('div')
.attr('class', 'tooltip')
.attr('class', 'chart-tooltip')
.attr('data-testid', 'tooltip-container')
.style('opacity', 0)

Expand All @@ -28,7 +28,9 @@ const mouseOverHandle = (tooltip, _, item) => {
.duration(200)
.style('opacity', 0.9)

tooltip.html(`${item.data.asset} <br />${item.data.value} ${item.data.valueSymbol} `)
tooltip.html(
`${item.data.asset} <br />${item.data.value} ${item.data.valueSymbol} `,
)
}

const mouseOutHandle = (tooltip) => {
Expand Down
6 changes: 5 additions & 1 deletion src/components/basic/Input/InputBTC.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { useEffect, useState, useContext } from 'react'
import { AppInfo, Expressions } from '@Constants'
import { NumbersHelper } from '@Helpers'
import { useEffect, useState } from 'react'
import Input from './Input'

import { TransactionContext } from '@Contexts'

const InputBTC = (props) => {
const { transactionMode } = useContext(TransactionContext)
const mask = Expressions.FIELDS.BTC.getExpression(
AppInfo.decimalSeparator,
AppInfo.thousandsSeparator,
Expand Down Expand Up @@ -87,6 +90,7 @@ const InputBTC = (props) => {
mask={mask}
getMaskedValue={getMaskedValue}
justNumbers
disabled={transactionMode === AppInfo.ML_TRANSACTION_MODES.DELEGATION}
/>
)
}
Expand Down
33 changes: 33 additions & 0 deletions src/components/basic/Timer/Timer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { useEffect, useState } from 'react'

const Timer = ({ onTimerEnd, repeat, duration }) => {
const [timer, setTimer] = useState(null)

const stopTimer = () => {
if (timer) {
clearTimeout(timer)
setTimer(null)
}
}

const startTimer = () => {
stopTimer() // Ensure no timer is already running
const newTimer = setTimeout(() => {
onTimerEnd() // Call the function provided via props
if (repeat) {
startTimer() // Restart the timer if `repeat` is true
}
}, duration)
setTimer(newTimer)
}

useEffect(() => {
startTimer()
return () => stopTimer() // Cleanup on component unmount
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [repeat, duration, onTimerEnd])

return <div></div>
}

export default Timer
Loading

0 comments on commit c3ff1aa

Please sign in to comment.