Refactor codes

This commit is contained in:
elegant651
2020-04-04 12:28:37 +09:00
parent dd3033be9c
commit 6c51a302b9
20 changed files with 59 additions and 97 deletions

View File

@@ -1,4 +1,4 @@
# bet-dapp
# numbergame-bapp
## Project setup
```

View File

@@ -36,9 +36,6 @@ export default {
...mapGetters('wallet', [
'klaytn'
])
},
mounted () {
},
methods: {

View File

@@ -50,10 +50,10 @@ export default {
this.setIsConnectWallet(false)
}
},
async getBalance () {
if (this.myaddress) {
const balance = await this.klaytn.getBalance(this.myaddress)
console.log(this.myaddress, balance)
const balance = await this.klaytn.getBalance(this.myaddress)
this.setBalance(balance)
}
},

View File

@@ -46,8 +46,7 @@
import { mapGetters, mapMutations } from 'vuex'
export default {
data: () => ({
// accessType: 'keystore',
data: () => ({
keystore: null,
password: '',
privateKey: null,
@@ -72,8 +71,7 @@ export default {
const fileReader = new FileReader()
fileReader.onload = (e) => {
try {
if (!this.checkValidKeystore(e.target.result)) {
// If key store file is invalid, show message "Invalid keystore file."
if (!this.checkValidKeystore(e.target.result)) {
alert('Invalid keystore file.')
return
}
@@ -90,11 +88,9 @@ export default {
async handleAddWallet () {
try {
// Access type2: access thorugh private key
if(this.privateKey) {
await this.klaytn.integrateWallet(this.privateKey)
} else {
// Access type1: access through keystore + password
await this.klaytn.loginWithKeystore(this.keystore, this.password)
}
this.getWalletInfo()

View File

@@ -1,8 +1,4 @@
/**
* caver-js library helps making connection with klaytn node.
* You can connect to specific klaytn node by setting 'rpcURL' value.
* default rpcURL is 'https://api.baobab.klaytn.net:8651'.
*/
import Caver from 'caver-js'
const deployedABI = require('./deployedABI.json')

View File

@@ -6,17 +6,14 @@ export default class KlaytnService {
async init () {
const walletFromSession = sessionStorage.getItem('walletInstance')
// If 'walletInstance' value exists, add it to caver's wallet
if (walletFromSession) {
try {
const address = JSON.parse(walletFromSession).address
cav.klay.accounts.wallet.add(JSON.parse(walletFromSession))
return address
} catch (e) {
// If value in sessionStorage is invalid wallet instance,
// remove it from sessionStorage.
} catch (e) {
sessionStorage.removeItem('walletInstance')
return false
}