调整一些跟链有关的功能和界面

This commit is contained in:
cebgcontract 2022-03-15 16:06:32 +08:00
parent 134885f8d5
commit b97f45243e
17 changed files with 130 additions and 51 deletions

BIN
src/assets/market/cec-s.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 16 KiB

BIN
src/assets/market/ceg-s.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
src/assets/market/ceg.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -1,5 +1,5 @@
import { singleton } from '@/decorators/singleton.decorator' import { singleton } from '@/decorators/singleton.decorator'
import { BlockChain } from '@/utils/blockchain' import { Blockchain } from '@/chain/blockchain'
import { getNonce } from '@/api/User' import { getNonce } from '@/api/User'
import { AppModule } from '@/store/modules/app' import { AppModule } from '@/store/modules/app'
import { UserModule } from '@/store/modules/user' import { UserModule } from '@/store/modules/user'
@ -7,9 +7,9 @@ import { Message } from 'element-ui'
@singleton @singleton
export default class ChainManager { export default class ChainManager {
bc: BlockChain bc: Blockchain
constructor() { constructor() {
this.bc = new BlockChain() this.bc = new Blockchain()
// EventBus.$on(NEED_NONCE, this.checkNance.bind(this)) // EventBus.$on(NEED_NONCE, this.checkNance.bind(this))
} }

View File

@ -3,13 +3,7 @@ import WalletConnectProvider from '@walletconnect/web3-provider'
import { AppModule } from '@/store/modules/app' import { AppModule } from '@/store/modules/app'
import Web3 from 'web3' import Web3 from 'web3'
import { ERC20ABI, MALL_ADDRESS } from '@/configs/config_chain' import { ERC20ABI, MALL_ADDRESS } from '@/configs/config_chain'
import { import { EventBus, NEED_CHANGE_CHAIN, NEED_LOGIN, NEED_NONCE, SHOW_CHAIN_MODAL } from '@/utils/event-bus'
ACCOUNT_CHANGE,
EventBus, NEED_CHANGE_CHAIN,
NEED_LOGIN,
NEED_NONCE,
SHOW_CHAIN_MODAL
} from '@/utils/event-bus'
import { UserModule } from '@/store/modules/user' import { UserModule } from '@/store/modules/user'
import { chains, IChainData } from '@/configs/chains' import { chains, IChainData } from '@/configs/chains'
import { isMobile } from '@/utils/resize' import { isMobile } from '@/utils/resize'
@ -27,7 +21,7 @@ const EIP721_DOMAIN_DATA = [
const CACHE_KEY = 'cebg_chain_cache_key' const CACHE_KEY = 'cebg_chain_cache_key'
@singleton @singleton
export class BlockChain { export class Blockchain {
provider:any provider:any
web3: Web3 web3: Web3
currentChain = 0 currentChain = 0
@ -216,7 +210,7 @@ export class BlockChain {
) )
} }
private async getCoinInstance(address: string) { public async getCoinInstance(address: string) {
if (this.coinInstanceMap.has(address)) { if (this.coinInstanceMap.has(address)) {
return this.coinInstanceMap.get(address) return this.coinInstanceMap.get(address)
} else { } else {
@ -261,6 +255,7 @@ export class BlockChain {
await this.provider?.disconnect() await this.provider?.disconnect()
this.currentChain = 0 this.currentChain = 0
this.walletType = 0 this.walletType = 0
this.coinInstanceMap.clear()
this.clearCachedProvider() this.clearCachedProvider()
AppModule.updateStep(0) AppModule.updateStep(0)
AppModule.updateNonce('') AppModule.updateNonce('')
@ -375,10 +370,16 @@ export class BlockChain {
console.log('increaseAllowance: ', res) console.log('increaseAllowance: ', res)
} }
public parsePrice(price: number, decimals: number) { /**
const v = Math.pow(10, decimals) *
const priceStr = (price / v) + '' * @param {string} address
return this.web3.utils.toWei(priceStr) * @param {string | null} account
* @return {Promise<any>}
*/
public async getBalance(address: string, account: string | null) {
account = account || AppModule.accountId
const coinInstance: any = this.getCoinInstance(address)
return await coinInstance.methods.balanceOf(account).call()
} }
public async signData(signObj: any, signer: string) { public async signData(signObj: any, signer: string) {

View File

@ -30,7 +30,7 @@
import { Component, Vue } from 'vue-property-decorator' import { Component, Vue } from 'vue-property-decorator'
import { AppModule } from '@/store/modules/app' import { AppModule } from '@/store/modules/app'
import { UserModule } from '@/store/modules/user' import { UserModule } from '@/store/modules/user'
import ChainManager from '@/utils/ChainManager' import ChainManager from '@/chain/ChainManager'
declare module 'vue/types/vue' { declare module 'vue/types/vue' {
interface Vue { interface Vue {

View File

@ -69,9 +69,8 @@
<script lang="ts"> <script lang="ts">
import { Component, Vue } from 'vue-property-decorator' import { Component, Vue } from 'vue-property-decorator'
import { AppModule } from '@/store/modules/app' import { AppModule } from '@/store/modules/app'
import { BlockChain } from '@/utils/blockchain'
import { UserModule } from '@/store/modules/user' import { UserModule } from '@/store/modules/user'
import { getNonce } from '@/api/User' import ChainManager from '@/chain/ChainManager'
declare module 'vue/types/vue' { declare module 'vue/types/vue' {
interface Vue { interface Vue {
@ -87,7 +86,7 @@ declare module 'vue/types/vue' {
}) })
export default class extends Vue { export default class extends Vue {
private dropShow = false private dropShow = false
bc = new BlockChain(); chainManager = new ChainManager()
changeSection(e: PointerEvent) { changeSection(e: PointerEvent) {
this.dropShow = false this.dropShow = false
@ -98,23 +97,11 @@ export default class extends Vue {
} }
async disconnectWallet() { async disconnectWallet() {
return this.bc.disconnect() return this.chainManager.logout()
} }
async collectToWallet() { async collectToWallet() {
await this.bc.connect() return this.chainManager.login()
const preRequest: any = await getNonce({
account: AppModule.accountId,
net_id: AppModule.chainId
})
if (!preRequest.token_state) {
await UserModule.Login({
bcInstance: this.bc,
account: AppModule.accountId,
chainId: AppModule.chainId,
nonce: preRequest.nonce
})
}
} }
get logined() { get logined() {

View File

@ -29,7 +29,7 @@ import { EventBus, PRESALE_BEGIN, PRESALE_ERROR, PRESALE_ORDER_GET, PRESALE_SUCC
import { ElLoadingComponent } from 'element-ui/types/loading' import { ElLoadingComponent } from 'element-ui/types/loading'
import TimeLoader from '@/components/main/TimeLoader.vue' import TimeLoader from '@/components/main/TimeLoader.vue'
import { UserModule } from '@/store/modules/user' import { UserModule } from '@/store/modules/user'
import ChainManager from '@/utils/ChainManager' import ChainManager from '@/chain/ChainManager'
@Component({ @Component({
name: 'NftSection', name: 'NftSection',

View File

@ -25,7 +25,8 @@ import { AppModule } from '@/store/modules/app'
import { buyBox } from '@/api/Mall' import { buyBox } from '@/api/Mall'
import { EventBus, PRESALE_BEGIN, PRESALE_ERROR, PRESALE_ORDER_GET } from '@/utils/event-bus' import { EventBus, PRESALE_BEGIN, PRESALE_ERROR, PRESALE_ORDER_GET } from '@/utils/event-bus'
import { UserModule } from '@/store/modules/user' import { UserModule } from '@/store/modules/user'
import ChainManager from '@/utils/ChainManager' import ChainManager from '@/chain/ChainManager'
import { parsePrice, formatPrice } from '@/utils/chain.util'
declare module 'vue/types/vue' { declare module 'vue/types/vue' {
interface Vue { interface Vue {
@ -60,8 +61,15 @@ export default class extends Vue {
} }
get priceShow() { get priceShow() {
const v = Math.pow(10, this.data.decimals!) if (this.data?.price ) {
return (this.data.price! / v).toFixed(3) if (this.data?.decimals) {
return formatPrice(this.data.price, this.data.decimals, 2)
} else {
return this.data.price
}
} else {
return '-'
}
} }
get accountId() { get accountId() {
@ -102,7 +110,7 @@ export default class extends Vue {
EventBus.$emit(PRESALE_BEGIN) EventBus.$emit(PRESALE_BEGIN)
const account = AppModule.accountId const account = AppModule.accountId
try { try {
const price = this.chainManger.bc.parsePrice(this.data.priceDiscount!, this.data.decimals!) const price = parsePrice(this.data.priceDiscount!, this.data.decimals!)
const { nonce, signature } = await this.chainManger.bc.signPresale({ const { nonce, signature } = await this.chainManger.bc.signPresale({
type: this.data.recordId!, type: this.data.recordId!,
paymentTokenAddress: this.data.coinAddress!, paymentTokenAddress: this.data.coinAddress!,

View File

@ -13,13 +13,13 @@
<a class="menu-item" href="/"> <a class="menu-item" href="/">
<div class="item" >Home</div> <div class="item" >Home</div>
</a> </a>
<a class="menu-item" href="" @click.stop="comingSoon"> <a class="menu-item" href="javascript:void(0)" @click.stop="comingSoon">
<div class="item" :class="{'active': currentTab==='official'}"> <div class="item" :class="{'active': currentTab==='official'}">
Official Shop Official Shop
<div class="active-bottom" v-if="currentTab==='official'"></div> <div class="active-bottom" v-if="currentTab==='official'"></div>
</div> </div>
</a> </a>
<a class="menu-item" href="" @click.stop="comingSoon"> <a class="menu-item" href="javascript:void(0)" @click.stop="comingSoon">
<div class="item " :class="{'active': currentTab==='market'}"> <div class="item " :class="{'active': currentTab==='market'}">
Marketplace Marketplace
<div class="active-bottom" v-if="currentTab==='market'"></div> <div class="active-bottom" v-if="currentTab==='market'"></div>
@ -93,7 +93,7 @@
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 { AppModule, DeviceType } from '@/store/modules/app' import { AppModule, DeviceType } from '@/store/modules/app'
import ChainManager from '@/utils/ChainManager' import ChainManager from '@/chain/ChainManager'
import { UserModule } from '@/store/modules/user' import { UserModule } from '@/store/modules/user'
import AnimMenu from '@/components/core/AnimMenu.vue' import AnimMenu from '@/components/core/AnimMenu.vue'

View File

@ -37,16 +37,16 @@
<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 { AppModule } from '@/store/modules/app' import { AppModule } from '@/store/modules/app'
import VueClipboard from 'vue-clipboard2' import VueClipboard from 'vue-clipboard2'
import ChainManager from '@/chain/ChainManager'
@Component({ @Component({
name: 'TopUserInfo', name: 'TopUserInfo',
components: {} components: {}
}) })
export default class extends Vue { export default class extends Vue {
bc = new BlockChain(); chainManager = new ChainManager()
close(e: any) { close(e: any) {
console.log(e) console.log(e)
this.$emit('close-self') this.$emit('close-self')
@ -69,7 +69,7 @@ export default class extends Vue {
} }
async disconnectWallet() { async disconnectWallet() {
return this.bc.disconnect() return this.chainManager.logout()
} }
onCopy(e: any) { onCopy(e: any) {

View File

@ -31,7 +31,8 @@ import { AppModule } from '@/store/modules/app'
import { buyBox } from '@/api/Mall' import { buyBox } from '@/api/Mall'
import { EventBus, PRESALE_BEGIN, PRESALE_ERROR, PRESALE_ORDER_GET } from '@/utils/event-bus' import { EventBus, PRESALE_BEGIN, PRESALE_ERROR, PRESALE_ORDER_GET } from '@/utils/event-bus'
import { UserModule } from '@/store/modules/user' import { UserModule } from '@/store/modules/user'
import ChainManager from '@/utils/ChainManager' import ChainManager from '@/chain/ChainManager'
import { parsePrice } from '@/utils/chain.util'
declare module 'vue/types/vue' { declare module 'vue/types/vue' {
interface Vue { interface Vue {
@ -101,7 +102,7 @@ export default class HeroNft extends Vue {
EventBus.$emit(PRESALE_BEGIN) EventBus.$emit(PRESALE_BEGIN)
const account = AppModule.accountId const account = AppModule.accountId
try { try {
const price = this.chainManger.bc.parsePrice(this.data.priceDiscount!, this.data.decimals!) const price = parsePrice(this.data.priceDiscount!, this.data.decimals!)
const { nonce, signature } = await this.chainManger.bc.signPresale({ const { nonce, signature } = await this.chainManger.bc.signPresale({
type: this.data.recordId!, type: this.data.recordId!,
paymentTokenAddress: this.data.coinAddress!, paymentTokenAddress: this.data.coinAddress!,

View File

@ -0,0 +1,26 @@
<template>
<div class="placeholder-card" v-if="!mobile">
</div>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { AppModule, DeviceType } from '@/store/modules/app'
@Component({
name: 'PlaceholderPanel',
components: {
}
})
export default class PlaceholderPanel extends Vue {
get mobile() {
return AppModule.device === DeviceType.Mobile
}
}
</script>
<style lang="scss" scoped>
.placeholder-card{
width: 25em;
height: 12.125em;
}
</style>

View File

@ -4,9 +4,13 @@
<div class="label">Wallet</div> <div class="label">Wallet</div>
</div> </div>
<div class="horizonalBar"></div> <div class="horizonalBar"></div>
<div class="code"><span class="uuid">0x42448c...fc2c0231</span> <div class="code"><span class="uuid">{{showAccount}}</span>
<img <img
class="icCopy" width="16" height="16" class="icCopy" width="16" height="16"
v-clipboard:copy="account"
v-clipboard:success="onCopy"
v-clipboard:error="onCopyError"
alt="icCopy"
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">
</div> </div>
<div class="wallet"> <div class="wallet">
@ -17,6 +21,7 @@
</div> </div>
<div class="horizonalBar"></div> <div class="horizonalBar"></div>
<div class="wallet"> <div class="wallet">
<placeholder-panel></placeholder-panel>
<game-coin-card v-for="d in gameCoinList" :coin-data="d" :key="d.symbol"></game-coin-card> <game-coin-card v-for="d in gameCoinList" :coin-data="d" :key="d.symbol"></game-coin-card>
</div> </div>
</div> </div>
@ -26,10 +31,14 @@ import { Component, Vue } from 'vue-property-decorator'
import TotalBalance from '@/components/market/wallet/TotalBalance.vue' import TotalBalance from '@/components/market/wallet/TotalBalance.vue'
import CoinCard, { ICoinData } from '@/components/market/wallet/CoinCard.vue' import CoinCard, { ICoinData } from '@/components/market/wallet/CoinCard.vue'
import GameCoinCard from '@/components/market/wallet/GameCoinCard.vue' import GameCoinCard from '@/components/market/wallet/GameCoinCard.vue'
import { AppModule } from '@/store/modules/app'
import VueClipboard from 'vue-clipboard2'
import PlaceholderPanel from '@/components/market/wallet/PlaceholderPanel.vue'
@Component({ @Component({
name: 'WalletPanel', name: 'WalletPanel',
components: { components: {
PlaceholderPanel,
GameCoinCard, GameCoinCard,
CoinCard, CoinCard,
TotalBalance TotalBalance
@ -69,6 +78,34 @@ export default class WalletPanel extends Vue {
price: 100 price: 100
} }
] ]
beforeMount() {
Vue.use(VueClipboard)
}
get showAccount() {
return AppModule.accountShow
}
get account() {
return AppModule.accountId
}
onCopy(e: any) {
this.$message({
message: 'You just copied accountId',
type: 'success',
duration: 5 * 1000
})
}
onCopyError(e: any) {
this.$message({
message: 'Failed to copy texts',
type: 'error',
duration: 5 * 1000
})
}
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -27,7 +27,7 @@
import { Component, Vue } from 'vue-property-decorator' import { Component, Vue } from 'vue-property-decorator'
import { AppModule } from '@/store/modules/app' import { AppModule } from '@/store/modules/app'
import { UserModule } from '@/store/modules/user' import { UserModule } from '@/store/modules/user'
import ChainManager from '@/utils/ChainManager' import ChainManager from '@/chain/ChainManager'
import AnimMenu from '@/components/core/AnimMenu.vue' import AnimMenu from '@/components/core/AnimMenu.vue'
@Component({ @Component({

View File

@ -3,8 +3,8 @@ export function verifyInjectedProvider(check: string): boolean {
return window.ethereum return window.ethereum
? window.ethereum[check] ? window.ethereum[check]
: window.web3 && : window.web3 &&
window.web3.currentProvider && window.web3.currentProvider &&
window.web3.currentProvider[check] window.web3.currentProvider[check]
} }
/** /**
@ -18,3 +18,22 @@ export function hasMetamask(): boolean {
return false return false
} }
} }
export function parsePrice(price: number, decimals: number) {
const n = 19 - decimals
return price + new Array(n).join('0')
}
export function formatPrice(price: number|string, decimals: number, fixed: number = 2) {
var str = price + ''
var length = str.length
str = str.padStart(decimals, '0')
if (decimals >= length) {
str = '0.'+str
} else {
var pos = length - decimals
str = str.slice(0, pos) + '.' + str.slice(pos);
}
str = str.slice(0, str.lastIndexOf('.') + fixed + 1)
return str.replace(/0+$/, '').replace(/\.+$/, '')
}