From da2ace5802f96efe882b31429e5340b01d0a75a3 Mon Sep 17 00:00:00 2001 From: Bob Jr Date: Tue, 28 Nov 2023 13:41:55 +0700 Subject: [PATCH] [wallet-integration] new wallets integration --- app/app.js | 147 ++++- app/components/Setting.vue | 207 +++--- app/walletAdapter.js | 94 +++ crawl.js | 73 ++- package-lock.json | 1260 ++++++++++++++++++++++++++---------- package.json | 2 +- 6 files changed, 1302 insertions(+), 481 deletions(-) create mode 100644 app/walletAdapter.js diff --git a/app/app.js b/app/app.js index 1a120fa8..541b2731 100644 --- a/app/app.js +++ b/app/app.js @@ -35,6 +35,7 @@ import * as HDKey from 'hdkey' import * as ethUtils from 'ethereumjs-util' import Meta from 'vue-meta' import Helper from './utils' +const { connectCoin98, connectMetamask, connectRamper, connectViction, WALLET_TYPE } = require('./walletAdapter.js') Vue.use(Meta) Vue.use(BootstrapVue) @@ -44,9 +45,9 @@ Vue.use(Toasted, { position: 'bottom-right', theme: 'bubble', duration: 4000, - action : { - text : 'Dismiss', - onClick : (e, toastObject) => { + action: { + text: 'Dismiss', + onClick: (e, toastObject) => { toastObject.goAway(0) } }, @@ -55,7 +56,7 @@ Vue.use(Toasted, { // set trezor's manifest TrezorConnect.manifest({ - email: 'admin@tomochain.com', + email: 'hi@viction.xyz', appUrl: 'https://vicmaster.xyz' }) @@ -81,23 +82,63 @@ Vue.prototype.setupProvider = async function (provider, wjs) { Vue.prototype.getAccount = async function () { const provider = Vue.prototype.NetworkProvider || '' const wjs = Vue.prototype.web3 + const config = await getConfig() + const supportedWalletOption = [{ + chainId: '0x' + parseInt(config.blockchain.networkId).toString(16), + chainName: 'Viction', + nativeCurrency: { + name: 'VIC', + symbol: 'VIC', + decimals: 18 + }, + rpcUrls: [config.blockchain.rpc] + }] + let account switch (provider) { - case 'metamask': - // Request account access if needed - for metamask - if (window.ethereum) { - // await window.ethereum.enable() - await window.ethereum.request({ method: 'eth_requestAccounts' }) + case WALLET_TYPE.COIN98: + account = await connectCoin98(supportedWalletOption) + break + case WALLET_TYPE.VICTION: + if (window.coin98) { + account = await connectCoin98(supportedWalletOption) + break } - account = (await wjs.eth.getAccounts())[0] + account = await connectViction(supportedWalletOption) + break + case WALLET_TYPE.RAMPER: + if (window.coin98) { + account = await connectCoin98(supportedWalletOption) + break + } + if (window.viction) { + account = await connectViction(supportedWalletOption) + break + } + account = await connectRamper(supportedWalletOption) break - // case 'pantograph': - // // Request account access if needed - for metamask - // if (window.tomochain) { - // await window.tomochain.enable() - // } - // account = (await wjs.eth.getAccounts())[0] - // break + case WALLET_TYPE.METAMASK: + if (window.coin98) { + account = await connectCoin98(supportedWalletOption) + break + } + if (window.viction) { + account = await connectViction(supportedWalletOption) + break + } + if (window.ramper2) { + account = await connectRamper(supportedWalletOption) + break + } + account = await connectMetamask(supportedWalletOption) + break + // case 'pantograph': + // // Request account access if needed - for metamask + // if (window.tomochain) { + // await window.tomochain.enable() + // } + // account = (await wjs.eth.getAccounts())[0] + // break case 'tomowalletDapp': account = (await wjs.eth.getAccounts())[0] break @@ -299,7 +340,7 @@ getConfig().then((config) => { localStorage.set('configMaster', config) Vue.use(VueAnalytics, { id: config.GA, - linkers: ['master.tomochain.com'], + linkers: ['vicmaster.xyz'], router, autoTraking: { screenView: true @@ -324,7 +365,55 @@ Vue.prototype.detectNetwork = async function (provider) { const chainConfig = config.blockchain if (!wjs) { switch (provider) { - case 'metamask': + case WALLET_TYPE.COIN98: + if (window.coin98) { + let p = window.coin98.provider + wjs = new Web3(p) + } + break + case WALLET_TYPE.VICTION: + if (window.coin98) { + let p = window.coin98.provider + wjs = new Web3(p) + break + } + if (window.viction) { + let p = window.viction + wjs = new Web3(p) + } + break + case WALLET_TYPE.RAMPER: + if (window.coin98) { + let p = window.coin98.provider + wjs = new Web3(p) + break + } + if (window.viction) { + let p = window.viction + wjs = new Web3(p) + break + } + if (window.ramper2) { + let p = window.ramper2.provider + wjs = new Web3(p) + } + break + case WALLET_TYPE.METAMASK: + if (window.coin98) { + let p = window.coin98.provider + wjs = new Web3(p) + break + } + if (window.viction) { + let p = window.viction + wjs = new Web3(p) + break + } + if (window.ramper2) { + let p = window.ramper2.provider + wjs = new Web3(p) + break + } if (window.ethereum) { let p = window.ethereum wjs = new Web3(p) @@ -340,16 +429,16 @@ Vue.prototype.detectNetwork = async function (provider) { } } break - // case 'pantograph': - // if (window.tomoWeb3) { - // if (window.tomoWeb3.currentProvider) { - // let pp = window.tomoWeb3.currentProvider - // wjs = new Web3(pp) - // } else { - // wjs = window.tomoWeb3 - // } - // } - // break + // case 'pantograph': + // if (window.tomoWeb3) { + // if (window.tomoWeb3.currentProvider) { + // let pp = window.tomoWeb3.currentProvider + // wjs = new Web3(pp) + // } else { + // wjs = window.tomoWeb3 + // } + // } + // break case 'tomowallet': wjs = new Web3(new HDWalletProvider( '', diff --git a/app/components/Setting.vue b/app/components/Setting.vue index a125213c..1a9f3011 100644 --- a/app/components/Setting.vue +++ b/app/components/Setting.vue @@ -15,7 +15,7 @@ @submit.prevent="validate()"> + + + @@ -30,17 +39,15 @@ value="tomowallet">TomoWallet (Recommended) --> - - - - Using node at {{ chainConfig.rpc }}. + class="form-text text-muted">Using node at {{ chainConfig.rpc }}. --> -
+

Please install & login Metamask Extension - then connect it to Viction Mainnet or Testnet.

+ then connect it to Viction Mainnet or Testnet. +

-
+

Please install & login Pantograph Extension - then connect it to Viction Mainnet or Testnet.

+ then connect it to Viction Mainnet or Testnet. +

{{ formatNumber(balance) }} - {{ getCurrencySymbol() }}

+ {{ getCurrencySymbol() }} +

Balance
@@ -258,7 +262,8 @@
-->

{{ w.cap }} - {{ getCurrencySymbol() }}

+ {{ getCurrencySymbol() }} +

Capacity