diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..da400d0 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "semi": false, + "trailingComma" : "none", + "spaceBeforeFunctionParen": false, + "singleQuote": true +} diff --git a/apollo.config.js b/apollo.config.js index e94457b..5ffdca3 100644 --- a/apollo.config.js +++ b/apollo.config.js @@ -6,7 +6,7 @@ module.exports = { client: { service: { name: 'my-service', - url: 'http://127.0.0.1:9696/graphql' + url: 'https://yat.vit.ooo/graphql' }, // Files processed by the extension includes: ['src/**/*.vue', 'src/**/*.js', 'src/**/*.ts'] diff --git a/quasar.config.js b/quasar.config.js index 4e9b6d2..49f406e 100644 --- a/quasar.config.js +++ b/quasar.config.js @@ -31,7 +31,11 @@ module.exports = configure(function (/* ctx */) { // https://v2.quasar.dev/quasar-cli/boot-files boot: [ 'i18n', - 'apollo' + 'apollo', + 'db', + 'crypt', + 'utils', + 'fetch' ], // https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#css diff --git a/src/apollo/index.ts b/src/apollo/index.ts index c3bd0b1..92a6087 100644 --- a/src/apollo/index.ts +++ b/src/apollo/index.ts @@ -4,7 +4,7 @@ import type { BootFileParams } from '@quasar/app-vite' // https://github.com/quasarframework/app-extension-apollo -export /* async */ function getClientOptions ( +export /* async */ function getClientOptions( // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any /* {app, router, ...} */ options?: Partial> ) { @@ -12,7 +12,7 @@ export /* async */ function getClientOptions ( uri: process.env.GRAPHQL_URI || // Change to your graphql endpoint. - 'http://127.0.0.1:9696/graphql' + 'https://yat.vit.ooo/graphql' }) return >Object.assign( diff --git a/src/boot/crypt.js b/src/boot/crypt.js new file mode 100644 index 0000000..77e7fd5 --- /dev/null +++ b/src/boot/crypt.js @@ -0,0 +1,72 @@ +import { boot } from 'quasar/wrappers' +import { sign, randomBytes } from 'tweetnacl' + +export default boot(({ app }) => { + const crypt = { + + b2h (b) { + return Array.prototype.map.call(b, function (byte) { + return ('0' + (byte & 0xFF).toString(16)).slice(-2) + }).join('') + }, + + h2b (h) { + if (typeof h !== 'string') throw new TypeError('expected string') + const b = new Uint8Array(h.length / 2) + let i = 0 + while (h.length >= 2) { + b[i] = parseInt(h.substring(0, 2), 16) + h = h.substring(2, h.length) + i++ + } + return b + }, + + u2b (s) { + if (typeof s !== 'string') throw new TypeError('expected string') + const d = unescape(encodeURIComponent(s)), b = new Uint8Array(d.length) + for (let i = 0; i < d.length; i++) b[i] = d.charCodeAt(i) + return b + }, + + b2u (b) { + const s = [] + for (let i = 0; i < b.length; i++) s.push(String.fromCharCode(b[i])) + return decodeURIComponent(escape(s.join(''))) + }, + + async genKey () { + return this.b2h(randomBytes(32)) + }, + + async recKey (s) { + let k = '' + if (s.length > 64) { + k = sign.keyPair.fromSecretKey(this.h2b(s)) // legacy + } else { + k = sign.keyPair.fromSeed(this.h2b(s)) + } + const sec = k.secretKey // PRIVATE KEY + const pub = k.publicKey // PUBLIC KEY + return [this.b2h(sec), this.b2h(pub)] + }, + + // mes, sec + sign (m, s) { + return this.b2h(sign(this.u2b(m), this.h2b(s))) + }, + + // mes, pub + unsign (m, p) { + const o = sign.open(this.h2b(m), this.h2b(p)) + + if (o) { + return this.b2u(o) + } else { + return false + } + } + } + + app.config.globalProperties.$crypt = crypt +}) diff --git a/src/boot/db.js b/src/boot/db.js index e55866d..aa32f75 100644 --- a/src/boot/db.js +++ b/src/boot/db.js @@ -1,41 +1,45 @@ +import { boot } from 'quasar/wrappers' import { openDB } from 'idb' -const _db = openDB('yat', 1, { - upgrade (db) { - db.createObjectStore('settings') - const contacts = db.createObjectStore('contacts', { - keyPath: 'id', - autoIncrement: true - }) - contacts.createIndex('name', 'name') - } -}) +export default boot(({ app }) => { + const _db = openDB('yat', 1, { + // eslint-disable-next-line space-before-function-paren + upgrade (db) { + db.createObjectStore('settings') + const contacts = db.createObjectStore('contacts', { + keyPath: 'id', + autoIncrement: true + }) + contacts.createIndex('name', 'name') + } + }) -const db = { - async get (store, key) { - return (await _db).get(store, key) - }, - async set (store, key, val) { - return (await _db).put(store, val, key) - }, - async delete (store, key) { - return (await _db).delete(store, key) - }, - async clear (store) { - return (await _db).clear(store) - }, - async keys (store) { - return (await _db).getAllKeys(store) - }, - async addContact (name, addr) { - return (await _db).add('contacts', { - name, - addr - }) - }, - async getContacts () { - return (await _db).getAllFromIndex('contacts', 'name') + const db = { + async get (store, key) { + return (await _db).get(store, key) + }, + async set (store, key, val) { + return (await _db).put(store, val, key) + }, + async delete (store, key) { + return (await _db).delete(store, key) + }, + async clear (store) { + return (await _db).clear(store) + }, + async keys (store) { + return (await _db).getAllKeys(store) + }, + async addContact (name, addr) { + return (await _db).add('contacts', { + name, + addr + }) + }, + async getContacts () { + return (await _db).getAllFromIndex('contacts', 'name') + } } -} -export default db + app.config.globalProperties.$db = db +}) diff --git a/src/boot/fetch.js b/src/boot/fetch.js new file mode 100644 index 0000000..ffebcdf --- /dev/null +++ b/src/boot/fetch.js @@ -0,0 +1,41 @@ +import { boot } from 'quasar/wrappers' +import ky from 'ky' + +export default boot(({ app }) => { + const srv = import.meta.env.VITE_REST_SERVER + + const fetch = { + async balance (url) { + const res = await fetch(url) + const b = await res.json() + let s = 10 + if (b > 99999) { + s = 7 + } + if (b > 9999999) { + s = 6 + } + if (b > 999999999) { + s = 5 + } + return [b.toLocaleString(), s] + }, + async send (q) { + try { + const res = await fetch(srv + "send/", { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(q) + }) + return await res.json() + } catch (e) { + console.error(e) + return { success: 0 } + } + } + } + + app.config.globalProperties.$fetch = fetch +}) diff --git a/src/boot/utils.js b/src/boot/utils.js new file mode 100644 index 0000000..dadc058 --- /dev/null +++ b/src/boot/utils.js @@ -0,0 +1,16 @@ +import { boot } from 'quasar/wrappers' + +export default boot(({ app }) => { + const utils = { + randomInt (min, max) { + min = Math.ceil(min) + max = Math.floor(max) + return Math.floor(Math.random() * (max - min)) + min + }, + copy (txt) { + console.log(txt) + } + } + + app.config.globalProperties.$utils = utils +}) diff --git a/src/components/CopyButton.vue b/src/components/CopyButton.vue new file mode 100644 index 0000000..e69de29 diff --git a/src/components/UserTxHistory.vue b/src/components/UserTxHistory.vue deleted file mode 100644 index 1745d99..0000000 --- a/src/components/UserTxHistory.vue +++ /dev/null @@ -1,36 +0,0 @@ - - - diff --git a/src/composables/useFetchData.ts b/src/composables/useFetchData.ts index aee69f8..a3adc0d 100644 --- a/src/composables/useFetchData.ts +++ b/src/composables/useFetchData.ts @@ -34,27 +34,21 @@ const useFetchData = () => { return useQuery(getDataQuery, { id }) } - const getAllTransactions = (userId: number) => { + const getAllUserTransactions = () => { const getDataQuery = gql` - query getTransactions($userId: ID!) { - allTransactions(userId: $userId) { - id - amount + query MyQuery { + getAllTx { + credit debit - message - sender { - id - name - } - recipient { - id - name - } - created_at + amount + sign + hash + msg + time } } ` - return useQuery(getDataQuery, { userId }) + return useQuery(getDataQuery) } const getTransactionById = (id: number) => { @@ -124,8 +118,8 @@ const useFetchData = () => { getUserById, getUserTransactions, getTransactionById, - getAllTransactions, - allUserContacts, + getAllUserTransactions, + allUserContacts } } diff --git a/src/pages/user/UserProfile.vue b/src/pages/user/UserProfile.vue index 955fcc2..0c71be2 100644 --- a/src/pages/user/UserProfile.vue +++ b/src/pages/user/UserProfile.vue @@ -1,13 +1,116 @@ + + + + diff --git a/src/pages/user/UserTx.vue b/src/pages/user/UserTx.vue index e5d3e3b..1ade4f3 100644 --- a/src/pages/user/UserTx.vue +++ b/src/pages/user/UserTx.vue @@ -1,105 +1,45 @@ -