From bf2dc906f0d27fc9d948f17ebc59f862aee0d894 Mon Sep 17 00:00:00 2001 From: Wapaca Date: Sat, 1 Jul 2023 13:48:46 +0200 Subject: [PATCH] Dump scatter, wombat support, removed unused lib + fix bug --- components/modals/Login.vue | 13 -- plugins/wallets/Proton.js | 96 ----------- plugins/wallets/Scatter.js | 130 --------------- plugins/wallets/limitlessSigner.js | 258 ----------------------------- store/chain.js | 7 +- 5 files changed, 3 insertions(+), 501 deletions(-) delete mode 100644 plugins/wallets/Proton.js delete mode 100644 plugins/wallets/Scatter.js delete mode 100644 plugins/wallets/limitlessSigner.js diff --git a/components/modals/Login.vue b/components/modals/Login.vue index ee446b1..42f4bdc 100644 --- a/components/modals/Login.vue +++ b/components/modals/Login.vue @@ -50,19 +50,6 @@ export default { name: 'Anchor', logo: require('@/static/logos/anchor.svg'), create: 'https://greymass.com/en/anchor/' - }, - { - id: 'scatter', - name: 'Scatter / TP / Starteos', - logo: require('@/static/logos/scatter.svg'), - create: - 'https://github.com/GetScatter/ScatterDesktop/releases/tag/11.0.1' - }, - { - id: 'scatter', - name: 'Wombat', - logo: require('@/static/logos/wombat.png'), - create: 'https://www.wombat.app/the-app' } ] diff --git a/plugins/wallets/Proton.js b/plugins/wallets/Proton.js deleted file mode 100644 index 844a619..0000000 --- a/plugins/wallets/Proton.js +++ /dev/null @@ -1,96 +0,0 @@ -const ConnectWallet = (...args) => import('@proton/web-sdk').then(({ default: fetch }) => fetch(...args)) - -class WalletBase { - network = null - - constructor(network, rpc) { - this.network = network - this.rpc = rpc - } - - logout() {} -} - -export default class AnchoWallet extends WalletBase { - link = null - session = null - - async checkLogin() { - const { link, session } = await ConnectWallet({ - linkOptions: { chainId: this.network.chainId, endpoints: Object.keys(this.network.client_nodes), restoreSession: true }, - transportOptions: { requestAccount: this.network.contract }, - selectorOptions: { - appName: 'Alcor', - appLogo: 'https://wax.alcor.exchange/android-chrome-192x192.svg' - } - }) - - if (session) { - this.link = link - this.session = session - this.link.rpc = this.rpc - - const { actor, permission } = session.auth - - return { - name: actor.toString(), - authorization: { actor: actor.toString(), permission: permission.toString() } - } - } else { - return null - } - } - - async login() { - const { link, session } = await ConnectWallet({ - linkOptions: { - endpoints: ['https://proton.greymass.com'] - }, - - transportOptions: { - requestAccount: this.network.contract, - requestStatus: true /* Optional: Display request success and error messages, Default true */ - }, - - selectorOptions: { - appName: 'Alcor', - appLogo: 'https://wax.alcor.exchange/android-chrome-192x192.svg', - customStyleOptions: { - modalBackgroundColor: '#F4F7FA', - logoBackgroundColor: 'white', - isLogoRound: true, - optionBackgroundColor: 'white', - optionFontColor: 'black', - primaryFontColor: 'black', - secondaryFontColor: '#6B727F', - linkColor: '#752EEB' - } - //walletType: 'proton' - } - }) - - if (session) { - this.link = link - this.session = session - this.link.rpc = this.rpc - - const { actor, permission } = session.auth - - return { - name: actor.toString(), - authorization: { actor: actor.toString(), permission: permission.toString() } - } - } else { - return null - } - } - - async logout() { - await this.link.removeSession('Alcor Exchange', this.session.auth) - this.session = undefined - } - - transact(actions) { - return this.session.transact({ actions }) - } -} diff --git a/plugins/wallets/Scatter.js b/plugins/wallets/Scatter.js deleted file mode 100644 index b547cfb..0000000 --- a/plugins/wallets/Scatter.js +++ /dev/null @@ -1,130 +0,0 @@ -import { JsonRpc, Api } from 'eosjs' - -import ScatterEOS from '@scatterjs/eosjs2' -import ScatterJS from '@scatterjs/core' -//import ScatterJS from 'scatterjs-core' -//import ScatterEOS from 'scatterjs-plugin-eosjs2' - -class WalletBase { - network = null - - constructor(network) { - this.network = network - } -} - -export default class WCWWallet extends WalletBase { - scatter_plugin = null - scatter_api = null - - getScatter = () => this.scatter_api || this.scatter_plugin - - accountPublickey = null - signatureProvider = null - - constructor(network, rpc) { - super(network) - this.rpc = rpc - - ScatterJS.plugins(new ScatterEOS()) - - if (typeof window !== 'undefined' || typeof document !== 'undefined') { - document.addEventListener('scatterLoaded', () => { - console.log('scatter connect in hook') - this.scatter_plugin = window.scatter - }) - } - - this.connect() - } - - async connect() { - const scatter = this.getScatter() - if (scatter && await scatter.isConnected()) return true - - const connected = await ScatterJS.scatter.connect('Alcor Exchange', { network: this.network }) - - if (connected) { - this.scatter_api = ScatterJS.scatter - return true - } else { - console.log('Cannot connect to Scatter...') - } - } - - async checkLogin() { - } - - async login() { - const scatter = this.getScatter() - try { - await scatter.checkLogin() - } catch (e) { - console.log('check login err', e) - } - - try { - // Useful for testnets to provide a convenient means for the end use to quickly add - // the required network configuration to their Scatter seamlessly while logging in. - await scatter.suggestNetwork({ ...this.network, blockchain: 'eos' }) - - const identity = await scatter.getIdentity({ - accounts: [{ ...this.network, blockchain: 'eos' }] - }) - - if (!identity) { - return Promise.reject('No identity obtained from Scatter') - } - - const account = - (identity && - identity.accounts && - identity.accounts.find((x) => x.blockchain === 'eos')) || undefined - - if (!account) { - return Promise.reject( - 'No account data obtained from Scatter identity' - ) - } - - this.accountPublickey = account.publicKey - - return { - name: account.name, - authorization: { actor: account.name, permission: account.authority } - } - } catch (error) { - console.log('[scatter]', error) - return Promise.reject(error) - } - } - - logout() { - const scatter = this.getScatter() - - try { - return scatter.logout() - } catch { - return scatter.forgetIdentity() - } - } - - transact(actions) { - const scatter = this.getScatter() - let eos - - if ('eosHook' in scatter) { - console.log('sing using eosHook...', scatter) - const network = ScatterJS.Network.fromJson({ ...this.network, blockchain: 'eos' }) - const rpc = new JsonRpc(network.fullhost()) - eos = ScatterJS.eos(network, Api, { rpc }) - } else { - console.log('sing using eos object (old way)...') - const jNetwork = ScatterJS.Network.fromJson({ ...this.network, blockchain: 'eos' }) - const rpc = new JsonRpc(jNetwork.fullhost()) - eos = scatter.eos(jNetwork, Api, { rpc }) - } - - return eos.transact({ actions }, { blocksBehind: 3, expireSeconds: 1200 }) - } -} diff --git a/plugins/wallets/limitlessSigner.js b/plugins/wallets/limitlessSigner.js deleted file mode 100644 index 994e391..0000000 --- a/plugins/wallets/limitlessSigner.js +++ /dev/null @@ -1,258 +0,0 @@ -import axios from 'axios' - -const LIMITLESS_WAX_ENDPOINT = 'https://api.limitlesswax.co/' - -// Used only for wax -export class LimitlessSigner { - constructor (network) { - if (network.name != 'wax') throw new Error('LimitlessSigner working only for WAX') - this.network = network - } - - async isAvailable() { - try { - const r = await axios.get(LIMITLESS_WAX_ENDPOINT) - console.log(r) - } catch { - - } - } -} - -//if (rootState.network.name == 'wax') { -// // Verify cosinging endpoint is online -// const original_actions = actions -// let response = {} -// try { -// response = await fetch(rootState.network.LIMITLESS_WAX_ENDPOINT, { -// method: 'GET', -// headers: { -// Accept: 'application/json', -// 'Content-Type': 'application/json' -// } -// }) -// } catch (e) { -// console.error(e) -// console.log(JSON.stringify(e)) -// response.status = 400 -// } - -// let enough_cpu = false -// try { -// const account_info = await fetch( -// rootState.network.hyperion + -// '/v2/state/get_account?limit=1&skip=0&account=limitlesswax', -// { -// method: 'GET', -// headers: { -// Accept: 'application/json', -// 'Content-Type': 'application/json' -// } -// } -// ) -// const account_info_json = await account_info.json() -// if (parseInt(account_info_json.account.cpu_limit.available) > 5000) { -// console.log('Enough cpu left') -// enough_cpu = true -// } else { -// console.log('Not enough cpu') -// enough_cpu = false -// } -// } catch (e) { -// console.error(e) -// console.log(JSON.stringify(e)) -// enough_cpu = false -// } - -// let cosignpayer = '' -// let index = 0 -// let enough_bank_wax = false -// let ms = 1 -// if (actions[0].data.to == 'alcorammswap') { -// cosignpayer = 'alcorammswap' -// index = 1 -// } -// if (actions[0].data.to == 'alcordexmain') { -// cosignpayer = 'alcordexmain' -// index = 0 -// ms = 2 -// } -// try { -// const bank_wax = this.$rpc.get_table_rows({ -// json: true, // Get the response as json -// code: 'limitlessbnk', // Contract that we target -// scope: 'limitlessbnk', // Account that owns the data -// table: 'waxdeposits', // Table name -// limit: 100, // Maximum number of rows that we want to get -// reverse: false, // Optional: Get reversed data -// show_payer: false // Optional: Show ram payer -// }) -// for (let i = 0; i < bank_wax.rows.length; i++) { -// if (bank_wax.rows[i].index == index) { -// if (parseFloat(bank_wax.rows[i].deposit) > 0.1) { -// enough_bank_wax = true -// } -// } -// } -// if (!enough_bank_wax) console.log('Not enough wax in bank') -// } catch (e) { -// console.log('Not enough wax in bank') -// console.log(JSON.stringify(e)) -// } -// // Cannot cosign for user -// if ( -// response.status != 200 || -// enough_cpu == false || -// enough_bank_wax == false -// ) { -// return await getters.wallet.transact({ -// max_cpu_usage_ms: 10, -// max_net_usage_words: 10000, -// actions -// }) -// } else { -// // Can cosign for user -// let cpu_cost = 0.02 -// try { -// const table = await this.$rpc.get_table_rows({ -// json: true, // Get the response as json -// code: 'limitlessbnk', // Contract that we target -// scope: 'limitlessbnk', // Account that owns the data -// table: 'config', // Table name -// limit: 1, // Maximum number of rows that we want to get -// reverse: false, // Optional: Get reversed data -// show_payer: false, // Optional: Show ram payer -// }) -// cpu_cost = parseFloat(table.rows[0].cost) -// } catch (e) { -// console.log(JSON.stringify(e)) -// console.log('Cant determine cost') -// } -// const cosign = { -// account: 'limitlesswax', -// name: 'paycpu', -// data: { -// user: rootState.user.name, -// info: ms + ' ms max, alcor', -// }, -// authorization: [ -// { -// actor: 'limitlesswax', -// permission: 'cosign', -// }, -// ], -// } -// const cosignpay = { -// account: 'limitlessbnk', -// name: 'sendwax', -// data: { -// table_index: index, -// owner: 'alcordexfund', -// ms, -// maincontract: cosignpayer, -// amount: (cpu_cost * ms).toFixed(8) + ' WAX', -// }, -// authorization: [ -// { -// actor: 'limitlesswax', -// permission: 'cosign', -// }, -// ], -// } - -// actions = [cosign, cosignpay, ...actions] -// if (state.currentWallet == 'anchor') { -// const transaction = await apiWAX.transact( -// { -// max_cpu_usage_ms: ms, -// max_net_usage_words: 1000 * ms, -// actions, -// }, -// { -// broadcast: false, -// sign: false, -// blocksBehind: 5, -// expireSeconds: 1200, -// } -// ) -// const deserializedTransaction = await apiWAX.deserializeTransaction( -// transaction.serializedTransaction -// ) -// const abis = await apiWAX.getTransactionAbis( -// deserializedTransaction -// ) -// const serializedContextFreeData = -// await apiWAX.serializeContextFreeData( -// deserializedTransaction.context_free_data -// ) - -// const chainId = rootState.network.chainId -// const requiredKeys = -// await getters.wallet.sessionProvider.getAvailableKeys() -// const serializedTransaction = transaction.serializedTransaction -// const signedTransaction = await getters.wallet.sign( -// deserializedTransaction -// ) - -// const request = { -// transaction: Array.from(serializedTransaction), -// } - -// const response = await fetch( -// rootState.network.LIMITLESS_WAX_ENDPOINT + 'cpu-rent', -// { -// method: 'POST', -// headers: { -// Accept: 'application/json', -// 'Content-Type': 'application/json', -// }, -// body: JSON.stringify(request), -// } -// ) - -// if (!response.ok) { -// const body = await response.json() -// throw new Error(body.reason || 'Failed to connect to endpoint') -// } - -// const json = await response.json() - -// if (!json.isOk) { -// throw new Error(json.reason) -// } - -// const sigs = [] -// if (json.signature) { -// sigs.push(json.signature[0]) -// sigs.push(signedTransaction.signatures[0]) -// } - -// const full_transaction = { -// signatures: sigs, -// compression: false, -// serializedContextFreeData, -// serializedTransaction, -// } - -// try { -// const completed_transaction = await apiWAX.rpc.send_transaction( -// full_transaction -// ) -// return completed_transaction -// } catch (e) { -// console.log(e) -// throw new Error(e) -// } -// } -// if (state.currentWallet == 'wcw') { -// return await getters.wallet.transact({ -// max_cpu_usage_ms: ms, -// max_net_usage_words: 1000 * ms, -// actions, -// }) -// } -// // not logged in with anchor or wcw -// return await getters.wallet.transact(original_actions) -// } -//} - diff --git a/store/chain.js b/store/chain.js index 8911b48..268e7be 100644 --- a/store/chain.js +++ b/store/chain.js @@ -1,6 +1,5 @@ import WCW from '~/plugins/wallets/WCW' import AnchoWallet from '~/plugins/wallets/Anchor' -import ScatterWallet from '~/plugins/wallets/Scatter' import {precise} from '~/utils/utils.js' export const state = () => ({ @@ -33,22 +32,22 @@ export const actions = { const wallets = { anchor: new AnchoWallet(network, this.$rpc), - scatter: new ScatterWallet(network, this.$rpc), wcw: new WCW(network, this.$rpc) } commit('setWallets', wallets) if (state.lastWallet) { + if(state.lastWallet === 'null') + commit('setLastWallet', 'anchor') + commit('setCurrentWallet', state.lastWallet) dispatch('autoLogin') } }, async autoLogin({ state, dispatch, commit, getters }) { - console.log('try autoLogin..') const loginned = await getters.wallet.checkLogin() - console.log(loginned) if (loginned) { const { name, authorization } = loginned commit('setUser', { name, authorization }, { root: true })