From ccf5eda74f4313fe3a7852604b8034a118949380 Mon Sep 17 00:00:00 2001 From: Ivanov N Date: Mon, 21 Oct 2024 10:28:58 +0300 Subject: [PATCH 01/12] All-nodes-disabled-dialog bottom padding --- src/components/NodesOfflineDialog.vue | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/components/NodesOfflineDialog.vue b/src/components/NodesOfflineDialog.vue index 22ba4a60d..d492d54ca 100644 --- a/src/components/NodesOfflineDialog.vue +++ b/src/components/NodesOfflineDialog.vue @@ -96,6 +96,12 @@ export default { } } +.all-nodes-disabled-dialog { + &__btn-block { + padding-bottom: 16px; + } +} + .v-theme--dark { .nodes-offline-dialog { &__disclaimer { From e07d5a610d96f6fe263a0cc0950314fd1c5797ab Mon Sep 17 00:00:00 2001 From: Ivanov N Date: Tue, 22 Oct 2024 11:09:10 +0300 Subject: [PATCH 02/12] Support kly qr code --- src/components/SendFundsForm.vue | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/components/SendFundsForm.vue b/src/components/SendFundsForm.vue index 346d53533..bc5c0d721 100644 --- a/src/components/SendFundsForm.vue +++ b/src/components/SendFundsForm.vue @@ -227,6 +227,8 @@ import { isStringEqualCI } from '@/lib/textHelpers' import { formatSendTxError } from '@/lib/txVerify' import { AllCryptos } from '@/lib/constants/cryptos' +const KLAYR_PROTO = 'klayr' + /** * @returns {string | boolean} */ @@ -701,13 +703,16 @@ export default { */ onScanQrcode(uri) { const recipient = parseURIasAIP(uri) - + const { params } = recipient + const isKlayrWallet = this.currency === Cryptos.KLY && !recipient.crypto && recipient.protocol === KLAYR_PROTO this.cryptoAddress = '' - if (validateAddress(this.currency, recipient.address)) { - this.cryptoAddress = recipient.address - if (recipient.params.amount) { - const amount = formatNumber(this.exponent)(recipient.params.amount) - + let isValidAddress = false + if (isKlayrWallet) isValidAddress = validateAddress(this.currency, params.recipient) + else isValidAddress = validateAddress(this.currency, recipient.address) + if (isValidAddress) { + this.cryptoAddress = isKlayrWallet ? params.recipient : recipient.address + if (params.amount) { + const amount = formatNumber(this.exponent)(params.amount) if (Number(amount) <= this.maxToTransfer) { this.amountString = amount } From c7b2823df74c7f65e83e3d6f7f707d81ba8b3b7a Mon Sep 17 00:00:00 2001 From: Ivanov N Date: Wed, 23 Oct 2024 14:02:56 +0300 Subject: [PATCH 03/12] Fix: all-nodes-disabled-dialog css according to existed class name --- src/components/NodesOfflineDialog.vue | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/components/NodesOfflineDialog.vue b/src/components/NodesOfflineDialog.vue index d492d54ca..f4d324cb9 100644 --- a/src/components/NodesOfflineDialog.vue +++ b/src/components/NodesOfflineDialog.vue @@ -76,7 +76,7 @@ export default { @import 'vuetify/_settings.scss'; @import '@/assets/styles/settings/_colors.scss'; -.nodes-offline-dialog { +.all-nodes-disabled-dialog { &__card-text { padding: 16px !important; } @@ -91,19 +91,13 @@ export default { margin-right: 8px; } &__btn-block { - padding: 16px 0 32px 0; + padding: 16px 0 16px 0; text-align: center; } } -.all-nodes-disabled-dialog { - &__btn-block { - padding-bottom: 16px; - } -} - .v-theme--dark { - .nodes-offline-dialog { + .all-nodes-disabled-dialog { &__disclaimer { color: map-get($shades, 'white'); } From 841f010fa7182ee2e66a8d05ea5615750258a58a Mon Sep 17 00:00:00 2001 From: Ivanov N Date: Wed, 23 Oct 2024 16:04:36 +0300 Subject: [PATCH 04/12] Unified parseURI function --- src/components/SendFundsForm.vue | 20 ++++---- src/lib/uri.js | 78 ++++++++++++++++++++++++-------- 2 files changed, 68 insertions(+), 30 deletions(-) diff --git a/src/components/SendFundsForm.vue b/src/components/SendFundsForm.vue index bc5c0d721..ef954b69e 100644 --- a/src/components/SendFundsForm.vue +++ b/src/components/SendFundsForm.vue @@ -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' @@ -227,8 +227,6 @@ import { isStringEqualCI } from '@/lib/textHelpers' import { formatSendTxError } from '@/lib/txVerify' import { AllCryptos } from '@/lib/constants/cryptos' -const KLAYR_PROTO = 'klayr' - /** * @returns {string | boolean} */ @@ -673,7 +671,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() @@ -689,7 +687,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 @@ -702,15 +700,13 @@ export default { * @param {string} uri URI */ onScanQrcode(uri) { - const recipient = parseURIasAIP(uri) + if (this.cryptoAddress) this.cryptoAddress = '' + if (this.amountString) this.amountString = '' + const recipient = parseURI(uri) const { params } = recipient - const isKlayrWallet = this.currency === Cryptos.KLY && !recipient.crypto && recipient.protocol === KLAYR_PROTO - this.cryptoAddress = '' - let isValidAddress = false - if (isKlayrWallet) isValidAddress = validateAddress(this.currency, params.recipient) - else isValidAddress = validateAddress(this.currency, recipient.address) + const isValidAddress = validateAddress(this.currency, recipient.address) if (isValidAddress) { - this.cryptoAddress = isKlayrWallet ? params.recipient : recipient.address + this.cryptoAddress = recipient.address if (params.amount) { const amount = formatNumber(this.exponent)(params.amount) if (Number(amount) <= this.maxToTransfer) { diff --git a/src/lib/uri.js b/src/lib/uri.js index f1111218a..37c62fe2a 100644 --- a/src/lib/uri.js +++ b/src/lib/uri.js @@ -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 @@ -18,11 +20,64 @@ 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 + }, Object.create(null)) +} + +/** + * Parse info from an URI + * @param {string} uri URI. Default is address bar or argv[]. + * @returns { +* { +* address: string, +* crypto: string, +* params: Object, +* protocol: string +* } +* } + */ +export function parseURI(uri = getAddressBarURI()) { + const [origin, query = ''] = uri.split('?') + if (origin === KLAYR_WALLET) return parseKlyURI(origin, query) + else return parseURIasAIP(origin, query) +} + +/** + * Parse info from an URI of the Klayr wallet + * Sample: https://msg.adamant.im?address=U9821606738809290000&label=John+Doe&amount=1.12&message=Buy+a+beer + * { + * address: string, + * crypto: string, + * params: Object, + * protocol: string + * } + * } +*/ +function parseKlyURI(origin, query) { + let address = '' + let params = Object.create(null) + + if (query) { + params = formQueryParamsObject(query) + address = params.recipient || '' + } + + return { address, crypto: Cryptos.KLY, params, protocol: KLAYR_WALLET } +} + /** * 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[]. * @returns { * { * address: string, @@ -32,29 +87,16 @@ export function getAddressBarURI() { * } * } */ -export function parseURIasAIP(uri = getAddressBarURI()) { - const [origin, query = ''] = uri.split('?') +export function parseURIasAIP(origin, query) { let address = '' let crypto = '' 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)) { From 9d3f04a641ccd02d778d125975cf38e5a9806be2 Mon Sep 17 00:00:00 2001 From: Ivanov N Date: Wed, 23 Oct 2024 16:29:56 +0300 Subject: [PATCH 05/12] Small fixes --- src/lib/uri.js | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/lib/uri.js b/src/lib/uri.js index 37c62fe2a..08bc87a04 100644 --- a/src/lib/uri.js +++ b/src/lib/uri.js @@ -35,9 +35,9 @@ const formQueryParamsObject = (query) => { } /** - * Parse info from an URI - * @param {string} uri URI. Default is address bar or argv[]. - * @returns { +* Parse info from an URI +* @param {string} uri URI. Default is address bar or argv[]. +* @returns { * { * address: string, * crypto: string, @@ -45,25 +45,27 @@ const formQueryParamsObject = (query) => { * protocol: string * } * } - */ +*/ export function parseURI(uri = getAddressBarURI()) { const [origin, query = ''] = uri.split('?') - if (origin === KLAYR_WALLET) return parseKlyURI(origin, query) - else return parseURIasAIP(origin, query) + if (origin === KLAYR_WALLET) return parseKlyURI(query) + return parseURIasAIP(origin, query) } /** - * Parse info from an URI of the Klayr wallet - * Sample: https://msg.adamant.im?address=U9821606738809290000&label=John+Doe&amount=1.12&message=Buy+a+beer - * { - * address: string, - * crypto: string, - * params: Object, - * protocol: string - * } - * } +* 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, +* protocol: string +* } +* } */ -function parseKlyURI(origin, query) { +function parseKlyURI(query) { let address = '' let params = Object.create(null) @@ -78,6 +80,9 @@ function parseKlyURI(origin, query) { /** * 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's origin + * @param {string} URI's query parameters * @returns { * { * address: string, From 4b9dec0999014f7e3024b3ddf5d553e5819499a2 Mon Sep 17 00:00:00 2001 From: Ivanov N Date: Wed, 23 Oct 2024 16:39:37 +0300 Subject: [PATCH 06/12] Fix: parseURIasAIP() get returned default uri parameter --- src/lib/uri.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/uri.js b/src/lib/uri.js index 08bc87a04..732b8a0ba 100644 --- a/src/lib/uri.js +++ b/src/lib/uri.js @@ -49,7 +49,7 @@ const formQueryParamsObject = (query) => { export function parseURI(uri = getAddressBarURI()) { const [origin, query = ''] = uri.split('?') if (origin === KLAYR_WALLET) return parseKlyURI(query) - return parseURIasAIP(origin, query) + return parseURIasAIP(uri) } /** @@ -92,7 +92,8 @@ function parseKlyURI(query) { * } * } */ -export function parseURIasAIP(origin, query) { +export function parseURIasAIP(uri = getAddressBarURI()) { + const [origin, query = ''] = uri.split('?') let address = '' let crypto = '' let params = Object.create(null) From 7bac48c357b35f9fb7e27fa933aae78c20f93249 Mon Sep 17 00:00:00 2001 From: Ivanov N Date: Wed, 23 Oct 2024 18:59:00 +0300 Subject: [PATCH 07/12] fix: protocol name in parseKlyURI(); description parameters --- src/lib/uri.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib/uri.js b/src/lib/uri.js index 732b8a0ba..20c73e35c 100644 --- a/src/lib/uri.js +++ b/src/lib/uri.js @@ -74,15 +74,14 @@ function parseKlyURI(query) { address = params.recipient || '' } - return { address, crypto: Cryptos.KLY, params, protocol: KLAYR_WALLET } + return { address, crypto: Cryptos.KLY, params, protocol: Cryptos.KLY } } /** * 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's origin - * @param {string} URI's query parameters + * @param {string} URI * @returns { * { * address: string, From c7cd65cfe7f253f2760786a231f10c5a5a14378f Mon Sep 17 00:00:00 2001 From: Ivanov N Date: Thu, 24 Oct 2024 14:30:26 +0300 Subject: [PATCH 08/12] fix: small code fixes after review; klayr optional message --- src/components/SendFundsForm.vue | 11 +++++++---- src/lib/uri.js | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/SendFundsForm.vue b/src/components/SendFundsForm.vue index ef954b69e..4f235ec63 100644 --- a/src/components/SendFundsForm.vue +++ b/src/components/SendFundsForm.vue @@ -125,7 +125,7 @@ v-if="isTextDataAllowed" v-model="textData" class="a-input" - :label="textDataLabel" + :label="klayrOptionalMessage ? klayrOptionalMessage : textDataLabel" variant="underlined" counter maxlength="64" @@ -310,6 +310,7 @@ export default { increaseFee: false, showWarningOnPartnerAddressDialog: false, warningOnPartnerInfo: {}, + klayrOptionalMessage: '', // Account exists check // Currently works only with KLY @@ -700,19 +701,21 @@ export default { * @param {string} uri URI */ onScanQrcode(uri) { - if (this.cryptoAddress) this.cryptoAddress = '' - if (this.amountString) this.amountString = '' const recipient = parseURI(uri) const { params } = recipient const isValidAddress = validateAddress(this.currency, recipient.address) if (isValidAddress) { this.cryptoAddress = recipient.address - if (params.amount) { + if (params.amount && !this.amountString) { const amount = formatNumber(this.exponent)(params.amount) if (Number(amount) <= this.maxToTransfer) { this.amountString = amount } } + if (recipient.crypto === Cryptos.KLY) { + if (params.reference) this.klayrOptionalMessage = params.reference + else this.klayrOptionalMessage = '' + } } else { this.$emit('error', this.$t('transfer.error_incorrect_address', { crypto: this.currency })) } diff --git a/src/lib/uri.js b/src/lib/uri.js index 20c73e35c..4511acddd 100644 --- a/src/lib/uri.js +++ b/src/lib/uri.js @@ -31,7 +31,7 @@ const formQueryParamsObject = (query) => { ) } : accum - }, Object.create(null)) + }, {}) } /** @@ -67,7 +67,7 @@ export function parseURI(uri = getAddressBarURI()) { */ function parseKlyURI(query) { let address = '' - let params = Object.create(null) + let params = {} if (query) { params = formQueryParamsObject(query) From 1eebbd5c61f66b64738897e6230342831bbc54f7 Mon Sep 17 00:00:00 2001 From: Ivanov N Date: Thu, 24 Oct 2024 14:35:25 +0300 Subject: [PATCH 09/12] fix: protocol: Cryptos.KLY.toLowerCase() --- src/lib/uri.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/uri.js b/src/lib/uri.js index 4511acddd..a4ac31ef9 100644 --- a/src/lib/uri.js +++ b/src/lib/uri.js @@ -74,7 +74,7 @@ function parseKlyURI(query) { address = params.recipient || '' } - return { address, crypto: Cryptos.KLY, params, protocol: Cryptos.KLY } + return { address, crypto: Cryptos.KLY, params, protocol: Cryptos.KLY.toLowerCase() } } /** From 5c37665003830d07f5472763388d66a8b91cda65 Mon Sep 17 00:00:00 2001 From: Ivanov N Date: Thu, 24 Oct 2024 15:54:04 +0300 Subject: [PATCH 10/12] fix: textData model assignment; small code syntactical sugar changes --- src/components/SendFundsForm.vue | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/components/SendFundsForm.vue b/src/components/SendFundsForm.vue index 4f235ec63..fa5c9c466 100644 --- a/src/components/SendFundsForm.vue +++ b/src/components/SendFundsForm.vue @@ -125,7 +125,7 @@ v-if="isTextDataAllowed" v-model="textData" class="a-input" - :label="klayrOptionalMessage ? klayrOptionalMessage : textDataLabel" + :label="textDataLabel" variant="underlined" counter maxlength="64" @@ -702,19 +702,18 @@ export default { */ onScanQrcode(uri) { const recipient = parseURI(uri) - const { params } = recipient - const isValidAddress = validateAddress(this.currency, recipient.address) + const { params, address, crypto } = recipient + const isValidAddress = validateAddress(this.currency, address) if (isValidAddress) { - this.cryptoAddress = recipient.address + this.cryptoAddress = address if (params.amount && !this.amountString) { const amount = formatNumber(this.exponent)(params.amount) if (Number(amount) <= this.maxToTransfer) { this.amountString = amount } } - if (recipient.crypto === Cryptos.KLY) { - if (params.reference) this.klayrOptionalMessage = params.reference - else this.klayrOptionalMessage = '' + if (crypto === Cryptos.KLY) { + params.reference ? this.textData = params.reference : this.textData = '' } } else { this.$emit('error', this.$t('transfer.error_incorrect_address', { crypto: this.currency })) From 12e0fd180ae26c2ac3c4602a42dbeb2ed0c35424 Mon Sep 17 00:00:00 2001 From: Ivanov N Date: Thu, 24 Oct 2024 16:02:46 +0300 Subject: [PATCH 11/12] fix: more simplified ternary assignment --- src/components/SendFundsForm.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/SendFundsForm.vue b/src/components/SendFundsForm.vue index fa5c9c466..bd624e61e 100644 --- a/src/components/SendFundsForm.vue +++ b/src/components/SendFundsForm.vue @@ -713,7 +713,7 @@ export default { } } if (crypto === Cryptos.KLY) { - params.reference ? this.textData = params.reference : this.textData = '' + this.textData = params.reference ? params.reference : '' } } else { this.$emit('error', this.$t('transfer.error_incorrect_address', { crypto: this.currency })) From 01e07e9d87015c31c5db120eb1594e524ae88580 Mon Sep 17 00:00:00 2001 From: Ivanov N Date: Fri, 25 Oct 2024 10:26:52 +0300 Subject: [PATCH 12/12] fix: padding in styles --- src/components/NodesOfflineDialog.vue | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/NodesOfflineDialog.vue b/src/components/NodesOfflineDialog.vue index f4d324cb9..7dc6f00ca 100644 --- a/src/components/NodesOfflineDialog.vue +++ b/src/components/NodesOfflineDialog.vue @@ -77,8 +77,11 @@ export default { @import '@/assets/styles/settings/_colors.scss'; .all-nodes-disabled-dialog { + &__card-title { + padding: 14px !important; + } &__card-text { - padding: 16px !important; + padding: 14px !important; } &__disclaimer { margin-top: 10px;