Refactor codes
This commit is contained in:
@@ -8,13 +8,13 @@ contract TodoFeed {
|
||||
mapping(uint256 => TodoData) public todoMap;
|
||||
|
||||
struct TodoData {
|
||||
uint256 todoId; // Unique token id
|
||||
uint256 todoId;
|
||||
address owner;
|
||||
string title;
|
||||
bytes photo; // Image source encoded in uint 8 array format
|
||||
uint256 timestamp; // Uploaded time
|
||||
bool isVerified; // check if is verified, default false.
|
||||
address verifier; // verifier address
|
||||
bytes photo;
|
||||
uint256 timestamp;
|
||||
bool isVerified;
|
||||
address verifier;
|
||||
}
|
||||
|
||||
function writeTodo(string title, bytes photo) public {
|
||||
@@ -54,7 +54,7 @@ contract TodoFeed {
|
||||
todoMap[todoId].todoId,
|
||||
todoMap[todoId].owner,
|
||||
todoMap[todoId].title,
|
||||
todoMap[todoId].photo,
|
||||
todoMap[todoId].photo,
|
||||
todoMap[todoId].timestamp,
|
||||
todoMap[todoId].isVerified,
|
||||
todoMap[todoId].verifier);
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user