Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": false,
"trailingComma" : "none",
"spaceBeforeFunctionParen": false,
"singleQuote": true
}
2 changes: 1 addition & 1 deletion apollo.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
6 changes: 5 additions & 1 deletion quasar.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/apollo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ 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<BootFileParams<any>>
) {
const httpLink = createHttpLink({
uri:
process.env.GRAPHQL_URI ||
// Change to your graphql endpoint.
'http://127.0.0.1:9696/graphql'
'https://yat.vit.ooo/graphql'
})

return <ApolloClientOptions<unknown>>Object.assign(
Expand Down
72 changes: 72 additions & 0 deletions src/boot/crypt.js
Original file line number Diff line number Diff line change
@@ -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
})
76 changes: 40 additions & 36 deletions src/boot/db.js
Original file line number Diff line number Diff line change
@@ -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
})
41 changes: 41 additions & 0 deletions src/boot/fetch.js
Original file line number Diff line number Diff line change
@@ -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
})
16 changes: 16 additions & 0 deletions src/boot/utils.js
Original file line number Diff line number Diff line change
@@ -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
})
Empty file added src/components/CopyButton.vue
Empty file.
36 changes: 0 additions & 36 deletions src/components/UserTxHistory.vue

This file was deleted.

30 changes: 12 additions & 18 deletions src/composables/useFetchData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -124,8 +118,8 @@ const useFetchData = () => {
getUserById,
getUserTransactions,
getTransactionById,
getAllTransactions,
allUserContacts,
getAllUserTransactions,
allUserContacts
}
}

Expand Down
Loading