Skip to content

Commit

Permalink
Merge pull request #689 from pqv199x/twitter
Browse files Browse the repository at this point in the history
Fix storing account issue
  • Loading branch information
thanhson1085 committed Aug 6, 2019
2 parents 1b97c0e + 3a94fff commit ae7c3f9
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 88 deletions.
10 changes: 3 additions & 7 deletions app/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,8 @@ export default {
try {
let contract// = await self.getTomoValidatorInstance()
contract = self.TomoValidator
if (store.get('address')) {
self.account = store.get('address').toLowerCase()
} else {
self.account = this.$store.state.walletLoggedIn
? this.$store.state.walletLoggedIn : await self.getAccount()
}
self.account = store.get('address') ||
self.$store.state.address || await self.getAccount()
if (self.account && contract) {
self.isTomonet = true
}
Expand All @@ -471,7 +467,7 @@ export default {
},
signOut () {
store.clearAll()
this.$store.state.walletLoggedIn = null
this.$store.state.address = null
this.$router.go({
path: '/'
Expand Down
4 changes: 2 additions & 2 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Vue.prototype.setupProvider = async function (provider, wjs) {
your Ethereum client is configured correctly.`))
} else { return resolve(accs[0]) }
case 'tomowallet':
return resolve(self.$store.state.walletLoggedIn)
return resolve(self.$store.state.address)
case 'custom':
const provider = wjs.currentProvider.connection || wjs.currentProvider
if (provider.address) {
Expand Down Expand Up @@ -399,7 +399,7 @@ Vue.use(Vuex)

const store = new Vuex.Store({
state: {
walletLoggedIn: null
address: null
}
})
Vue.prototype.detectNetwork = async function (provider) {
Expand Down
22 changes: 10 additions & 12 deletions app/components/Setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ export default {
if (store.get('address') && self.isReady) {
account = store.get('address').toLowerCase()
} else {
account = this.$store.state.walletLoggedIn
? this.$store.state.walletLoggedIn : (self.web3 ? await self.getAccount() : false)
account = this.$store.state.address
? this.$store.state.address : (self.web3 ? await self.getAccount() : false)
}
if (!account) {
Expand Down Expand Up @@ -597,7 +597,7 @@ export default {
store.clearAll()
const self = this
self.address = ''
self.$store.state.walletLoggedIn = null
self.$store.state.address = null
// clear old data
self.withdraws = []
self.aw = []
Expand Down Expand Up @@ -634,28 +634,26 @@ export default {
store.set('offset', offset)
break
default:
console.log(self.hdPath)
self.mnemonic = self.mnemonic.trim()
const walletProvider =
(self.mnemonic.indexOf(' ') >= 0)
? new HDWalletProvider(
self.mnemonic.trim(),
self.chainConfig.rpc, 0, 1, self.hdPath)
: new PrivateKeyProvider(self.mnemonic, self.chainConfig.rpc)
wjs = new Web3(walletProvider)
console.log(wjs)
break
}
await self.setupProvider(this.provider, wjs)
await self.setupAccount()
self.loading = false
self.$store.state.walletLoggedIn = null
if (self.provider === 'metamask') {
store.set('address', self.address.toLowerCase())
store.set('network', self.provider)
}
if (self.address) {
self.$store.state.address = self.address.toLowerCase()
if (self.provider === 'metamask') {
store.set('address', self.address.toLowerCase())
store.set('network', self.provider)
}
self.$bus.$emit('logged', 'user logged')
self.$toasted.show('Network Provider was changed successfully')
} else {
Expand Down Expand Up @@ -724,7 +722,7 @@ export default {
const self = this
let contract
self.address = account
self.$store.state.walletLoggedIn = account
self.$store.state.address = account
const web3 = new Web3(new HDWalletProvider(
'',
self.chainConfig.rpc, 0, 1, self.hdPath))
Expand Down
15 changes: 5 additions & 10 deletions app/components/candidates/Apply.vue
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ export default {
},
created: async function () {
const self = this
let account
self.config = store.get('configMaster') || await self.appConfig()
self.chainConfig = self.config.blockchain || {}
try {
Expand All @@ -206,13 +205,8 @@ export default {
if (!self.web3 && self.NetworkProvider === 'metamask') {
throw Error('Web3 is not properly detected. Have you installed MetaMask extension?')
}
if (store.get('address')) {
account = store.get('address').toLowerCase()
} else {
account = this.$store.state.walletLoggedIn
? this.$store.state.walletLoggedIn : await self.getAccount()
}
self.account = account
self.account = store.get('address') ||
self.$store.state.address || await self.getAccount()
} catch (e) {
self.$toasted.show(`You need login your account before voting`,
{
Expand Down Expand Up @@ -295,8 +289,9 @@ export default {
let contract// = await self.getTomoValidatorInstance()
contract = self.TomoValidator
const account = (await self.getAccount() || '').toLowerCase()
let txParams = {
from : self.account,
from : account,
value: self.web3.utils.toHex(new BigNumber(value).multipliedBy(10 ** 18).toString(10)),
gasPrice: self.web3.utils.toHex(self.gasPrice),
gas: self.web3.utils.toHex(self.chainConfig.gas),
Expand All @@ -305,7 +300,7 @@ export default {
}
if (self.NetworkProvider === 'ledger' ||
self.NetworkProvider === 'trezor') {
let nonce = await self.web3.eth.getTransactionCount(self.account)
let nonce = await self.web3.eth.getTransactionCount(account)
// let dataTx = contract.propose.request(coinbase).params[0]
const data = await contract.methods.propose(coinbase).encodeABI()
const dataTx = {
Expand Down
11 changes: 3 additions & 8 deletions app/components/candidates/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ export default {
updated () {},
created: async function () {
let self = this
let account
self.isReady = !!self.web3
const config = store.get('configMaster') || await self.appConfig()
self.chainConfig = config.blockchain
Expand All @@ -244,13 +243,9 @@ export default {
if (self.isReady) {
let contract// = await self.getTomoValidatorInstance()
contract = self.TomoValidator
if (store.get('address')) {
account = store.get('address').toLowerCase()
} else {
account = this.$store.state.walletLoggedIn
? this.$store.state.walletLoggedIn : await self.getAccount()
}
if (account && contract) {
self.account = store.get('address') ||
self.$store.state.address || await self.getAccount()
if (self.account && contract) {
self.isTomonet = true
}
}
Expand Down
12 changes: 3 additions & 9 deletions app/components/candidates/Resign.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,14 @@ export default {
updated () {},
created: async function () {
let self = this
let account
self.config = store.get('configMaster') || await self.appConfig()
self.chainConfig = self.config.blockchain || {}
self.isReady = !!self.web3
self.gasPrice = await self.web3.eth.getGasPrice()
try {
if (self.isReady) {
if (store.get('address')) {
account = store.get('address').toLowerCase()
} else {
account = this.$store.state.walletLoggedIn
? this.$store.state.walletLoggedIn : await self.getAccount()
}
self.account = (account || '').toLowerCase()
self.account = store.get('address') ||
self.$store.state.address || await self.getAccount()
}
let candidate = await axios.get(`/api/candidates/${self.coinbase}`)
Expand All @@ -136,7 +130,7 @@ export default {
self.loading = true
let account = (await self.getAccount() || '').toLowerCase()
const account = (await self.getAccount() || '').toLowerCase()
let contract// = await self.getTomoValidatorInstance()
contract = self.TomoValidator
let coinbase = self.coinbase
Expand Down
8 changes: 2 additions & 6 deletions app/components/candidates/Update.vue
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,8 @@ export default {
self.$router.push({ path: '/setting' })
throw Error('Web3 is not properly detected.')
}
if (store.get('address')) {
self.account = store.get('address').toLowerCase()
} else {
self.account = this.$store.state.walletLoggedIn
? this.$store.state.walletLoggedIn : await self.getAccount()
}
self.account = store.get('address') ||
self.$store.state.address || await self.getAccount()
const { data } = await axios.get(`/api/candidates/${self.address}`)
if (data) {
if (data.owner !== self.account) {
Expand Down
8 changes: 2 additions & 6 deletions app/components/candidates/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -637,12 +637,8 @@ export default {
if (self.isReady) {
let contract// = self.TomoValidator.deployed()
contract = self.TomoValidator
if (store.get('address')) {
self.account = store.get('address').toLowerCase()
} else {
self.account = this.$store.state.walletLoggedIn
? this.$store.state.walletLoggedIn : self.getAccount()
}
self.account = store.get('address') ||
self.$store.state.address || await self.getAccount()
if (await self.account && await contract) {
self.isTomonet = true
}
Expand Down
7 changes: 2 additions & 5 deletions app/components/candidates/Withdraw.vue
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,10 @@ export default {
let self = this
let contract// = await self.getTomoValidatorInstance()
contract = self.TomoValidator
let account = await self.getAccount()
account = account.toLowerCase()
const account = (await self.getAccount() || '').toLowerCase()
self.loading = true
try {
console.log('==>', blockNumber, index)
// console.log('==>', blockNumber, index)
let txParams = {
from: account,
gasPrice: self.web3.utils.toHex(self.gasPrice),
Expand All @@ -196,8 +195,6 @@ export default {
self.NetworkProvider === 'trezor') {
let nonce = await self.web3.eth.getTransactionCount(account)
// let dataTx = contract.withdraw.request(String(blockNumber), String(index)).params[0]
console.log(blockNumber)
console.log(index)
const data = await contract.methods.withdraw(blockNumber, index).encodeABI()
const dataTx = {
data,
Expand Down
15 changes: 4 additions & 11 deletions app/components/voters/Unvoting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ export default {
created: async function () {
let self = this
let candidate = self.candidate
let account
self.loadingPage = true
self.config = store.get('configMaster') || await self.appConfig()
self.chainConfig = self.config.blockchain || {}
Expand All @@ -269,20 +268,15 @@ export default {
try {
self.isReady = !!self.web3
if (store.get('address')) {
account = store.get('address').toLowerCase()
} else {
account = this.$store.state.walletLoggedIn
? this.$store.state.walletLoggedIn : await self.getAccount()
}
self.voter = account
self.voter = store.get('address') ||
self.$store.state.address || await self.getAccount()
const isOwnerPromise = axios.get(`/api/candidates/${candidate}/${self.voter}/isOwner`)
let contract// = await self.getTomoValidatorInstance()
contract = self.TomoValidator
// let votedCap = await contract.getVoterCap(candidate, account)
let votedCap = await contract.methods.getVoterCap(candidate, account).call()
let votedCap = await contract.methods.getVoterCap(candidate, self.voter).call()
self.voted = new BigNumber(votedCap).div(10 ** 18).toString(10)
const isOwner = (await isOwnerPromise).data || false
Expand Down Expand Up @@ -333,8 +327,7 @@ export default {
self.loading = true
let unvoteValue = new BigNumber(value).multipliedBy(1e+18).toString(10)
let account = await self.getAccount()
account = account.toLowerCase()
const account = (await self.getAccount() || '').toLowerCase()
let contract// = await self.getTomoValidatorInstance()
contract = self.TomoValidator
let txParams = {
Expand Down
15 changes: 3 additions & 12 deletions app/components/voters/Voting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ export default {
updated () {},
created: async function () {
let self = this
let account
self.config = store.get('configMaster') || await self.appConfig()
self.chainConfig = self.config.blockchain || {}
self.isReady = !!self.web3
Expand All @@ -229,15 +228,8 @@ export default {
if (!self.isReady && self.NetworkProvider === 'metamask') {
throw Error('Web3 is not properly detected. Have you installed MetaMask extension?')
}
if (store.get('address')) {
account = store.get('address').toLowerCase()
} else {
account = this.$store.state.walletLoggedIn
? this.$store.state.walletLoggedIn : await self.getAccount()
}
if (account) {
self.voter = account
}
self.voter = store.get('address') ||
self.$store.state.address || await self.getAccount()
self.web3.eth.getBalance(self.voter, function (a, b) {
self.balance = new BigNumber(b).div(10 ** 18)
if (a) {
Expand Down Expand Up @@ -300,8 +292,7 @@ export default {
throw Error('Web3 is not properly detected.')
}
self.loading = true
let account = await self.getAccount()
account = account.toLowerCase()
const account = (await self.getAccount() || '').toLowerCase()
let contract// = await self.getTomoValidatorInstance()
contract = self.TomoValidator
let txParams = {
Expand Down

0 comments on commit ae7c3f9

Please sign in to comment.