完善钱包连接流程
This commit is contained in:
parent
5977e01fc6
commit
44c8656b7a
@ -7,6 +7,7 @@ export interface IUser {
|
|||||||
locked: boolean
|
locked: boolean
|
||||||
avatar: string
|
avatar: string
|
||||||
password: string
|
password: string
|
||||||
|
account: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultUser: IUser = {
|
export const defaultUser: IUser = {
|
||||||
@ -16,7 +17,8 @@ export const defaultUser: IUser = {
|
|||||||
comment: '',
|
comment: '',
|
||||||
locked: false,
|
locked: false,
|
||||||
password: '',
|
password: '',
|
||||||
avatar: ''
|
avatar: '',
|
||||||
|
account: ''
|
||||||
}
|
}
|
||||||
export const getUserInfo = (data: any) =>
|
export const getUserInfo = (data: any) =>
|
||||||
request({
|
request({
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<div class="nav overflow" :class="{'show': menuShow}">
|
<div class="nav overflow" :class="{'show': menuShow}">
|
||||||
<label class="navItem">Thetan Boxes</label>
|
<label class="navItem">Thetan Boxes</label>
|
||||||
<label class="navItem dash">Marketplace</label>
|
<label class="navItem dash">Marketplace</label>
|
||||||
<button class="general-btn connectButton mobile" @click="collectToWallet">
|
<button v-if="!walletCollected" class="general-btn connectButton mobile" @click="collectToWallet">
|
||||||
<span>Connect Wallet</span>
|
<span>Connect Wallet</span>
|
||||||
</button>
|
</button>
|
||||||
<label class="navItem contact">Contact us</label>
|
<label class="navItem contact">Contact us</label>
|
||||||
@ -20,7 +20,7 @@
|
|||||||
<div>My Profile</div>
|
<div>My Profile</div>
|
||||||
<img src="data:image/svg+xml,%3csvg width='10' height='18' viewBox='0 0 10 18' fill='none' xmlns='http://www.w3.org/2000/svg'%3e %3cpath d='M0.0507022 16.0711L1.46491 17.4854L9.9502 9.00007L1.46492 0.514787L0.0507015 1.929L7.12177 9.00007L0.0507022 16.0711Z' fill='%23BCADF2' /%3e %3c/svg%3e">
|
<img src="data:image/svg+xml,%3csvg width='10' height='18' viewBox='0 0 10 18' fill='none' xmlns='http://www.w3.org/2000/svg'%3e %3cpath d='M0.0507022 16.0711L1.46491 17.4854L9.9502 9.00007L1.46492 0.514787L0.0507015 1.929L7.12177 9.00007L0.0507022 16.0711Z' fill='%23BCADF2' /%3e %3c/svg%3e">
|
||||||
</label>
|
</label>
|
||||||
<label class="navItem" @click="disconnectWallet">Log Out</label>
|
<label class="navItem" v-if="walletCollected" @click="disconnectWallet">Log Out</label>
|
||||||
<div class="navChild" :class="{'show': subShow}">
|
<div class="navChild" :class="{'show': subShow}">
|
||||||
<label class="navItem profile" @click="subShow=!subShow">
|
<label class="navItem profile" @click="subShow=!subShow">
|
||||||
<img class="arrowIcon" src="data:image/svg+xml,%3csvg width='10' height='18' viewBox='0 0 10 18' fill='none' xmlns='http://www.w3.org/2000/svg'%3e %3cpath d='M0.0507022 16.0711L1.46491 17.4854L9.9502 9.00007L1.46492 0.514787L0.0507015 1.929L7.12177 9.00007L0.0507022 16.0711Z' fill='%23BCADF2' /%3e %3c/svg%3e">
|
<img class="arrowIcon" src="data:image/svg+xml,%3csvg width='10' height='18' viewBox='0 0 10 18' fill='none' xmlns='http://www.w3.org/2000/svg'%3e %3cpath d='M0.0507022 16.0711L1.46491 17.4854L9.9502 9.00007L1.46492 0.514787L0.0507015 1.929L7.12177 9.00007L0.0507022 16.0711Z' fill='%23BCADF2' /%3e %3c/svg%3e">
|
||||||
@ -38,6 +38,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Component, Vue } from 'vue-property-decorator'
|
import { Component, Vue } from 'vue-property-decorator'
|
||||||
import { BlockChain } from '@/utils/blockchain'
|
import { BlockChain } from '@/utils/blockchain'
|
||||||
|
import { AppModule } from '@/store/modules/app'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
name: 'MobileTop',
|
name: 'MobileTop',
|
||||||
@ -49,6 +50,11 @@ export default class extends Vue {
|
|||||||
menuShow = false
|
menuShow = false
|
||||||
subShow = false
|
subShow = false
|
||||||
bc = new BlockChain();
|
bc = new BlockChain();
|
||||||
|
|
||||||
|
get walletCollected() {
|
||||||
|
return AppModule.walletConnected
|
||||||
|
}
|
||||||
|
|
||||||
toggleMenu() {
|
toggleMenu() {
|
||||||
this.menuShow = !this.menuShow
|
this.menuShow = !this.menuShow
|
||||||
if (!this.menuShow) {
|
if (!this.menuShow) {
|
||||||
|
@ -46,16 +46,20 @@
|
|||||||
import { Component, Vue } from 'vue-property-decorator'
|
import { Component, Vue } from 'vue-property-decorator'
|
||||||
import TopUserInfo from '@/components/market/TopUserInfo.vue'
|
import TopUserInfo from '@/components/market/TopUserInfo.vue'
|
||||||
import { BlockChain } from '@/utils/blockchain'
|
import { BlockChain } from '@/utils/blockchain'
|
||||||
|
import { AppModule } from '@/store/modules/app'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
name: 'Navbar',
|
name: 'Navbar',
|
||||||
components: { TopUserInfo }
|
components: { TopUserInfo }
|
||||||
})
|
})
|
||||||
export default class extends Vue {
|
export default class extends Vue {
|
||||||
walletCollected = false;
|
|
||||||
infoPanelShow = false
|
infoPanelShow = false
|
||||||
bc = new BlockChain();
|
bc = new BlockChain();
|
||||||
|
|
||||||
|
get walletCollected() {
|
||||||
|
return AppModule.walletConnected
|
||||||
|
}
|
||||||
|
|
||||||
async collectToWallet() {
|
async collectToWallet() {
|
||||||
return this.bc.connect()
|
return this.bc.connect()
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<div class="position dropdown anim">
|
<div class="position dropdown anim">
|
||||||
<span class="name">SEgGQ58HRlLd</span>
|
<span class="name">SEgGQ58HRlLd</span>
|
||||||
<div class="divCode">
|
<div class="divCode">
|
||||||
<span class="address">0x42448c...fc2c0231</span>
|
<span class="address">{{showAccount}}</span>
|
||||||
<img
|
<img
|
||||||
class="icCopy" width="24" height="24"
|
class="icCopy" width="24" height="24"
|
||||||
src="data:image/svg+xml,%3csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3e %3cpath d='M20 9H11C9.89543 9 9 9.89543 9 11V20C9 21.1046 9.89543 22 11 22H20C21.1046 22 22 21.1046 22 20V11C22 9.89543 21.1046 9 20 9Z' stroke='%23BCADF2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' /%3e %3cpath d='M5 15H4C3.46957 15 2.96086 14.7893 2.58579 14.4142C2.21071 14.0391 2 13.5304 2 13V4C2 3.46957 2.21071 2.96086 2.58579 2.58579C2.96086 2.21071 3.46957 2 4 2H13C13.5304 2 14.0391 2.21071 14.4142 2.58579C14.7893 2.96086 15 3.46957 15 4V5' stroke='%23BCADF2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' /%3e %3c/svg%3e">
|
src="data:image/svg+xml,%3csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3e %3cpath d='M20 9H11C9.89543 9 9 9.89543 9 11V20C9 21.1046 9.89543 22 11 22H20C21.1046 22 22 21.1046 22 20V11C22 9.89543 21.1046 9 20 9Z' stroke='%23BCADF2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' /%3e %3cpath d='M5 15H4C3.46957 15 2.96086 14.7893 2.58579 14.4142C2.21071 14.0391 2 13.5304 2 13V4C2 3.46957 2.21071 2.96086 2.58579 2.58579C2.96086 2.21071 3.46957 2 4 2H13C13.5304 2 14.0391 2.21071 14.4142 2.58579C14.7893 2.96086 15 3.46957 15 4V5' stroke='%23BCADF2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' /%3e %3c/svg%3e">
|
||||||
@ -33,6 +33,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Component, Vue } from 'vue-property-decorator'
|
import { Component, Vue } from 'vue-property-decorator'
|
||||||
import { BlockChain } from '@/utils/blockchain'
|
import { BlockChain } from '@/utils/blockchain'
|
||||||
|
import { AppModule } from '@/store/modules/app'
|
||||||
|
import { UserModule } from '@/store/modules/user'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
name: 'TopUserInfo',
|
name: 'TopUserInfo',
|
||||||
@ -41,6 +43,14 @@ import { BlockChain } from '@/utils/blockchain'
|
|||||||
export default class extends Vue {
|
export default class extends Vue {
|
||||||
bc = new BlockChain();
|
bc = new BlockChain();
|
||||||
|
|
||||||
|
get walletCollected() {
|
||||||
|
return AppModule.walletConnected
|
||||||
|
}
|
||||||
|
|
||||||
|
get showAccount() {
|
||||||
|
return UserModule.accountShow
|
||||||
|
}
|
||||||
|
|
||||||
async disconnectWallet() {
|
async disconnectWallet() {
|
||||||
return this.bc.disconnect()
|
return this.bc.disconnect()
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,14 @@ export enum DeviceType {
|
|||||||
export interface IAppState {
|
export interface IAppState {
|
||||||
device: DeviceType
|
device: DeviceType
|
||||||
size: string
|
size: string
|
||||||
|
walletConnected: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
@Module({ dynamic: true, store, name: 'app' })
|
@Module({ dynamic: true, store, name: 'app' })
|
||||||
class App extends VuexModule implements IAppState {
|
class App extends VuexModule implements IAppState {
|
||||||
public device = DeviceType.Desktop;
|
public device = DeviceType.Desktop;
|
||||||
public size = getSize() || 'medium'
|
public size = getSize() || 'medium'
|
||||||
|
public walletConnected = false;
|
||||||
|
|
||||||
@Action
|
@Action
|
||||||
public ToggleDevice(device: DeviceType) {
|
public ToggleDevice(device: DeviceType) {
|
||||||
@ -27,6 +29,11 @@ class App extends VuexModule implements IAppState {
|
|||||||
this.SET_SIZE(size)
|
this.SET_SIZE(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Action
|
||||||
|
public updateWalletStatus(val: boolean) {
|
||||||
|
this.SET_WALLETSTATUS(val)
|
||||||
|
}
|
||||||
|
|
||||||
@Mutation
|
@Mutation
|
||||||
private TOGGLE_DEVICE(device: DeviceType) {
|
private TOGGLE_DEVICE(device: DeviceType) {
|
||||||
this.device = device
|
this.device = device
|
||||||
@ -37,6 +44,11 @@ class App extends VuexModule implements IAppState {
|
|||||||
this.size = size
|
this.size = size
|
||||||
setSize(this.size)
|
setSize(this.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Mutation
|
||||||
|
private SET_WALLETSTATUS(val: boolean) {
|
||||||
|
this.walletConnected = val
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AppModule = getModule(App)
|
export const AppModule = getModule(App)
|
||||||
|
@ -19,6 +19,7 @@ export interface IUserState {
|
|||||||
permissions: string[][]
|
permissions: string[][]
|
||||||
level: number
|
level: number
|
||||||
sex?: string
|
sex?: string
|
||||||
|
account: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@Module({ dynamic: true, store, name: 'user' })
|
@Module({ dynamic: true, store, name: 'user' })
|
||||||
@ -32,6 +33,7 @@ class User extends VuexModule implements IUserState {
|
|||||||
public email = ''
|
public email = ''
|
||||||
public level = 999
|
public level = 999
|
||||||
public sex = '0'
|
public sex = '0'
|
||||||
|
public account = ''
|
||||||
|
|
||||||
@Action
|
@Action
|
||||||
public async Login(userInfo: { username: string, password: string }) {
|
public async Login(userInfo: { username: string, password: string }) {
|
||||||
@ -92,6 +94,16 @@ class User extends VuexModule implements IUserState {
|
|||||||
this.token = token
|
this.token = token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Mutation
|
||||||
|
private SET_ACCOUNT(account: string) {
|
||||||
|
this.account = account
|
||||||
|
}
|
||||||
|
|
||||||
|
@Action
|
||||||
|
public updateAccount(account: string) {
|
||||||
|
this.SET_ACCOUNT(account)
|
||||||
|
}
|
||||||
|
|
||||||
@Action
|
@Action
|
||||||
public async updatePageToken(token: string) {
|
public async updatePageToken(token: string) {
|
||||||
this.SET_TOKEN(token)
|
this.SET_TOKEN(token)
|
||||||
@ -134,6 +146,14 @@ class User extends VuexModule implements IUserState {
|
|||||||
}
|
}
|
||||||
this.permissions = results
|
this.permissions = results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get accountShow() {
|
||||||
|
if (this.account.length > 0) {
|
||||||
|
return this.account.substring(0, 8) + '...' + this.account.substring(this.account.length - 8)
|
||||||
|
} else {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const UserModule = getModule(User)
|
export const UserModule = getModule(User)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { singleton } from '@/decorators/singleton.decorator'
|
import { singleton } from '@/decorators/singleton.decorator'
|
||||||
import WalletConnectProvider from '@walletconnect/web3-provider'
|
import WalletConnectProvider from '@walletconnect/web3-provider'
|
||||||
|
import { AppModule } from '@/store/modules/app'
|
||||||
|
import { UserModule } from '@/store/modules/user'
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
|
|
||||||
@singleton
|
@singleton
|
||||||
@ -8,16 +10,20 @@ export class BlockChain {
|
|||||||
web3: Web3
|
web3: Web3
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
const rpc = { 97: process.env.VUE_APP_CHAIN_RPC! }
|
const chainId = parseInt(process.env.VUE_APP_CHAIN_ID!)
|
||||||
|
const rpc: any = { }
|
||||||
|
rpc[chainId] = process.env.VUE_APP_CHAIN_RPC!
|
||||||
this.provider = new WalletConnectProvider({
|
this.provider = new WalletConnectProvider({
|
||||||
infuraId: process.env.VUE_APP_WALLET_INFURAID,
|
infuraId: process.env.VUE_APP_WALLET_INFURAID,
|
||||||
chainId: parseInt(process.env.VUE_APP_CHAIN_ID!),
|
chainId,
|
||||||
rpc
|
rpc
|
||||||
})
|
})
|
||||||
console.log('wallet connected: ', this.isWalletConnect)
|
console.log('wallet connected: ', this.isWalletConnect)
|
||||||
|
AppModule.updateWalletStatus(this.isWalletConnect)
|
||||||
if (this.isWalletConnect) {
|
if (this.isWalletConnect) {
|
||||||
this.connect()
|
this.connect()
|
||||||
}
|
}
|
||||||
|
this.subscribeToEvents()
|
||||||
}
|
}
|
||||||
|
|
||||||
get isWalletConnect() {
|
get isWalletConnect() {
|
||||||
@ -28,6 +34,11 @@ export class BlockChain {
|
|||||||
// Enable session (triggers QR Code modal)
|
// Enable session (triggers QR Code modal)
|
||||||
await this.provider.enable()
|
await this.provider.enable()
|
||||||
this.web3 = new Web3(<any> this.provider)
|
this.web3 = new Web3(<any> this.provider)
|
||||||
|
const accounts = await this.web3.eth.getAccounts()
|
||||||
|
console.log('accountsLogin: ', accounts)
|
||||||
|
if (accounts && accounts.length > 0) {
|
||||||
|
UserModule.updateAccount(accounts[0])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async disconnect() {
|
public async disconnect() {
|
||||||
@ -37,7 +48,10 @@ export class BlockChain {
|
|||||||
public subscribeToEvents = () => {
|
public subscribeToEvents = () => {
|
||||||
// Subscribe to accounts change
|
// Subscribe to accounts change
|
||||||
this.provider.on('accountsChanged', (accounts: string[]) => {
|
this.provider.on('accountsChanged', (accounts: string[]) => {
|
||||||
console.log(accounts)
|
console.log('accountsChanged: ', accounts)
|
||||||
|
if (accounts && accounts.length > 0) {
|
||||||
|
UserModule.updateAccount(accounts[0])
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Subscribe to chainId change
|
// Subscribe to chainId change
|
||||||
|
Loading…
x
Reference in New Issue
Block a user