fix: add register() call in the sign up flow

This commit is contained in:
snsd0805 2023-06-09 02:06:41 +08:00
parent 13b28e315b
commit 49009af8e3
Signed by: snsd0805
GPG Key ID: 569349933C77A854
2 changed files with 273 additions and 9 deletions

219
src/assets/Bank.json Normal file
View File

@ -0,0 +1,219 @@
[
{
"inputs": [
{
"internalType": "address",
"name": "SBT_addr",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function",
"constant": true
},
{
"inputs": [],
"name": "recv",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function",
"constant": true
},
{
"inputs": [],
"name": "sbt",
"outputs": [
{
"internalType": "contract SoulboundToken",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function",
"constant": true
},
{
"stateMutability": "payable",
"type": "receive",
"payable": true
},
{
"inputs": [
{
"internalType": "address",
"name": "client",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "setCredit",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "number",
"type": "uint256"
}
],
"name": "register",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "shop",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "pay",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "repay",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "payable",
"type": "function",
"payable": true
},
{
"inputs": [],
"name": "start_recv",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "stop_recv",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "client",
"type": "address"
}
],
"name": "getCredit",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function",
"constant": true
},
{
"inputs": [
{
"internalType": "address",
"name": "client",
"type": "address"
}
],
"name": "getArrear",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function",
"constant": true
},
{
"inputs": [
{
"internalType": "address",
"name": "client",
"type": "address"
}
],
"name": "getClientOrders",
"outputs": [
{
"components": [
{
"internalType": "bool",
"name": "isFinished",
"type": "bool"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "address",
"name": "shop",
"type": "address"
}
],
"internalType": "struct Order[]",
"name": "",
"type": "tuple[]"
}
],
"stateMutability": "view",
"type": "function",
"constant": true
}
]

View File

@ -5,6 +5,7 @@ import SBT from '@/assets/SBT.json'
import WarningModal from '../components/WarningModal.vue' import WarningModal from '../components/WarningModal.vue'
import SuccessModal from '../components/SuccessModal.vue' import SuccessModal from '../components/SuccessModal.vue'
import PageTitle from '../components/PageTitle.vue' import PageTitle from '../components/PageTitle.vue'
import Bank from '@/assets/Bank.json'
import { useClientStore } from '../stores/Client.js' import { useClientStore } from '../stores/Client.js'
@ -14,6 +15,7 @@ export default {
data() { data() {
return { return {
SBTAddress: import.meta.env.VITE_SBT_ADDR, SBTAddress: import.meta.env.VITE_SBT_ADDR,
BankAddress: import.meta.env.VITE_BANK_ADDR,
number: 0, number: 0,
warningModalStatus: false, warningModalStatus: false,
successModalStatus: false, successModalStatus: false,
@ -21,7 +23,8 @@ export default {
clientAddr: '', clientAddr: '',
web3: null, web3: null,
token: null, token: null,
isWaiting: false isWaiting: false,
link: ''
} }
}, },
async mounted() { async mounted() {
@ -29,17 +32,27 @@ export default {
this.clientAddr = (await this.web3.eth.getAccounts())[0] this.clientAddr = (await this.web3.eth.getAccounts())[0]
this.web3.eth.defaultAccount = this.clientAddr this.web3.eth.defaultAccount = this.clientAddr
this.token = new this.web3.eth.Contract(SBT, this.SBTAddress) this.token = new this.web3.eth.Contract(SBT, this.SBTAddress)
this.bank = new this.web3.eth.Contract(Bank, this.BankAddress)
}, },
methods: { methods: {
async check() { async check() {
this.isWaiting = true
var returnNumber = await this.token.methods.getAccountNumber(this.clientAddr).call() var returnNumber = await this.token.methods.getAccountNumber(this.clientAddr).call()
if (returnNumber != 0 && returnNumber == this.number) { if (returnNumber != 0 && returnNumber == this.number) {
this.successModalStatus = true try {
this.msg = '驗證成功!' await this.bank.methods.register(this.number).send({ from: this.clientAddr })
this.successModalStatus = true
this.link = '/signup/credit'
this.msg = '註冊成功!'
} catch (error) {
this.warningModalStatus = true
this.msg = '註冊失敗,您可能在本銀行已經註冊過了'
}
} else { } else {
this.warningModalStatus = true this.warningModalStatus = true
this.msg = '連接失敗,這並不是你的 SBT number' this.msg = '連接失敗,這並不是你的 SBT number'
} }
this.isWaiting = false
}, },
async mint() { async mint() {
this.isWaiting = true this.isWaiting = true
@ -47,6 +60,8 @@ export default {
var result = await this.token.methods.mint(this.clientAddr).send({ from: this.clientAddr }) var result = await this.token.methods.mint(this.clientAddr).send({ from: this.clientAddr })
this.successModalStatus = true this.successModalStatus = true
var returnNumber = await this.token.methods.getAccountNumber(this.clientAddr).call() var returnNumber = await this.token.methods.getAccountNumber(this.clientAddr).call()
this.number = returnNumber
this.link = '/signup/linksbt'
this.msg = 'mint 成功! <a href="https://sepolia.etherscan.io/tx/' + result.transactionHash + '">etherscan</a><br>您的 SBT number 是 ' + returnNumber this.msg = 'mint 成功! <a href="https://sepolia.etherscan.io/tx/' + result.transactionHash + '">etherscan</a><br>您的 SBT number 是 ' + returnNumber
} catch (error) { } catch (error) {
this.warningModalStatus = true this.warningModalStatus = true
@ -73,7 +88,7 @@ export default {
<h1 class="title is-4">您已經擁有 SBT</h1> <h1 class="title is-4">您已經擁有 SBT</h1>
</div> </div>
<div class="block"> <div class="block">
請輸入您的 SBT 相關資訊 跟銀行註冊您的 SBT 相關資訊
</div> </div>
<div class="block"> <div class="block">
<div class="field"> <div class="field">
@ -96,7 +111,12 @@ export default {
<!-- <p class="help is-success">This username is available</p> --> <!-- <p class="help is-success">This username is available</p> -->
</div> </div>
<div class="column is-2 is-offset-5"> <div class="column is-2 is-offset-5">
<button class="button is-info is-outlined" @click="check">驗證</button> <template v-if="!isWaiting">
<button class="button is-info is-outlined" @click="check">註冊</button>
</template>
<template v-else>
<button class="button is-info is-outlined is-loading"></button>
</template>
</div> </div>
</div> </div>
</div> </div>
@ -107,8 +127,7 @@ export default {
<h1 class="title is-4">您還沒有 SBT</h1> <h1 class="title is-4">您還沒有 SBT</h1>
</div> </div>
<div class="block"> <div class="block">
向下方 SBT 智能合約地址請求 Mint 一個 Soulbound Token 到你的地址 1. 向下方 SBT 智能合約地址請求 Mint 一個 Soulbound Token 到你的地址
</div> </div>
<div class="block"> <div class="block">
<div class="field"> <div class="field">
@ -125,6 +144,32 @@ export default {
<button class="button is-info is-outlined is-loading"></button> <button class="button is-info is-outlined is-loading"></button>
</template> </template>
</div> </div>
</div>
<div class="block">
2. 跟銀行註冊您的 SBT 相關資訊
</div>
<div class="block">
<div class="field">
<label class="label">Username</label>
<div class="control has-icons-left has-icons-right">
<input class="input is-info is-rounded" type="number" placeholder="Token number" v-model="number">
<span class="icon is-small is-left">
<i class="fas fa-user"></i>
</span>
<span class="icon is-small is-right">
<!-- <i class="fas fa-check"></i> -->
</span>
</div>
<!-- <p class="help is-success">This username is available</p> -->
</div>
<div class="column is-2 is-offset-5">
<template v-if="!isWaiting">
<button class="button is-info is-outlined" @click="check">註冊</button>
</template>
<template v-else>
<button class="button is-info is-outlined is-loading"></button>
</template>
</div>
</div> </div>
</div> </div>
@ -134,6 +179,6 @@ export default {
</div> </div>
</section> </section>
<WarningModal :active="warningModalStatus" :errorMsg="msg" @closeModal="warningModalStatus = false"></WarningModal> <WarningModal :active="warningModalStatus" :errorMsg="msg" @closeModal="warningModalStatus = false"></WarningModal>
<SuccessModal :active="successModalStatus" :successMsg="msg" @closeModal="successModalStatus = false" <SuccessModal :active="successModalStatus" :successMsg="msg" @closeModal="successModalStatus = false" :link="link"
link="/signup/credit" btnName="繼續"></SuccessModal> btnName="繼續"></SuccessModal>
</template> </template>