Refactor codes
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# frontend-nftdapp
|
||||
# frontend-nftbapp
|
||||
|
||||
## Project setup
|
||||
```
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "frontend-nftdapp",
|
||||
"name": "frontend-nftbapp",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<noscript>
|
||||
<strong>We're sorry but frontend-nftdapp doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||
<strong>We're sorry but frontend-nftbapp doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||
</noscript>
|
||||
<div id="app"></div>
|
||||
<!-- built files will be auto injected -->
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<v-app>
|
||||
<v-app-bar app clipped-left dense>
|
||||
<v-toolbar-title>NFT APP</v-toolbar-title>
|
||||
<v-toolbar-title>NFT BAPP</v-toolbar-title>
|
||||
<v-spacer></v-spacer>
|
||||
|
||||
<div class="nav">
|
||||
@@ -26,7 +26,7 @@ import KlaytnService from './klaytn/klaytnService'
|
||||
export default {
|
||||
name: 'app',
|
||||
|
||||
async mounted () {
|
||||
async created () {
|
||||
await this.connect()
|
||||
},
|
||||
|
||||
|
||||
@@ -76,13 +76,13 @@ import KlaytnService from '@/klaytn/klaytnService'
|
||||
snackbar: false,
|
||||
snackbarMsg: '',
|
||||
|
||||
klaytn: null,
|
||||
privateKey: null,
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
...mapGetters('wallet', [
|
||||
'klaytn',
|
||||
'isConnectWallet',
|
||||
'myaddress',
|
||||
'balance'
|
||||
@@ -90,15 +90,19 @@ import KlaytnService from '@/klaytn/klaytnService'
|
||||
},
|
||||
|
||||
async mounted() {
|
||||
this.klaytn = new KlaytnService()
|
||||
await this.klaytn.init()
|
||||
const klaytn = new KlaytnService()
|
||||
this.setKlaytn(klaytn)
|
||||
const address = await klaytn.init()
|
||||
|
||||
if (address) {
|
||||
await this.getWalletInfo()
|
||||
await this.getMyAuctions()
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
...mapMutations('wallet', [
|
||||
'setKlaytn',
|
||||
'setIsConnectWallet',
|
||||
'setMyAddress',
|
||||
'setBalance'
|
||||
|
||||
@@ -44,10 +44,6 @@ export default {
|
||||
])
|
||||
},
|
||||
|
||||
async mounted() {
|
||||
|
||||
},
|
||||
|
||||
methods: {
|
||||
async createAuction() {
|
||||
if(!this.tokenid) {
|
||||
|
||||
@@ -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 AuctionsABI = require('@/contracts/Auctions.json').abi
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# bet-dapp
|
||||
# numbergame-bapp
|
||||
|
||||
## Project setup
|
||||
```
|
||||
|
||||
@@ -38,9 +38,6 @@ export default {
|
||||
])
|
||||
},
|
||||
|
||||
mounted () {
|
||||
},
|
||||
|
||||
methods: {
|
||||
clickNumber (event) {
|
||||
console.log('betting number', event.target.innerHTML, this.amount)
|
||||
|
||||
@@ -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)
|
||||
this.setBalance(balance)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -47,7 +47,6 @@ import { mapGetters, mapMutations } from 'vuex'
|
||||
|
||||
export default {
|
||||
data: () => ({
|
||||
// accessType: 'keystore',
|
||||
keystore: null,
|
||||
password: '',
|
||||
privateKey: null,
|
||||
@@ -73,7 +72,6 @@ export default {
|
||||
fileReader.onload = (e) => {
|
||||
try {
|
||||
if (!this.checkValidKeystore(e.target.result)) {
|
||||
// If key store file is invalid, show message "Invalid keystore file."
|
||||
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()
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -7,7 +7,6 @@ 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
|
||||
@@ -15,8 +14,6 @@ export default class KlaytnService {
|
||||
|
||||
return address
|
||||
} catch (e) {
|
||||
// If value in sessionStorage is invalid wallet instance,
|
||||
// remove it from sessionStorage.
|
||||
sessionStorage.removeItem('walletInstance')
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -97,7 +97,7 @@ export default {
|
||||
async mounted () {
|
||||
await this.connect()
|
||||
|
||||
await this.getFeeds()
|
||||
this.getFeeds()
|
||||
},
|
||||
|
||||
methods: {
|
||||
@@ -145,7 +145,6 @@ export default {
|
||||
this.snackbar = true
|
||||
|
||||
this.getFeeds()
|
||||
this.getBalance()
|
||||
|
||||
this.showWriteBox = false
|
||||
},
|
||||
@@ -156,7 +155,6 @@ export default {
|
||||
this.snackbar = true
|
||||
|
||||
this.getFeeds()
|
||||
this.getBalance()
|
||||
})
|
||||
},
|
||||
|
||||
@@ -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>
|
||||
@@ -65,7 +65,6 @@ export default {
|
||||
snackbar: false,
|
||||
errorTxt: '',
|
||||
|
||||
// accessType: 'keystore',
|
||||
keystore: null,
|
||||
password: '',
|
||||
privateKey: null,
|
||||
@@ -83,10 +82,6 @@ export default {
|
||||
'setBalance'
|
||||
]),
|
||||
|
||||
validate () {
|
||||
|
||||
},
|
||||
|
||||
handleImport (e) {
|
||||
const keystore = e.target.files[0]
|
||||
|
||||
@@ -94,7 +89,6 @@ export default {
|
||||
fileReader.onload = (e) => {
|
||||
try {
|
||||
if (!this.checkValidKeystore(e.target.result)) {
|
||||
// If key store file is invalid, show message "Invalid keystore file."
|
||||
this.errorTxt = 'Invalid keystore file.'
|
||||
this.snackbar = true
|
||||
return
|
||||
@@ -113,11 +107,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()
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -7,7 +7,6 @@ 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
|
||||
@@ -15,8 +14,6 @@ export default class KlaytnService {
|
||||
|
||||
return address
|
||||
} catch (e) {
|
||||
// If value in sessionStorage is invalid wallet instance,
|
||||
// remove it from sessionStorage.
|
||||
sessionStorage.removeItem('walletInstance')
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user