Skip to content

Commit

Permalink
Merge pull request #290 from thanhson1085/master
Browse files Browse the repository at this point in the history
removing support metamask in default
  • Loading branch information
thanhson1085 committed Nov 13, 2018
2 parents 44dc8e8 + 92f4382 commit 18290aa
Show file tree
Hide file tree
Showing 4 changed files with 3,519 additions and 3,505 deletions.
10 changes: 4 additions & 6 deletions app/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,15 @@ export default {
this.$router.push({ path: `/candidate/${s}` })
},
async checkNetworkAndLogin () {
try {
setTimeout(async () => {
setTimeout(async () => {
try {
const contract = await this.TomoValidator.deployed()
const account = await this.getAccount()
if (account && contract) {
this.isTomonet = true
}
}, 0)
} catch (error) {
console.log(error)
}
} catch (error) {}
}, 0)
}
}
}
Expand Down
24 changes: 15 additions & 9 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ Vue.use(HighchartsVue)
Vue.prototype.TomoValidator = contract(TomoValidatorArtifacts)
Vue.prototype.isElectron = !!(window && window.process && window.process.type)

if (window.web3) {
var web3js = new Web3(window.web3.currentProvider)
} else {
web3js = false
}

Vue.prototype.setupProvider = function (provider, wjs) {
Vue.prototype.NetworkProvider = provider
if (wjs instanceof Web3) {
Expand All @@ -67,6 +61,17 @@ Vue.prototype.setupProvider = function (provider, wjs) {
return reject(err)
}

if (provider === 'rpc') {
if (wjs.currentProvider.address) {
return resolve(wjs.currentProvider.address)
}

if (wjs.currentProvider.addresses) {
return resolve(wjs.currentProvider.addresses[0])
}
return resolve('')
}

if (accs.length === 0) {
console.log(`Couldn't get any accounts! Make sure
your Ethereum client is configured correctly.`)
Expand All @@ -81,9 +86,6 @@ Vue.prototype.setupProvider = function (provider, wjs) {
}
}

let provider = (Vue.prototype.isElectron) ? 'testnet' : 'metamask'
Vue.prototype.setupProvider(provider, web3js)

Vue.prototype.formatNumber = function (number) {
let seps = number.toString().split('.')
seps[0] = seps[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',')
Expand Down Expand Up @@ -190,6 +192,10 @@ const router = new VueRouter({
})

getConfig().then((config) => {
let provider = 'rpc'
var web3js = new Web3(new Web3.providers.HttpProvider(config.blockchain.rpc))
Vue.prototype.setupProvider(provider, web3js)

Vue.use(VueAnalytics, {
id: config.GA,
router,
Expand Down
38 changes: 21 additions & 17 deletions app/components/Setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
<b-form-select
id="provider"
v-model="provider">
<option value="rpc">PrivateKey/MNEMONIC</option>
<option
v-if="!isElectron"
value="metamask">Metamask</option>
<option value="testnet">Tomochain Testnet</option>
<option value="custom">Custom Network</option>
</b-form-select>
<small
v-if="provider === 'testnet'"
class="form-text text-muted">Using node at https://testnet.tomochain.com.</small>
v-if="provider === 'rpc'"
class="form-text text-muted">Using node at {{ chainConfig.rpc }}.</small>
</b-input-group>
</b-form-group>
<b-form-group
Expand All @@ -50,7 +49,7 @@
<b-form-group
v-if="provider !== 'metamask'"
class="mb-4"
label="MNEMONIC/PrivateKey"
label="Privatekey/MNEMONIC"
label-for="mnemonic">
<b-form-input
:class="getValidationClass('mnemonic')"
Expand Down Expand Up @@ -79,7 +78,8 @@
</b-card>
<b-card
v-if="isReady"
class="col-12 col-md-8 col-lg-7 tomo-card tomo-card--lighter p-0">
:class="'col-12 col-md-8 col-lg-7 tomo-card tomo-card--lighter p-0'
+ (loading ? ' tomo-loading' : '')">
<h4 class="h4 color-white tomo-card__title tomo-card__title--big">
Account Information</h4>
<ul class="tomo-list list-unstyled">
Expand Down Expand Up @@ -179,15 +179,16 @@ export default {
isReady: !!this.web3,
mnemonic: '',
config: {},
provider: 'metamask',
provider: 'rpc',
address: '',
withdraws: [],
wh: [],
aw: false,
balance: 0,
chainConfig: {},
networks: {
// mainnet: 'https://core.tomochain.com',
testnet: 'https://testnet.tomochain.com',
rpc: 'https://testnet.tomochain.com',
custom: 'http://localhost:8545'
},
loading: false
Expand All @@ -208,10 +209,11 @@ export default {
watch: {},
updated () {},
created: async function () {
this.provider = this.NetworkProvider
this.provider = this.NetworkProvider || 'rpc'
let self = this
self.config = await self.appConfig()
self.chainConfig = self.config.blockchain
self.chainConfig = self.config.blockchain || {}
self.networks.rpc = self.chainConfig.rpc
self.setupAccount = async () => {
let contract
Expand All @@ -227,6 +229,11 @@ export default {
}
let account = await self.getAccount()
if (!account) {
return false
}
self.address = account
self.account = account
self.web3.eth.getBalance(self.address, function (a, b) {
Expand Down Expand Up @@ -302,7 +309,7 @@ export default {
this.save()
}
},
save: function () {
save: async function () {
const self = this
var wjs = false
self.loading = true
Expand All @@ -321,12 +328,10 @@ export default {
wjs = new Web3(walletProvider)
}
self.setupProvider(this.provider, wjs)
await self.setupProvider(this.provider, wjs)
setTimeout(async () => {
self.loading = false
await self.setupAccount()
}, 2000)
await self.setupAccount()
self.loading = false
} catch (e) {
self.loading = false
self.$toasted.show('There are some errors when changing the network provider', {
Expand All @@ -341,7 +346,6 @@ export default {
let account = await self.getAccount()
self.loading = true
try {
console.log('==>', blockNumber, index)
let wd = await contract.withdraw(String(blockNumber), String(index), {
from: account,
gasPrice: 2500,
Expand Down
Loading

0 comments on commit 18290aa

Please sign in to comment.