Compare commits

...

2 Commits

Author SHA1 Message Date
49009af8e3
fix: add register() call in the sign up flow 2023-06-09 02:06:41 +08:00
13b28e315b
feat: show payment logs on credit page 2023-06-09 01:33:43 +08:00
5 changed files with 421 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

@ -63,6 +63,12 @@
"name": "client", "name": "client",
"type": "address" "type": "address"
}, },
{
"indexed": false,
"internalType": "address",
"name": "shop",
"type": "address"
},
{ {
"indexed": false, "indexed": false,
"internalType": "address", "internalType": "address",
@ -528,6 +534,11 @@
"name": "client", "name": "client",
"type": "address" "type": "address"
}, },
{
"internalType": "address",
"name": "shop",
"type": "address"
},
{ {
"internalType": "uint256", "internalType": "uint256",
"name": "id", "name": "id",

View File

@ -2,6 +2,7 @@ import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue' import HomeView from '../views/HomeView.vue'
import SignupView from '../views/SignupView.vue' import SignupView from '../views/SignupView.vue'
import LinkSBTView from '../views/LinkSBTView.vue' import LinkSBTView from '../views/LinkSBTView.vue'
import CreditView from '../views/CreditView.vue'
const router = createRouter({ const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL), history: createWebHistory(import.meta.env.BASE_URL),
@ -20,6 +21,11 @@ const router = createRouter({
path: '/signup/linksbt', path: '/signup/linksbt',
name: 'linksbt', name: 'linksbt',
component: LinkSBTView component: LinkSBTView
},
{
path: '/signup/credit',
name: 'startcredit',
component: CreditView
} }
] ]
}) })

131
src/views/CreditView.vue Normal file
View File

@ -0,0 +1,131 @@
<script>
import Web3 from 'web3';
import SBT from '@/assets/SBT.json'
import PageTitle from '../components/PageTitle.vue'
import detectEthereumProvider from '@metamask/detect-provider'
import WarningModal from '../components/WarningModal.vue'
import SuccessModal from '../components/SuccessModal.vue'
import { useClientStore } from '../stores/Client.js'
export default {
components: { PageTitle, WarningModal, SuccessModal },
data() {
return {
SBTAddress: import.meta.env.VITE_SBT_ADDR,
number: 0,
warningModalStatus: false,
successModalStatus: false,
msg: '',
clientAddr: '',
web3: null,
token: null,
isWaiting: false,
log: []
}
},
async mounted() {
this.web3 = new Web3(window.ethereum)
this.clientAddr = (await this.web3.eth.getAccounts())[0]
this.web3.eth.defaultAccount = this.clientAddr
this.token = new this.web3.eth.Contract(SBT, this.SBTAddress)
var borrow = await this.token.getPastEvents("Borrow", { fromBlock: 0, toBlock: 'latest', filter: { client: this.clientAddr } })
for (let i of borrow) {
let result = i.returnValues
let obj = {
bank: result['bank'],
shop: result['shop'],
id: result['id'],
amount: this.web3.utils.fromWei(result['amount'], 'ether'),
repay: false
}
this.log.push(obj)
}
var repay = await this.token.getPastEvents("Repay", { fromBlock: 0, toBlock: 'latest', filter: { client: this.clientAddr } })
for (let i of repay) {
let result = i.returnValues
for (let j of this.log) {
if ((result['bank'] == j.bank) && (result['id'] == j.id)) {
j.repay = true
}
}
}
console.log(this.log)
},
methods: {
}
}
</script>
<template>
<section class="blog-posts">
<div class="container">
<div class="block">
<PageTitle title="Set Credit Limit" subtitle="根據 SBT 信用紀錄設定額度"></PageTitle>
</div>
<div class="block">
<div class="box">
<div class="content">
<h5 class="title is-5">說明</h5>
<ul>
<li>我們會根據您提供的 SBT 查詢相關信用紀錄我們會根據紀錄設定給予的每月額度</li>
<li>若在前個步驟您 mint 了新的 SBT代表您不曾擁有過信用紀錄下表為空</li>
<li>若您不曾擁有過信用交易紀錄我們提供最低額度 3 ETH/1 month</li>
<li>請確認下表紀錄我們將依照該紀錄表計算</li>
</ul>
</div>
</div>
</div>
<br>
<div class="block">
<h1 class="title is-4">支付紀錄</h1>
<table class="table is-fullwidth is-striped is-hoverable">
<thead>
<tr>
<th>#</th>
<th>銀行</th>
<th>銀行帳款編號</th>
<th>商店</th>
<th>金額</th>
<th>已結清帳款</th>
</tr>
</thead>
<tbody>
<template v-for="(value, index) of log">
<tr>
<th>{{ index }}</th>
<td>{{ value.bank }}</td>
<td>{{ value.id }}</td>
<td>{{ value.shop }}</td>
<td>{{ value.amount }} ETH</td>
<td v-if="value.repay">
<span class="icon has-text-success">
<i class="fas fa-check-square"></i>
</span>
</td>
</tr>
</template>
</tbody>
</table>
</div>
<div class="block">
<div class="columns">
<div class="column is-2 is-offset-4">
<button @click="detect" class="button is-primary is-fullwidth is-medium is-outlined">Link to
MetaMask</button>
</div>
<div class="column is-2">
<RouterLink to="/" class="button is-danger is-fullwidth is-medium is-outlined">Cancel</RouterLink>
</div>
</div>
</div>
</div>
</section>
<WarningModal :active="warningModalStatus" :errorMsg="msg" @closeModal="warningModalStatus = false"></WarningModal>
<SuccessModal :active="successModalStatus" :successMsg="msg" @closeModal="successModalStatus = false"
link="/signup/linksbt" btnName="繼續"></SuccessModal>
</template>

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>