├── .dockerignore ├── .editorconfig ├── .eslintrc.js ├── .gitignore ├── Dockerfile ├── README.md ├── assets ├── README.md ├── logo.svg ├── main.css └── tokens │ └── tkt_eossanguotkt.png ├── components ├── History.vue ├── NewOrderForm.vue ├── README.md ├── elements │ ├── ShortToken.vue │ └── TokenImage.vue └── errors │ └── NotFound.vue ├── config.js ├── layouts ├── README.md ├── default.vue └── error.vue ├── middleware └── README.md ├── nuxt.config.js ├── package.json ├── pages ├── README.md ├── index.vue └── order │ └── _id │ └── index.vue ├── plugins ├── README.md ├── element-ui.js ├── filters.js └── startapp.js ├── static ├── README.md ├── android-chrome-192x192.png ├── android-chrome-512x512.png ├── apple-touch-icon.png ├── browserconfig.xml ├── favicon-16x16.png ├── favicon-32x32.png ├── favicon.ico ├── mstile-144x144.png ├── mstile-150x150.png ├── mstile-310x150.png ├── mstile-310x310.png ├── mstile-70x70.png ├── safari-pinned-tab.svg ├── site.webmanifest └── telegram.png ├── store ├── chain.js └── index.js ├── utils └── index.js └── yarn.lock /.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug* 3 | .nuxt 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | browser: true, 5 | node: true 6 | }, 7 | parserOptions: { 8 | parser: 'babel-eslint' 9 | }, 10 | extends: [ 11 | 'plugin:vue/recommended', 12 | ], 13 | // required to lint *.vue files 14 | plugins: [ 15 | 'vue', 16 | ], 17 | // add your custom rules here 18 | rules: { 19 | 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', 20 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off' 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Node template 3 | # Logs 4 | logs 5 | *.log 6 | npm-debug.log* 7 | yarn-debug.log* 8 | yarn-error.log* 9 | 10 | # Runtime data 11 | pids 12 | *.pid 13 | *.seed 14 | *.pid.lock 15 | 16 | # Directory for instrumented libs generated by jscoverage/JSCover 17 | lib-cov 18 | 19 | # Coverage directory used by tools like istanbul 20 | coverage 21 | 22 | # nyc test coverage 23 | .nyc_output 24 | 25 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 26 | .grunt 27 | 28 | # Bower dependency directory (https://bower.io/) 29 | bower_components 30 | 31 | # node-waf configuration 32 | .lock-wscript 33 | 34 | # Compiled binary addons (https://nodejs.org/api/addons.html) 35 | build/Release 36 | 37 | # Dependency directories 38 | node_modules/ 39 | jspm_packages/ 40 | 41 | # TypeScript v1 declaration files 42 | typings/ 43 | 44 | # Optional npm cache directory 45 | .npm 46 | 47 | # Optional eslint cache 48 | .eslintcache 49 | 50 | # Optional REPL history 51 | .node_repl_history 52 | 53 | # Output of 'npm pack' 54 | *.tgz 55 | 56 | # Yarn Integrity file 57 | .yarn-integrity 58 | 59 | # dotenv environment variables file 60 | .env 61 | 62 | # parcel-bundler cache (https://parceljs.org/) 63 | .cache 64 | 65 | # next.js build output 66 | .next 67 | 68 | # nuxt.js build output 69 | .nuxt 70 | 71 | # Nuxt generate 72 | dist 73 | 74 | # vuepress build output 75 | .vuepress/dist 76 | 77 | # Serverless directories 78 | .serverless 79 | 80 | # IDE 81 | .idea 82 | 83 | .DS_Store 84 | .tern-port 85 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:12 2 | 3 | # create destination directory 4 | RUN mkdir /app 5 | WORKDIR /app 6 | 7 | # update and install dependency 8 | #RUN apk update && apk upgrade 9 | #RUN apk add git 10 | 11 | # copy the app, note .dockerignore 12 | COPY . /app/ 13 | RUN yarn install 14 | 15 | # build necessary, even if no static files are needed, 16 | # since it builds the server as well 17 | ENV NETWORK=eos 18 | RUN yarn build 19 | 20 | # expose 5000 on container 21 | EXPOSE 7000 22 | 23 | # set app serving to permissive / assigned 24 | ENV NUXT_HOST=0.0.0.0 25 | # set app port 26 | ENV NUXT_PORT=7000 27 | 28 | # start the app 29 | CMD [ "yarn", "start" ] 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## [EOSSWAP.IO](https://eosswap.io) 2 | > EOS trustless OTC trading 3 | 4 | ![EOSSWAP](https://a.imge.to/2019/07/09/TlwaR.png) 5 | 6 | With EOSSWAP you can exchange any EOS.IO tokens, for any other EOS.IO tokens, 7 | atomically, without the participation of third parties! The tokens should comply with the 8 | standard eosio.token of the contract. 9 | 10 | ## Build Setup 11 | 12 | ``` bash 13 | # install dependencies 14 | $ yarn install 15 | 16 | # serve with hot reload at localhost:3000 17 | $ NETWORK= yarn run dev 18 | 19 | # build for production and launch server 20 | $ NETWORK= yarn run build 21 | $ yarn start 22 | 23 | # generate static project 24 | $ yarn run generate 25 | ``` 26 | -------------------------------------------------------------------------------- /assets/README.md: -------------------------------------------------------------------------------- 1 | # ASSETS 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your un-compiled assets such as LESS, SASS, or JavaScript. 6 | 7 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/assets#webpacked). 8 | -------------------------------------------------------------------------------- /assets/logo.svg: -------------------------------------------------------------------------------- 1 | EOS SWAP HORIZONTAL 2 | -------------------------------------------------------------------------------- /assets/main.css: -------------------------------------------------------------------------------- 1 | button { 2 | outline: 0; 3 | } 4 | 5 | button:focus { 6 | outline: 0; 7 | outline: 0; 8 | } 9 | -------------------------------------------------------------------------------- /assets/tokens/tkt_eossanguotkt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avral/EOSSWAP/91debdb3424aaccd468c89ed64476ddaa4c66175/assets/tokens/tkt_eossanguotkt.png -------------------------------------------------------------------------------- /components/History.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | 105 | -------------------------------------------------------------------------------- /components/NewOrderForm.vue: -------------------------------------------------------------------------------- 1 | 63 | 64 | 232 | 233 | 245 | -------------------------------------------------------------------------------- /components/README.md: -------------------------------------------------------------------------------- 1 | # COMPONENTS 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | The components directory contains your Vue.js Components. 6 | 7 | _Nuxt.js doesn't supercharge these components._ 8 | -------------------------------------------------------------------------------- /components/elements/ShortToken.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 29 | -------------------------------------------------------------------------------- /components/elements/TokenImage.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 30 | -------------------------------------------------------------------------------- /components/errors/NotFound.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 23 | -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | const networks = { 2 | local: { 3 | name: 'local', 4 | contract: 'ordersbook', 5 | 6 | chainId: 'cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f', 7 | host: 'http://localhost:8888', 8 | port: 8888, 9 | protocol: 'http', 10 | monitor: 'https://jungle.eosx.io', 11 | lightapi: 'https://lightapi.eosgeneva.io', 12 | }, 13 | 14 | jungle: { 15 | name: 'jungle', 16 | contract: 'avralsjungle', 17 | 18 | chainId: 'e70aaab8997e1dfce58fbfac80cbbb8fecec7b99cf982a9444273cbc64c41473', 19 | host: 'https://api.jungle.alohaeos.com', 20 | port: 443, 21 | protocol: 'https', 22 | monitor: 'https://jungle.eosx.io', 23 | lightapi: 'https://lightapi.eosgeneva.io', 24 | }, 25 | 26 | eos: { 27 | name: 'eos', 28 | contract: 'wwweosswapio', 29 | 30 | chainId: 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906', 31 | 32 | host: 'https://api.main.alohaeos.com:443', 33 | port: 443, 34 | protocol: 'https', 35 | monitor: 'https://eosx.io', 36 | lightapi: 'https://api.light.xeos.me', 37 | } 38 | } 39 | 40 | 41 | export default networks[process.env.NETWORK] || networks.local 42 | -------------------------------------------------------------------------------- /layouts/README.md: -------------------------------------------------------------------------------- 1 | # LAYOUTS 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your Application Layouts. 6 | 7 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/views#layouts). 8 | -------------------------------------------------------------------------------- /layouts/default.vue: -------------------------------------------------------------------------------- 1 | 52 | 53 | 94 | 95 | 113 | -------------------------------------------------------------------------------- /layouts/error.vue: -------------------------------------------------------------------------------- 1 | 14 | 15 | 34 | -------------------------------------------------------------------------------- /middleware/README.md: -------------------------------------------------------------------------------- 1 | # MIDDLEWARE 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your application middleware. 6 | The middleware lets you define custom function to be ran before rendering a page or a group of pages (layouts). 7 | 8 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/routing#middleware). 9 | -------------------------------------------------------------------------------- /nuxt.config.js: -------------------------------------------------------------------------------- 1 | const pkg = require('./package') 2 | 3 | const isSPA = process.argv.includes('--spa') 4 | const isDev = process.env.npm_lifecycle_event == 'dev' 5 | 6 | 7 | const desc = 'With EOSSWAP you can exchange any EOS.IO tokens, for any other EOS.IO tokens, atomically, without the participation of third parties!' 8 | 9 | module.exports = { 10 | env: { 11 | isDev, 12 | NETWORK: process.env.NETWORK 13 | }, 14 | 15 | /* 16 | ** Headers of the page 17 | */ 18 | head: { 19 | title: 'EOSSWAP | EOSIO Trustless tokens swaps.', 20 | meta: [ 21 | { charset: 'utf-8' }, 22 | { name: 'viewport', content: 'width=device-width, initial-scale=1' }, 23 | { hid: 'description', name: 'description', content: desc }, 24 | { name: 'msapplication-TileColor', content: '#da532c' }, 25 | { name: 'theme-color', content: '#ffffff' }, 26 | ], 27 | 28 | link: [{ rel: 'apple-touch-icon', sizes: '180x180', href: '/apple-touch-icon.png' }], 29 | link: [{ rel: 'icon', type: "image/png", sizes: '32x32', href: '/favicon-32x32.png' }], 30 | link: [{ rel: 'icon', type: 'image/png', sizes: '16x16', href: '/favicon-16x16.png' }], 31 | link: [{ rel: 'manifest', href: '/site.webmanifest' }], 32 | link: [{ rel: 'mask-icon', color: '#5bbad5', href: '/safari-pinned-tab.svg' }], 33 | 34 | //link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }] 35 | }, 36 | 37 | /* 38 | ** Customize the progress-bar color 39 | */ 40 | loading: { color: '#fff' }, 41 | 42 | /* 43 | ** Global CSS 44 | */ 45 | css: [ 46 | 'element-ui/lib/theme-chalk/index.css', 47 | 'bootstrap-utilities/bootstrap-utilities.css', 48 | 'bootstrap/dist/css/bootstrap.min.css', 49 | '~/assets/main.css', 50 | 51 | ], 52 | 53 | /* 54 | ** Plugins to load before mounting the App 55 | */ 56 | plugins: [ 57 | '@/plugins/element-ui', 58 | '@/plugins/filters', 59 | 60 | {ssr: false, src: '~/plugins/startapp.js'}, 61 | ], 62 | 63 | /* 64 | ** Nuxt.js modules 65 | */ 66 | modules: [ 67 | // Doc: https://github.com/nuxt-community/axios-module#usage 68 | '@nuxtjs/axios', 69 | '@nuxtjs/sentry', 70 | 'vue-github-buttons/nuxt', 71 | ], 72 | /* 73 | ** Axios module configuration 74 | */ 75 | axios: { 76 | // See https://github.com/nuxt-community/axios-module#options 77 | }, 78 | 79 | /* 80 | ** Sentry module configuration 81 | */ 82 | sentry: { 83 | dsn: process.env.SENTRY_DSN || 'https://a2a78e2d93f6406ab3bea315676f5517@sentry.io/1411799', 84 | disabled: isDev 85 | }, 86 | 87 | /* 88 | ** Build configuration 89 | */ 90 | build: { 91 | /* 92 | ** You can extend webpack config here 93 | */ 94 | extend(config, ctx) { 95 | // Run ESLint on save 96 | if (ctx.isDev && ctx.isClient) { 97 | config.module.rules.push({ 98 | enforce: 'pre', 99 | test: /\.(js|vue)$/, 100 | loader: 'eslint-loader', 101 | exclude: /(node_modules)/ 102 | }) 103 | } 104 | 105 | if (isSPA) { 106 | config.output.publicPath = './_nuxt/' 107 | } 108 | } 109 | }, 110 | 111 | router: { 112 | mode: isSPA ? 'hash' : 'history', 113 | linkActiveClass: 'active', 114 | }, 115 | } 116 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "EOSSWAP-UI", 3 | "version": "1.0.0", 4 | "description": "Exchange for eosio tokens", 5 | "author": "avral", 6 | "private": true, 7 | "scripts": { 8 | "dev": "nuxt", 9 | "devmainnet": "nuxt --mainnet", 10 | "build": "nuxt build", 11 | "build-mainnet": "nuxt build --spa --mainnet", 12 | "start": "nuxt start", 13 | "generate": "nuxt generate", 14 | "lint": "eslint --fix --ext .js,.vue --ignore-path .gitignore .", 15 | "precommit": "npm run lint" 16 | }, 17 | "dependencies": { 18 | "@nuxtjs/axios": "^5.0.0", 19 | "@nuxtjs/sentry": "^2.3.1", 20 | "@scatterjs/core": "^2.7.44", 21 | "@scatterjs/eosjs2": "^1.5.26", 22 | "axios": "^0.19.0", 23 | "axios-cache-adapter": "^2.3.3", 24 | "bootstrap": "^4.3.1", 25 | "bootstrap-utilities": "^4.1.3", 26 | "cross-env": "^5.2.0", 27 | "element-ui": "^2.4.6", 28 | "eosjs": "20.0.0", 29 | "esm": "^3.2.25", 30 | "js-yaml": "^3.13.1", 31 | "node-fetch": "^2.6.0", 32 | "nuxt": "^2.0.0", 33 | "vue-github-buttons": "^3.1.0", 34 | "webpack-bundle-analyzer": "^3.3.2" 35 | }, 36 | "devDependencies": { 37 | "babel-eslint": "^8.2.1", 38 | "eslint": "^5.0.1", 39 | "eslint-loader": "^2.0.0", 40 | "eslint-plugin-html": "^5.0.0", 41 | "eslint-plugin-vue": "^4.0.0", 42 | "nodemon": "^1.11.0", 43 | "pug": "^2.0.3", 44 | "pug-plain-loader": "^1.0.0" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /pages/README.md: -------------------------------------------------------------------------------- 1 | # PAGES 2 | 3 | This directory contains your Application Views and Routes. 4 | The framework reads all the `*.vue` files inside this directory and create the router of your application. 5 | 6 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/routing). 7 | -------------------------------------------------------------------------------- /pages/index.vue: -------------------------------------------------------------------------------- 1 | 117 | 118 | 328 | 329 | 330 | 331 | 340 | -------------------------------------------------------------------------------- /pages/order/_id/index.vue: -------------------------------------------------------------------------------- 1 | 45 | 46 | 47 | 188 | 189 | 194 | -------------------------------------------------------------------------------- /plugins/README.md: -------------------------------------------------------------------------------- 1 | # PLUGINS 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your Javascript plugins that you want to run before mounting the root Vue.js application. 6 | 7 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/plugins). 8 | -------------------------------------------------------------------------------- /plugins/element-ui.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Element from 'element-ui/lib/element-ui.common' 3 | import locale from 'element-ui/lib/locale/lang/en' 4 | 5 | export default () => { 6 | Vue.use(Element, { locale }) 7 | } 8 | -------------------------------------------------------------------------------- /plugins/filters.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | 3 | import config from '~/config' 4 | 5 | Vue.filter('monitorAccount', function (account) { 6 | return `${config.monitor}/account/${account}` 7 | }) 8 | 9 | 10 | Vue.prototype.$tokenLogo = function(symbol, contract) { 11 | if (symbol == 'PIXEOS' && contract == 'pixeos1token') 12 | return 'https://pixeos.io/ico/apple-touch-icon-57-precomposed.png' 13 | 14 | if (symbol == 'TKT' && contract == 'eossanguotkt') 15 | return require('@/assets/tokens/tkt_eossanguotkt.png') 16 | 17 | return `https://raw.githubusercontent.com/BlockABC/eos-tokens/master/tokens/${contract}/${symbol}.png` 18 | } 19 | -------------------------------------------------------------------------------- /plugins/startapp.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | 3 | export default ({app: { store }}) => { 4 | window.onNuxtReady(() => { 5 | store.dispatch('chain/init') 6 | }) 7 | } 8 | -------------------------------------------------------------------------------- /static/README.md: -------------------------------------------------------------------------------- 1 | # STATIC 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your static files. 6 | Each file inside this directory is mapped to `/`. 7 | 8 | Example: `/static/robots.txt` is mapped as `/robots.txt`. 9 | 10 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/assets#static). 11 | -------------------------------------------------------------------------------- /static/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avral/EOSSWAP/91debdb3424aaccd468c89ed64476ddaa4c66175/static/android-chrome-192x192.png -------------------------------------------------------------------------------- /static/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avral/EOSSWAP/91debdb3424aaccd468c89ed64476ddaa4c66175/static/android-chrome-512x512.png -------------------------------------------------------------------------------- /static/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avral/EOSSWAP/91debdb3424aaccd468c89ed64476ddaa4c66175/static/apple-touch-icon.png -------------------------------------------------------------------------------- /static/browserconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | #da532c 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /static/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avral/EOSSWAP/91debdb3424aaccd468c89ed64476ddaa4c66175/static/favicon-16x16.png -------------------------------------------------------------------------------- /static/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avral/EOSSWAP/91debdb3424aaccd468c89ed64476ddaa4c66175/static/favicon-32x32.png -------------------------------------------------------------------------------- /static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avral/EOSSWAP/91debdb3424aaccd468c89ed64476ddaa4c66175/static/favicon.ico -------------------------------------------------------------------------------- /static/mstile-144x144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avral/EOSSWAP/91debdb3424aaccd468c89ed64476ddaa4c66175/static/mstile-144x144.png -------------------------------------------------------------------------------- /static/mstile-150x150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avral/EOSSWAP/91debdb3424aaccd468c89ed64476ddaa4c66175/static/mstile-150x150.png -------------------------------------------------------------------------------- /static/mstile-310x150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avral/EOSSWAP/91debdb3424aaccd468c89ed64476ddaa4c66175/static/mstile-310x150.png -------------------------------------------------------------------------------- /static/mstile-310x310.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avral/EOSSWAP/91debdb3424aaccd468c89ed64476ddaa4c66175/static/mstile-310x310.png -------------------------------------------------------------------------------- /static/mstile-70x70.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avral/EOSSWAP/91debdb3424aaccd468c89ed64476ddaa4c66175/static/mstile-70x70.png -------------------------------------------------------------------------------- /static/safari-pinned-tab.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | Created by potrace 1.11, written by Peter Selinger 2001-2013 9 | 10 | 12 | 57 | 61 | 66 | 69 | 75 | 80 | 88 | 92 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /static/site.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "short_name": "", 4 | "icons": [ 5 | { 6 | "src": "/android-chrome-192x192.png", 7 | "sizes": "192x192", 8 | "type": "image/png" 9 | }, 10 | { 11 | "src": "/android-chrome-512x512.png", 12 | "sizes": "512x512", 13 | "type": "image/png" 14 | } 15 | ], 16 | "theme_color": "#ffffff", 17 | "background_color": "#ffffff", 18 | "display": "standalone" 19 | } 20 | -------------------------------------------------------------------------------- /static/telegram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avral/EOSSWAP/91debdb3424aaccd468c89ed64476ddaa4c66175/static/telegram.png -------------------------------------------------------------------------------- /store/chain.js: -------------------------------------------------------------------------------- 1 | import config from '~/config' 2 | 3 | import fetch from 'node-fetch' 4 | import { configureScope } from '@sentry/browser' 5 | 6 | import ScatterJS from '@scatterjs/core'; 7 | import ScatterEOS from '@scatterjs/eosjs2'; 8 | import { Api, JsonRpc } from 'eosjs' 9 | 10 | ScatterJS.plugins(new ScatterEOS()) 11 | 12 | export const network = ScatterJS.Network.fromJson({ 13 | blockchain: 'eos', 14 | ...config 15 | }); 16 | 17 | const rpc = new JsonRpc(config.host, { fetch }); 18 | const eos = ScatterJS.eos(network, Api, {rpc, beta3:true}) 19 | 20 | 21 | export const state = () => ({ 22 | scatterConnected: true, 23 | oldScatter: false 24 | }) 25 | 26 | export const actions = { 27 | async init({ state, commit, dispatch }) { 28 | console.log('App starting..') 29 | 30 | await ScatterJS.connect('EOSSWAP', { network }).then(v => commit('setScatterConnected', v)) 31 | 32 | if (state.scatterConnected) { 33 | let scatter_version 34 | 35 | try { 36 | scatter_version = await ScatterJS.scatter.getVersion() 37 | 38 | // Automatic login 39 | dispatch('login') 40 | } catch(e) { 41 | commit('setOldScatter', true) 42 | scatter_version = 'Scatter as browser extention (Unmainteined)' 43 | } finally { 44 | configureScope((scope) => scope.setTag("scatter.version", scatter_version)) 45 | } 46 | } 47 | }, 48 | 49 | async logout({ commit }) { 50 | await ScatterJS.logout() 51 | commit('setUser', null, { root: true }) 52 | }, 53 | 54 | async login({ state, commit, dispatch }) { 55 | if (!state.scatterConnected) 56 | return this._vm.$notify({ title: 'Login', message: 'Scatter is not connected', type: 'error' }) 57 | 58 | try { 59 | let r = await ScatterJS.login() 60 | 61 | configureScope((scope) => scope.setUser({"username": r.accounts[0].name})) 62 | commit('setUser', r.accounts[0], { root: true }) 63 | dispatch('loadUserBalances', {}, { root: true }) 64 | } catch(e) { 65 | this._vm.$notify({ title: 'Login', message: e.message, type: 'error' }) 66 | } 67 | }, 68 | 69 | async scatterConnect({ commit }) { 70 | commit('setScatterConnected', await ScatterJS.connect('Ordersbook', { network })) 71 | }, 72 | 73 | getOrders() { 74 | return rpc.get_table_rows({code: config.contract, scope: config.contract, table: 'orders'}) 75 | } 76 | } 77 | 78 | export const mutations = { 79 | setUser: (state, user) => state.user = user, 80 | setScatterConnected: (state, value) => state.scatterConnected = value, 81 | setOldScatter: (state, value) => state.oldScatter = value, 82 | } 83 | 84 | export const getters = { 85 | rpc: state => rpc, 86 | eos: state => eos, 87 | scatter: state => ScatterJS.scatter 88 | } 89 | 90 | export function transfer(contract, actor, quantity, memo) { 91 | return eos.transact({ 92 | actions: [{ 93 | account: contract, 94 | name: 'transfer', 95 | authorization: [{ 96 | actor: actor, 97 | permission: 'active', 98 | }], 99 | data: { 100 | from: actor, 101 | to: config.contract, 102 | quantity, 103 | memo, 104 | }, 105 | }] 106 | }, { blocksBehind: 3, expireSeconds: 3 * 60 } 107 | ) 108 | } 109 | 110 | export function cancelorder(maker, order_id) { 111 | return eos.transact({ 112 | actions: [{ 113 | account: config.contract, 114 | name: 'cancelorder', 115 | authorization: [{ 116 | actor: maker, 117 | permission: 'active', 118 | }], 119 | data: { maker, order_id }, }] 120 | }, { blocksBehind: 3, expireSeconds: 3 * 60 } 121 | ) 122 | } 123 | 124 | 125 | // FIXME Patch JsonRpc https://github.com/EOSIO/eosjs/issues/324 not redy for production 126 | rpc.get_table_rows = async function({ 127 | json = true, 128 | code, 129 | scope, 130 | table, 131 | table_key = "", 132 | lower_bound = "", 133 | upper_bound = "", 134 | index_position = 1, 135 | key_type = "", 136 | limit = 10, 137 | reverse = false, 138 | show_payer = false, 139 | }) { 140 | return await this.fetch( 141 | "/v1/chain/get_table_rows", { 142 | json, 143 | code, 144 | scope, 145 | table, 146 | table_key, 147 | lower_bound, 148 | upper_bound, 149 | index_position, 150 | key_type, 151 | limit, 152 | reverse, 153 | show_payer, 154 | }); 155 | } 156 | -------------------------------------------------------------------------------- /store/index.js: -------------------------------------------------------------------------------- 1 | import config from '~/config' 2 | import axios from 'axios' 3 | 4 | 5 | export const state = () => ({ 6 | user: null 7 | }) 8 | 9 | export const mutations = { 10 | setUser: (state, user) => state.user = user 11 | } 12 | 13 | 14 | export const actions = { 15 | loadUserBalances({ rootState, state, commit }) { 16 | if (state.user) { 17 | // TODO Вынести этот эндпоинт в конфиг 18 | axios.get(`${config.lightapi}/api/account/${config.name}/${rootState.user.name}`).then(r => { 19 | let balances = r.data.balances 20 | balances.sort((a, b) => { 21 | if(a.currency < b.currency) { return -1; } 22 | if(a.currency > b.currency) { return 1; } 23 | 24 | return 0; 25 | }) 26 | 27 | balances.map(b => b.id = b.currency + '@' + b.contract) 28 | 29 | commit('setUser', { ...state.user, balances }, { root: true }) 30 | }) 31 | } 32 | } 33 | } 34 | 35 | 36 | export const getters = { 37 | user(state) { 38 | return state.user 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /utils/index.js: -------------------------------------------------------------------------------- 1 | export function calculatePrice(sell, buy) { 2 | let first = parseAsset(buy) 3 | let second = parseAsset(sell) 4 | 5 | if (second.symbol == 'EOS' && sell.contract == 'eosio.token') 6 | // EOS main token as main in price 7 | [first, second] = [second, first] 8 | 9 | 10 | let price = (first.amount / second.amount).toFixed(8) 11 | 12 | return `${price} ${first.symbol}` 13 | } 14 | 15 | export function parseAsset(asset) { 16 | if (asset.hasOwnProperty('symbol')) return asset 17 | 18 | let paths = asset.quantity.split(' ') 19 | return { 20 | symbol: paths[1], 21 | contract: asset.contract, 22 | amount: parseFloat(paths[0]), 23 | 24 | get str() { 25 | return `${this.symbol}@${this.contract}` 26 | }, 27 | 28 | get quantity () { 29 | // TODO Precision 30 | return this.amount.toFixed(4) + ' ' + this.symbol 31 | } 32 | } 33 | } 34 | --------------------------------------------------------------------------------