Skip to content

Commit

Permalink
Merge pull request #129 from mintlayer/dev
Browse files Browse the repository at this point in the history
Dev-26-03-2024-v-1-2-1
  • Loading branch information
owlsua authored Mar 26, 2024
2 parents c3ff1aa + b44dd49 commit 6854582
Show file tree
Hide file tree
Showing 18 changed files with 181 additions and 47 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/create-account.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('create account page ', () => {
'Write down each of the words (seed phrases) that are shown on the next screen.',
).should('be.visible')
cy.contains(
'Store them in a safe place as they are the only way to restore your account.',
'Store them in a safe place as they are the only way to restore your wallet.',
).should('be.visible')
cy.contains('button', 'I understand').should('be.visible')

Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/home.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ describe('mojito wallet app', () => {
it('click on Create and navigate', () => {
cy.contains('button', 'Create').click()

cy.contains('Create a name for your account').should('be.visible')
cy.contains('Create a name for your wallet').should('be.visible')
})

it('click on Restore and navigate', () => {
cy.contains('button', 'Restore').click()
cy.contains('Create a name for your account').should('be.visible')
cy.contains('Create a name for your wallet').should('be.visible')
})
})
8 changes: 4 additions & 4 deletions cypress/e2e/set-account.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ describe('set Account page', () => {
cy.contains('button', 'Create').click()
})

it('check and click on button Account Name', function () {
cy.contains('li.step.active', 'Account Name').should('be.visible')
cy.contains('Create a name for your account').should('be.visible')
it('check and click on button Wallet Name', function () {
cy.contains('li.step.active', 'Wallet Name').should('be.visible')
cy.contains('Create a name for your wallet').should('be.visible')
cy.contains('Mojito').should('be.visible')

cy.setAccount(this.access.name)
cy.contains('button', 'Continue').should('be.visible')

cy.contains('li.step.false', 'Account Name').should('be.visible')
cy.contains('li.step.false', 'Wallet Name').should('be.visible')
})
})
2 changes: 1 addition & 1 deletion cypress/e2e/set-password.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('set password page', () => {

it('displays attribute pages', () => {
cy.contains('li.step.active', 'Account Password').should('be.visible')
cy.contains('Create a password for your account').should('be.visible')
cy.contains('Create a password for your wallet').should('be.visible')
cy.contains('Mojito').should('be.visible')
cy.contains('button', 'Continue').should('be.visible')
cy.get('input[placeholder="Password"]').should('be.visible')
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.2.0",
"version": "1.2.1",
"private": true,
"dependencies": {
"@mintlayer/entropy-generator": "^1.0.2",
Expand Down
107 changes: 107 additions & 0 deletions public/background-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/* eslint-disable no-undef */
let popupWindowId = null
let connectWindowId = null
let isPopupOpening = false

browser.runtime.onConnect.addListener((port) => {
port.onMessage.addListener((msg) => {
if (msg && msg.myProperty && msg.myProperty.message) {
switch (msg.myProperty.message.message) {
case 'version':
port.postMessage({ version: browser.runtime.getManifest().version })
break
case 'connect':
handleConnect(msg, port)
break
case 'delegate':
handleDelegate(msg)
break
case 'stake':
handleStake(msg)
break
default:
console.log('Unknown message')
}
}
})

async function handleConnect(request, port) {
if (connectWindowId === null) {
await createPopup('index.html', async (win) => {
connectWindowId = win.id
setTimeout(async () => {
const response = await browser.runtime.sendMessage({
action: 'connect',
})
port.postMessage(response)
}, 1000)
})
} else {
await browser.windows.update(connectWindowId, { focused: true })
}
}

async function handleDelegate(request) {
if (popupWindowId === null && !isPopupOpening) {
isPopupOpening = true
await createPopup('index.html', async (win) => {
popupWindowId = win.id
isPopupOpening = false
setTimeout(async () => {
await browser.runtime.sendMessage({
action: 'createDelegate',
data: { pool_id: request.myProperty.message.pool_id },
})
}, 1000)
})
} else if (popupWindowId !== null) {
await browser.windows.update(popupWindowId, { focused: true })
}
}

async function handleStake(request) {
if (popupWindowId === null) {
await createPopup('index.html', async (win) => {
popupWindowId = win.id
setTimeout(async () => {
await browser.runtime.sendMessage({
action: 'addStake',
data: {
delegation_id: request.delegation_id,
amount: request.amount,
},
})
}, 1000)
})
} else {
await browser.windows.update(popupWindowId, { focused: true })
}
}

function createPopup(url, callback) {
return new Promise((resolve, reject) => {
browser.windows
.create({
url: browser.runtime.getURL(url),
type: 'popup',
width: 800,
height: 630,
focused: true,
})
.then((win) => {
resolve(callback(win))
})
.catch((error) => {
reject(error)
})
})
}
browser.windows.onRemoved.addListener((winId) => {
if (popupWindowId === winId) {
popupWindowId = null
}
if (connectWindowId === winId) {
connectWindowId = null
}
})
})
3 changes: 2 additions & 1 deletion public/background.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-depth */
/* global chrome */

var popupWindowId = false
Expand Down Expand Up @@ -82,7 +83,7 @@ chrome.runtime.onMessageExternal.addListener(function (
url: chrome.runtime.getURL('index.html'),
type: 'popup',
width: 800,
height: 600,
height: 630,
focused: true,
},
function (win) {
Expand Down
24 changes: 22 additions & 2 deletions public/explorer/content-script.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
/* eslint-disable no-undef */
function start() {
const api = typeof browser !== 'undefined' ? browser : chrome
window.addEventListener('InitWalletRequest', function (evt) {
var content = {
type: 'MOJITO_INIT',
version: chrome.runtime.getManifest().version,
extension_id: chrome.runtime.id,
version: api.runtime.getManifest().version,
extension_id: api.runtime.id,
}

if (typeof cloneInto !== 'undefined') {
// Firefox
content = cloneInto(content, window)
}

var event = new CustomEvent('InitWalletResponse', { detail: content })

window.dispatchEvent(event)
window.addEventListener('message', (event) => {
if (
event.source == window &&
event.data &&
event.data.direction == 'from-page-script' &&
typeof browser !== 'undefined'
) {
const port = browser.runtime.connect({ name: 'my-connection' })
port.postMessage({ myProperty: event.data })
}
})
})
}

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.2.0",
"version": "1.2.1",
"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
40 changes: 23 additions & 17 deletions public/manifestFirefox.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"manifest_version": 3,
"name": "Mojito - A Mintlayer Wallet",
"version": "1.2.0",
"short_name": "Mojito",
"version": "1.2.1",
"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/",
"icons": {
Expand All @@ -13,26 +12,33 @@
"192": "logo192.png",
"512": "logo512.png"
},
"content_security_policy": {
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'; img-src 'self' data:; style-src 'self' https://fonts.cdnfonts.com https://fonts.googleapis.com https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com https://fonts.cdnfonts.com; style-src-elem 'self' https://fonts.googleapis.com"
"permissions": ["activeTab", "nativeMessaging", "tabs"],
"host_permissions": [
"*://localhost/*",
"*://explorer.mintlayer.org/*",
"*://lovelace.explorer.mintlayer.org/*",
"*://blockexplorer-staging.mintlayer.org/*"
],
"content_scripts": [
{
"matches": [
"*://localhost/*",
"*://explorer.mintlayer.org/*",
"*://lovelace.explorer.mintlayer.org/*",
"*://blockexplorer-staging.mintlayer.org/*"
],
"js": ["explorer/content-script.js"]
}
],
"background": {
"scripts": ["background-script.js"]
},
"action": {
"default_icon": "logo192.png",
"default_title": "Mojito",
"default_popup": "index.html"
},
"browser_specific_settings": {
"gecko": {
"id": "browserextension@mintlayer",
"strict_min_version": "109.0"
}
},
"host_permissions": ["https://www.mintlayer.org/"],
"commands": {
"_execute_action": {
"suggested_key": {
"default": "Ctrl+Shift+Y"
}
}
"content_security_policy": {
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'; img-src 'self' data:; style-src 'self' https://fonts.cdnfonts.com https://fonts.googleapis.com https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com https://fonts.cdnfonts.com; style-src-elem 'self' https://fonts.googleapis.com"
}
}
6 changes: 3 additions & 3 deletions src/components/composed/Carousel/Carousel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ test('Render Carousel', () => {
test('Render Carousel onClick', () => {
render(<Carousel {...data} />)

fireEvent.click(screen.getByText('Account Name'))
fireEvent.click(screen.getByText('Account Wallet'))
expect(data.onClick).toHaveBeenCalled()
screen.getByText('Account Name')
expect(screen.getByText('Account Name')).toHaveClass('selected')
screen.getByText('Wallet Name')
expect(screen.getByText('Wallet Name')).toHaveClass('selected')
})

test('Render Carousel previousSlide', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/components/containers/CreateAccount/CreateAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const CreateAccount = ({

useEffect(() => {
const message = !accountNameValid
? 'The account name should have at least 4 characteres.'
? 'The wallet name should have at least 4 characteres.'
: null

setAccountNameErrorMessage(message)
Expand Down Expand Up @@ -225,8 +225,8 @@ const CreateAccount = ({
value={accountNameValue}
onChangeHandle={accountNameChangeHandler}
validity={accountNameValid}
placeHolder={'Account Name'}
label={'Create a name for your account'}
placeHolder={'Wallet Name'}
label={'Create a name for your wallet'}
extraStyleClasses={inputExtraclasses}
errorMessages={accountNameErrorMessage}
pristinity={accountNamePristinity}
Expand All @@ -242,7 +242,7 @@ const CreateAccount = ({
validity={accountPasswordValid}
pattern={passwordPattern}
password
label={'Create a password for your account'}
label={'Create a password for your wallet'}
placeHolder={'Password'}
extraStyleClasses={inputExtraclasses}
errorMessages={accountPasswordErrorMessage}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test('Renders set account page with step 1', () => {
expect(setAccountForm).toBeInTheDocument()
expect(setAccountForm).toHaveAttribute('method', 'POST')
expect(inputComponent).toHaveAttribute('type', 'text')
expect(inputComponent).toHaveAttribute('placeholder', 'Account Name')
expect(inputComponent).toHaveAttribute('placeholder', 'Wallet Name')
fireEvent.change(inputComponent, { target: { value: '1' } })
expect(inputComponent).not.toHaveClass('invalid')
expect(inputComponent).not.toHaveClass('valid')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const WordsDescription = () => {
data-testid="description-paragraph"
>
Store them in a safe place as they are the only way to restore your
account.
wallet.
</p>
</CenteredLayout>
)
Expand Down
8 changes: 4 additions & 4 deletions src/components/containers/RestoreAccount/RestoreAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const RestoreAccount = ({

useEffect(() => {
const message = !accountNameValid
? 'The account name should have at least 4 characteres.'
? 'The wallet name should have at least 4 characteres.'
: null

setAccountNameErrorMessage(message)
Expand Down Expand Up @@ -259,8 +259,8 @@ const RestoreAccount = ({
value={accountNameValue}
onChangeHandle={accountNameChangeHandler}
validity={accountNameValid}
placeHolder={'Account Name'}
label={'Create a name for your account'}
placeHolder={'Wallet Name'}
label={'Create a name for your wallet'}
extraStyleClasses={inputExtraclasses}
errorMessages={accountNameErrorMessage}
pristinity={accountNamePristinity}
Expand All @@ -276,7 +276,7 @@ const RestoreAccount = ({
validity={accountPasswordValid}
pattern={passwordPattern}
password
label={'Create a password for your account'}
label={'Create a password for your wallet'}
placeHolder={'Password'}
extraStyleClasses={inputExtraclasses}
errorMessages={accountPasswordErrorMessage}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test('Renders restore account page with step 1', () => {
expect(restoreAccountForm).toBeInTheDocument()
expect(restoreAccountForm).toHaveAttribute('method', 'POST')
expect(inputComponent).toHaveAttribute('type', 'text')
expect(inputComponent).toHaveAttribute('placeholder', 'Account Name')
expect(inputComponent).toHaveAttribute('placeholder', 'Wallet Name')
fireEvent.change(inputComponent, { target: { value: '1' } })
expect(inputComponent).not.toHaveClass('invalid')
expect(inputComponent).not.toHaveClass('valid')
Expand Down
Loading

0 comments on commit 6854582

Please sign in to comment.