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

@@ -97,7 +97,7 @@ export default {
async mounted () {
await this.connect()
await this.getFeeds()
this.getFeeds()
},
methods: {
@@ -144,8 +144,7 @@ export default {
this.snackbarMsg = msg
this.snackbar = true
this.getFeeds()
this.getBalance()
this.getFeeds()
this.showWriteBox = false
},
@@ -155,8 +154,7 @@ export default {
this.snackbarMsg = `Complete.. blocknumber: #${receipt.blockNumber} , ${receipt.transactionHash}`
this.snackbar = true
this.getFeeds()
this.getBalance()
this.getFeeds()
})
},
@@ -164,6 +162,8 @@ export default {
this.klaytn.getFeeds((feed) => {
this.setTodos(feed)
})
this.getBalance()
}
}
}

View File

@@ -8,7 +8,7 @@
<v-col cols="16">
<h2>Integrated</h2>
<div class="address">{{walletInstance.address}}</div>
<v-btn outlined class="btnSubmit mt-3" @click="this.handleRemoveWallet">REMOVE WALLEt</v-btn>
<v-btn outlined class="btnSubmit mt-3" @click="this.handleRemoveWallet">REMOVE WALLET</v-btn>
</v-col>
</v-row>
</v-container>
@@ -64,8 +64,7 @@ export default {
data: () => ({
snackbar: false,
errorTxt: '',
// accessType: 'keystore',
keystore: null,
password: '',
privateKey: null,
@@ -81,11 +80,7 @@ export default {
'setIsConnectWallet',
'setMyAddress',
'setBalance'
]),
validate () {
},
]),
handleImport (e) {
const keystore = e.target.files[0]
@@ -93,8 +88,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)) {
this.errorTxt = 'Invalid keystore file.'
this.snackbar = true
return
@@ -112,12 +106,10 @@ export default {
},
async handleAddWallet () {
try {
// Access type2: access thorugh private key
try {
if(this.privateKey) {
await this.klaytn.integrateWallet(this.privateKey)
} else {
// Access type1: access through keystore + password
} else {
await this.klaytn.loginWithKeystore(this.keystore, this.password)
}
this.getWalletInfo()

View File

@@ -85,8 +85,6 @@ export default {
try {
this.isLoading = true
await this.klaytn.writeTodo(this.title, this.imgFile, (receipt) => {
console.log(receipt)
const snackbarMsg = `Complete.. blocknumber: #${receipt.blockNumber} , ${receipt.transactionHash}`
this.$emit('success-write', snackbarMsg)
@@ -99,7 +97,6 @@ export default {
})
} catch (e) {
console.error(e)
this.isLoading = false
}
}

View File

@@ -1,8 +1,3 @@
/**
* 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
}