From 6c51a302b9bb0b73aa28244c9255d949588ee030 Mon Sep 17 00:00:00 2001 From: elegant651 Date: Sat, 4 Apr 2020 12:28:37 +0900 Subject: [PATCH] Refactor codes --- nftbapp/frontend-nftbapp/README.md | 2 +- nftbapp/frontend-nftbapp/package.json | 2 +- nftbapp/frontend-nftbapp/public/index.html | 2 +- nftbapp/frontend-nftbapp/src/App.vue | 6 ++-- .../src/components/MyUpload.vue | 18 +++++------ .../src/components/MyWallet.vue | 30 +++++++++++-------- .../src/components/PostAuction.vue | 4 --- nftbapp/frontend-nftbapp/src/klaytn/caver.js | 5 ---- numbergame/README.md | 2 +- .../src/components/betting-component.vue | 3 -- numbergame/src/components/game-bapp.vue | 4 +-- numbergame/src/components/wallet.vue | 8 ++--- numbergame/src/klaytn/caver.js | 6 +--- numbergame/src/klaytn/klaytnService.js | 7 ++--- .../backend-todofeed/contracts/TodoFeed.sol | 12 ++++---- todofeed/front-todofeed/src/App.vue | 10 +++---- .../src/components/LoginBox.vue | 20 ++++--------- .../src/components/WriteBox.vue | 3 -- todofeed/front-todofeed/src/klaytn/caver.js | 5 ---- .../src/klaytn/klaytnService.js | 7 ++--- 20 files changed, 59 insertions(+), 97 deletions(-) diff --git a/nftbapp/frontend-nftbapp/README.md b/nftbapp/frontend-nftbapp/README.md index ed6ab1e..5e4cb4a 100644 --- a/nftbapp/frontend-nftbapp/README.md +++ b/nftbapp/frontend-nftbapp/README.md @@ -1,4 +1,4 @@ -# frontend-nftdapp +# frontend-nftbapp ## Project setup ``` diff --git a/nftbapp/frontend-nftbapp/package.json b/nftbapp/frontend-nftbapp/package.json index c6a15d7..32f5f66 100644 --- a/nftbapp/frontend-nftbapp/package.json +++ b/nftbapp/frontend-nftbapp/package.json @@ -1,5 +1,5 @@ { - "name": "frontend-nftdapp", + "name": "frontend-nftbapp", "version": "0.1.0", "private": true, "scripts": { diff --git a/nftbapp/frontend-nftbapp/public/index.html b/nftbapp/frontend-nftbapp/public/index.html index fe2e950..be21d04 100644 --- a/nftbapp/frontend-nftbapp/public/index.html +++ b/nftbapp/frontend-nftbapp/public/index.html @@ -13,7 +13,7 @@
diff --git a/nftbapp/frontend-nftbapp/src/App.vue b/nftbapp/frontend-nftbapp/src/App.vue index 2feb2de..f4bbac3 100644 --- a/nftbapp/frontend-nftbapp/src/App.vue +++ b/nftbapp/frontend-nftbapp/src/App.vue @@ -1,7 +1,7 @@ - - + +

Transfer

@@ -75,14 +75,14 @@ import KlaytnService from '@/klaytn/klaytnService' snackbar: false, snackbarMsg: '', - - klaytn: null, + privateKey: null, } }, computed: { - ...mapGetters('wallet', [ + ...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() - await this.getWalletInfo() - await this.getMyAuctions() - }, + if (address) { + await this.getWalletInfo() + await this.getMyAuctions() + } + }, methods: { - ...mapMutations('wallet', [ + ...mapMutations('wallet', [ + 'setKlaytn', 'setIsConnectWallet', 'setMyAddress', 'setBalance' @@ -108,7 +112,7 @@ import KlaytnService from '@/klaytn/klaytnService' if(this.privateKey) { await this.klaytn.integrateWallet(this.privateKey) this.getWalletInfo() - } + } } catch (e) { this.snackbarMsg = `private key doesn't match.` this.snackbar = true @@ -146,7 +150,7 @@ import KlaytnService from '@/klaytn/klaytnService' alert(`Auction finalized...! (#${receipt.blockNumber} ,${receipt.transactionHash})`) }, (error) => { console.error(error) - }) + }) } } diff --git a/nftbapp/frontend-nftbapp/src/components/PostAuction.vue b/nftbapp/frontend-nftbapp/src/components/PostAuction.vue index ab82c63..4c701fb 100644 --- a/nftbapp/frontend-nftbapp/src/components/PostAuction.vue +++ b/nftbapp/frontend-nftbapp/src/components/PostAuction.vue @@ -44,10 +44,6 @@ export default { ]) }, - async mounted() { - - }, - methods: { async createAuction() { if(!this.tokenid) { diff --git a/nftbapp/frontend-nftbapp/src/klaytn/caver.js b/nftbapp/frontend-nftbapp/src/klaytn/caver.js index 7faa990..5f7faa8 100644 --- a/nftbapp/frontend-nftbapp/src/klaytn/caver.js +++ b/nftbapp/frontend-nftbapp/src/klaytn/caver.js @@ -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 diff --git a/numbergame/README.md b/numbergame/README.md index bdb3d1a..354bd5a 100644 --- a/numbergame/README.md +++ b/numbergame/README.md @@ -1,4 +1,4 @@ -# bet-dapp +# numbergame-bapp ## Project setup ``` diff --git a/numbergame/src/components/betting-component.vue b/numbergame/src/components/betting-component.vue index 1c1b840..8e6ed32 100644 --- a/numbergame/src/components/betting-component.vue +++ b/numbergame/src/components/betting-component.vue @@ -36,9 +36,6 @@ export default { ...mapGetters('wallet', [ 'klaytn' ]) - }, - - mounted () { }, methods: { diff --git a/numbergame/src/components/game-bapp.vue b/numbergame/src/components/game-bapp.vue index d472d27..baa5c78 100644 --- a/numbergame/src/components/game-bapp.vue +++ b/numbergame/src/components/game-bapp.vue @@ -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) } }, diff --git a/numbergame/src/components/wallet.vue b/numbergame/src/components/wallet.vue index cfb0749..2ce01da 100644 --- a/numbergame/src/components/wallet.vue +++ b/numbergame/src/components/wallet.vue @@ -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() diff --git a/numbergame/src/klaytn/caver.js b/numbergame/src/klaytn/caver.js index 77cb918..5e5f955 100644 --- a/numbergame/src/klaytn/caver.js +++ b/numbergame/src/klaytn/caver.js @@ -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') diff --git a/numbergame/src/klaytn/klaytnService.js b/numbergame/src/klaytn/klaytnService.js index 4681806..f2c330c 100644 --- a/numbergame/src/klaytn/klaytnService.js +++ b/numbergame/src/klaytn/klaytnService.js @@ -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 } diff --git a/todofeed/backend-todofeed/contracts/TodoFeed.sol b/todofeed/backend-todofeed/contracts/TodoFeed.sol index 4fbaee0..e52e8ad 100644 --- a/todofeed/backend-todofeed/contracts/TodoFeed.sol +++ b/todofeed/backend-todofeed/contracts/TodoFeed.sol @@ -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); diff --git a/todofeed/front-todofeed/src/App.vue b/todofeed/front-todofeed/src/App.vue index ee69307..2df380f 100644 --- a/todofeed/front-todofeed/src/App.vue +++ b/todofeed/front-todofeed/src/App.vue @@ -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() } } } diff --git a/todofeed/front-todofeed/src/components/LoginBox.vue b/todofeed/front-todofeed/src/components/LoginBox.vue index 30ed3c8..2df4de8 100644 --- a/todofeed/front-todofeed/src/components/LoginBox.vue +++ b/todofeed/front-todofeed/src/components/LoginBox.vue @@ -8,7 +8,7 @@

Integrated

{{walletInstance.address}}
- REMOVE WALLEt + REMOVE WALLET
@@ -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() diff --git a/todofeed/front-todofeed/src/components/WriteBox.vue b/todofeed/front-todofeed/src/components/WriteBox.vue index ee2f955..4fd59ee 100644 --- a/todofeed/front-todofeed/src/components/WriteBox.vue +++ b/todofeed/front-todofeed/src/components/WriteBox.vue @@ -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 } } diff --git a/todofeed/front-todofeed/src/klaytn/caver.js b/todofeed/front-todofeed/src/klaytn/caver.js index cc47621..a4573a7 100644 --- a/todofeed/front-todofeed/src/klaytn/caver.js +++ b/todofeed/front-todofeed/src/klaytn/caver.js @@ -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') diff --git a/todofeed/front-todofeed/src/klaytn/klaytnService.js b/todofeed/front-todofeed/src/klaytn/klaytnService.js index a843194..adc40e6 100644 --- a/todofeed/front-todofeed/src/klaytn/klaytnService.js +++ b/todofeed/front-todofeed/src/klaytn/klaytnService.js @@ -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 }