Skip to content

Commit

Permalink
Merge pull request #403 from DcentWallet/nifty-wallet/feature/dcent-i…
Browse files Browse the repository at this point in the history
…ntegration

Add D'CENT hardware wallet support
  • Loading branch information
vbaranov committed Sep 20, 2021
2 parents 0cb6d65 + f6e6f73 commit 1be8c47
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@
"description": "choice between creating or importing a new account"
},
"orderOneHere": {
"message": "Order a Trezor or Ledger and keep your funds in cold storage"
"message": "Order a Trezor, Ledger or D'CENT and keep your funds in cold storage"
},
"origin": {
"message": "Origin"
Expand Down
2 changes: 1 addition & 1 deletion app/_locales/ko/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@
"description": "새 계정을 만들거나 가져오기 중에 선택하기"
},
"orderOneHere": {
"message": "Trezor 혹은 Ledger를 구입하고 자금을 콜드 스토리지에 저장합니다"
"message": "Trezor, Ledger 혹은 D'CENT를 구입하고 자금을 콜드 스토리지에 저장합니다"
},
"origin": {
"message": "Origin"
Expand Down
1 change: 1 addition & 0 deletions app/images/dcent-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ import seedPhraseVerifier from './lib/seed-phrase-verifier'
import log from 'loglevel'
const TrezorKeyring = require('eth-trezor-keyring')
const LedgerBridgeKeyring = require('eth-ledger-bridge-keyring')
import DcentKeyring from 'eth-dcent-keyring'
import EthQuery from 'eth-query'
import nanoid from 'nanoid'
const { importTypes } = require('../../old-ui/app/accounts/import/enums')
const { LEDGER, TREZOR } = require('../../old-ui/app/components/connect-hardware/enum')
const { LEDGER, TREZOR, DCENT } = require('../../old-ui/app/components/connect-hardware/enum')
const { ifPOA, ifXDai, ifRSK, getNetworkID, getDPath, setDPath } = require('../../old-ui/app/util')
const { GasPriceOracle } = require('gas-price-oracle')
import {
Expand Down Expand Up @@ -192,7 +193,7 @@ module.exports = class MetamaskController extends EventEmitter {
})

// key mgmt
const additionalKeyrings = [TrezorKeyring, LedgerBridgeKeyring]
const additionalKeyrings = [TrezorKeyring, LedgerBridgeKeyring, DcentKeyring]
this.keyringController = new KeyringController({
keyringTypes: additionalKeyrings,
initState: initState.KeyringController,
Expand Down Expand Up @@ -763,6 +764,9 @@ module.exports = class MetamaskController extends EventEmitter {
case LEDGER:
keyringName = LedgerBridgeKeyring.type
break
case DCENT:
keyringName = DcentKeyring.type
break
default:
throw new Error('MetamaskController:getKeyringForDevice - Unknown device')
}
Expand Down
21 changes: 18 additions & 3 deletions old-ui/app/components/connect-hardware/connect-screen.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import Button from '../../../../ui/app/components/button'
import { LEDGER, TREZOR } from './enum'
import { LEDGER, TREZOR, DCENT } from './enum'
import { capitalizeFirstLetter } from '../../../../app/scripts/lib/util'

const trezorCap = capitalizeFirstLetter(TREZOR)
Expand Down Expand Up @@ -49,13 +49,27 @@ class ConnectScreen extends Component {
)
}

renderConnectToDcentButton () {
return (
<button
className={`hw-connect__btn${this.state.selectedDevice === DCENT ? ' selected' : ''}`}
onClick={(_) => this.setState({ selectedDevice: DCENT })}
>
<img className="hw-connect__btn__img" src="images/dcent-logo.svg"/>
</button>
)
}

renderButtons () {
return (
<div>
<div className="hw-connect__btn-wrapper">
{this.renderConnectToLedgerButton()}
{this.renderConnectToTrezorButton()}
</div>
<div className="hw-connect__btn-wrapper">
{this.renderConnectToDcentButton()}
</div>
<button
className={`hw-connect__connect-btn${!this.state.selectedDevice ? ' disabled' : ''}`}
onClick={this.connect}
Expand Down Expand Up @@ -94,10 +108,11 @@ class ConnectScreen extends Component {
const links = {
trezor: `<a class='hw-connect__get-hw__link' href='https://shop.trezor.io/?a=niftywallet' target='_blank'>${trezorCap}</a>`,
ledger: `<a class='hw-connect__get-hw__link' href='https://www.ledger.com/products/ledger-nano-s' target='_blank'>${ledgerCap}</a>`,
dcent: `<a class='hw-connect__get-hw__link' href='https://dcentwallet.com/Shop?utm_source=metamask&utm_medium=affiliate&utm_campaign=202005-metamask-promotion' target='_blank'>D'CENT</a>`,
}

const text = `Order a ${trezorCap} or ${ledgerCap} and keep your funds in cold storage`
const response = text.replace(trezorCap, links.trezor).replace(ledgerCap, links.ledger)
const text = `Order a ${trezorCap}, ${ledgerCap} or D'CENT and keep your funds in cold storage`
const response = text.replace(trezorCap, links.trezor).replace(ledgerCap, links.ledger).replace(`D'CENT`, links.dcent)

return (
<div className="hw-connect__get-hw__msg" dangerouslySetInnerHTML={{ __html: response }} />
Expand Down
2 changes: 2 additions & 0 deletions old-ui/app/components/connect-hardware/enum.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const LEDGER = 'ledger'
const TREZOR = 'trezor'
const DCENT = 'dcent'

module.exports = {
LEDGER,
TREZOR,
DCENT,
}
4 changes: 2 additions & 2 deletions old-ui/app/components/connect-hardware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { formatBalance } from '../../util'
import { getPlatform } from '../../../../app/scripts/lib/util'
import { PLATFORM_FIREFOX } from '../../../../app/scripts/lib/enums'
import { getMetaMaskAccounts } from '../../../../ui/app/selectors'
import { LEDGER, TREZOR } from './enum'
import { LEDGER, TREZOR, DCENT } from './enum'

class ConnectHardwareForm extends Component {
constructor (props, context) {
Expand Down Expand Up @@ -45,7 +45,7 @@ class ConnectHardwareForm extends Component {
}

async checkIfUnlocked () {
[TREZOR, LEDGER].forEach(async device => {
[TREZOR, LEDGER, DCENT].forEach(async device => {
const hdPath = this._setHdPath(device)
const unlocked = await this.props.checkHardwareStatus(device, hdPath)
if (unlocked) {
Expand Down
8 changes: 7 additions & 1 deletion old-ui/app/css/hw.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
flex-direction: row;
display: flex;
}
.hw-connect__btn-wrapper:not(:first-of-type) {
margin-top: 15px;
}
.hw-connect__connect-btn {
color: #fff;
border: none;
Expand Down Expand Up @@ -64,8 +67,11 @@
border: 2px solid #60DB97;
width: 149px;
}
.hw-connect__btn:first-child {
.hw-connect__btn:not(:last-of-type) {
margin-right: 15px;
}
.hw-connect__btn:first-child {

}
.hw-connect__btn:last-child {

Expand Down
65 changes: 65 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
"dnode": "^1.2.2",
"end-of-stream": "^1.4.4",
"eth-block-tracker": "^4.4.2",
"eth-contract-metadata": "^1.13.0",
"eth-dcent-keyring": "^0.1.2",
"eth-ens-namehash": "^2.0.8",
"eth-json-rpc-errors": "^2.0.2",
"eth-json-rpc-filters": "github:poanetwork/eth-json-rpc-filters#3.0.2",
Expand Down
1 change: 1 addition & 0 deletions ui/app/reducers/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function reduceApp (state, action) {
defaultHdPaths: {
trezor: `m/44'/60'/0'/0`,
ledger: `m/44'/60'/0'/0/0`,
dcent: `m/44'/60'/0'/0/0`,
},
customHdPaths: customHdPaths,
}, state.appState)
Expand Down

0 comments on commit 1be8c47

Please sign in to comment.