Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI style "no active adm nodes" dialog #675

Closed
wants to merge 12 commits into from
11 changes: 7 additions & 4 deletions src/components/NodesOfflineDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ export default {
@import 'vuetify/_settings.scss';
@import '@/assets/styles/settings/_colors.scss';

.nodes-offline-dialog {
.all-nodes-disabled-dialog {
&__card-title {
padding: 14px !important;
}
&__card-text {
padding: 16px !important;
padding: 14px !important;
}
&__disclaimer {
margin-top: 10px;
Expand All @@ -91,13 +94,13 @@ export default {
margin-right: 8px;
}
&__btn-block {
padding: 16px 0 32px 0;
padding: 16px 0 16px 0;
text-align: center;
}
}

.v-theme--dark {
.nodes-offline-dialog {
.all-nodes-disabled-dialog {
&__disclaimer {
color: map-get($shades, 'white');
}
Expand Down
25 changes: 14 additions & 11 deletions src/components/SendFundsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ import {
Fees
} from '@/lib/constants'

import { parseURIasAIP } from '@/lib/uri'
import { parseURI } from '@/lib/uri'
import { sendMessage } from '@/lib/adamant-api'
import { replyMessageAsset } from '@/lib/adamant-api/asset'

Expand Down Expand Up @@ -310,6 +310,7 @@ export default {
increaseFee: false,
showWarningOnPartnerAddressDialog: false,
warningOnPartnerInfo: {},
klayrOptionalMessage: '',

// Account exists check
// Currently works only with KLY
Expand Down Expand Up @@ -671,7 +672,7 @@ export default {
*/
onPasteURIAddress(e) {
const data = e.clipboardData.getData('text')
const address = parseURIasAIP(data).address
const address = parseURI(data).address

if (validateAddress(this.currency, address)) {
e.preventDefault()
Expand All @@ -687,7 +688,7 @@ export default {
*/
onPasteURIComment(e) {
nextTick(() => {
const params = parseURIasAIP(e.target.value).params
const params = parseURI(e.target.value).params

if (params.message) {
this.comment = params.message
Expand All @@ -700,18 +701,20 @@ export default {
* @param {string} uri URI
*/
onScanQrcode(uri) {
const recipient = parseURIasAIP(uri)

this.cryptoAddress = ''
if (validateAddress(this.currency, recipient.address)) {
this.cryptoAddress = recipient.address
if (recipient.params.amount) {
const amount = formatNumber(this.exponent)(recipient.params.amount)

const recipient = parseURI(uri)
const { params, address, crypto } = recipient
const isValidAddress = validateAddress(this.currency, address)
if (isValidAddress) {
this.cryptoAddress = address
if (params.amount && !this.amountString) {
const amount = formatNumber(this.exponent)(params.amount)
if (Number(amount) <= this.maxToTransfer) {
this.amountString = amount
}
}
if (crypto === Cryptos.KLY) {
this.textData = params.reference ? params.reference : ''
}
} else {
this.$emit('error', this.$t('transfer.error_incorrect_address', { crypto: this.currency }))
}
Expand Down
77 changes: 62 additions & 15 deletions src/lib/uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { isAddress as isEthAddress, isHexStrict } from 'web3-utils'
import { validateBase32Address as isKlyAddress } from '@klayr/cryptography'
import { Cryptos, CryptosInfo } from './constants'

const KLAYR_WALLET = 'klayr://wallet'

/**
* Get an ADAMANT URI from the address bar or argv[]
* Complies with AIP-2, AIP-8, AIP-9
Expand All @@ -18,11 +20,68 @@ export function getAddressBarURI() {
return aip2 || document.URL
}

const formQueryParamsObject = (query) => {
return query.split('&').reduce((accum, param) => {
const [key, value = ''] = param.split('=')
return key && value
? {
...accum,
[key]: window.decodeURIComponent(
value.includes('+') ? value.replace(/\+/g, ' ') : value
)
}
: accum
}, {})
}

/**
* Parse info from an URI
* @param {string} uri URI. Default is address bar or argv[].
* @returns {
* {
* address: string,
* crypto: string,
* params: Object<string, string>,
* protocol: string
* }
* }
*/
export function parseURI(uri = getAddressBarURI()) {
const [origin, query = ''] = uri.split('?')
if (origin === KLAYR_WALLET) return parseKlyURI(query)
return parseURIasAIP(uri)
}

/**
* Parse info from an URI of the Klayr wallet
* Ex.: klayr://wallet?modal=send&recipient=klyap2bbanxn4agw286ofz85zf3y2brdzjdyoby8r&amount=123&token=0000000000000000&recipientChain=00000000
* @param {string} URI's query parameters
* @returns {
* {
* address: string,
* crypto: string,
* params: Object<string, string>,
* protocol: string
* }
* }
*/
function parseKlyURI(query) {
let address = ''
let params = {}

if (query) {
params = formQueryParamsObject(query)
address = params.recipient || ''
}

return { address, crypto: Cryptos.KLY, params, protocol: Cryptos.KLY.toLowerCase() }
}

/**
* Parse info from an URI containing a cryptocurrency address
* Complies with AIP-2, AIP-8, AIP-9
* Sample: https://msg.adamant.im?address=U9821606738809290000&label=John+Doe&amount=1.12&message=Buy+a+beer
* @param {string} uri URI. Default is address bar or argv[].
* @param {string} URI
* @returns {
* {
* address: string,
Expand All @@ -39,22 +98,10 @@ export function parseURIasAIP(uri = getAddressBarURI()) {
let params = Object.create(null)
let protocol = ''

if (query) {
params = query.split('&').reduce((accum, param) => {
const [key, value = ''] = param.split('=')
return key && value
? {
...accum,
[key]: window.decodeURIComponent(
value.includes('+') ? value.replace(/\+/g, ' ') : value
)
}
: accum
}, Object.create(null))
}
if (query) params = formQueryParamsObject(query)

if (origin.includes(':')) {
;[protocol, address] = origin.split(':')
[protocol, address] = origin.split(':')
if (protocol === 'ethereum') {
crypto = Cryptos.ETH
} else if (/^https?$/.test(protocol) || /^app$/.test(protocol)) {
Expand Down