diff --git a/src/assets/market/cec-s.png b/src/assets/market/cec-s.png new file mode 100644 index 0000000..c7ae163 Binary files /dev/null and b/src/assets/market/cec-s.png differ diff --git a/src/assets/market/cec.png b/src/assets/market/cec.png index dd8db40..9f046b5 100644 Binary files a/src/assets/market/cec.png and b/src/assets/market/cec.png differ diff --git a/src/assets/market/ceg-s.png b/src/assets/market/ceg-s.png new file mode 100644 index 0000000..447e238 Binary files /dev/null and b/src/assets/market/ceg-s.png differ diff --git a/src/assets/market/ceg.png b/src/assets/market/ceg.png old mode 100755 new mode 100644 index b810afd..5ead7d1 Binary files a/src/assets/market/ceg.png and b/src/assets/market/ceg.png differ diff --git a/src/utils/ChainManager.ts b/src/chain/ChainManager.ts similarity index 95% rename from src/utils/ChainManager.ts rename to src/chain/ChainManager.ts index 8ddd480..aae21d8 100644 --- a/src/utils/ChainManager.ts +++ b/src/chain/ChainManager.ts @@ -1,5 +1,5 @@ import { singleton } from '@/decorators/singleton.decorator' -import { BlockChain } from '@/utils/blockchain' +import { Blockchain } from '@/chain/blockchain' import { getNonce } from '@/api/User' import { AppModule } from '@/store/modules/app' import { UserModule } from '@/store/modules/user' @@ -7,9 +7,9 @@ import { Message } from 'element-ui' @singleton export default class ChainManager { - bc: BlockChain + bc: Blockchain constructor() { - this.bc = new BlockChain() + this.bc = new Blockchain() // EventBus.$on(NEED_NONCE, this.checkNance.bind(this)) } diff --git a/src/utils/blockchain.ts b/src/chain/blockchain.ts similarity index 95% rename from src/utils/blockchain.ts rename to src/chain/blockchain.ts index 6a3afab..a6ba9a7 100644 --- a/src/utils/blockchain.ts +++ b/src/chain/blockchain.ts @@ -3,13 +3,7 @@ import WalletConnectProvider from '@walletconnect/web3-provider' import { AppModule } from '@/store/modules/app' import Web3 from 'web3' import { ERC20ABI, MALL_ADDRESS } from '@/configs/config_chain' -import { - ACCOUNT_CHANGE, - EventBus, NEED_CHANGE_CHAIN, - NEED_LOGIN, - NEED_NONCE, - SHOW_CHAIN_MODAL -} from '@/utils/event-bus' +import { EventBus, NEED_CHANGE_CHAIN, NEED_LOGIN, NEED_NONCE, SHOW_CHAIN_MODAL } from '@/utils/event-bus' import { UserModule } from '@/store/modules/user' import { chains, IChainData } from '@/configs/chains' import { isMobile } from '@/utils/resize' @@ -27,7 +21,7 @@ const EIP721_DOMAIN_DATA = [ const CACHE_KEY = 'cebg_chain_cache_key' @singleton -export class BlockChain { +export class Blockchain { provider:any web3: Web3 currentChain = 0 @@ -216,7 +210,7 @@ export class BlockChain { ) } - private async getCoinInstance(address: string) { + public async getCoinInstance(address: string) { if (this.coinInstanceMap.has(address)) { return this.coinInstanceMap.get(address) } else { @@ -261,6 +255,7 @@ export class BlockChain { await this.provider?.disconnect() this.currentChain = 0 this.walletType = 0 + this.coinInstanceMap.clear() this.clearCachedProvider() AppModule.updateStep(0) AppModule.updateNonce('') @@ -375,10 +370,16 @@ export class BlockChain { console.log('increaseAllowance: ', res) } - public parsePrice(price: number, decimals: number) { - const v = Math.pow(10, decimals) - const priceStr = (price / v) + '' - return this.web3.utils.toWei(priceStr) + /** + * 获取某种币的余额 + * @param {string} address + * @param {string | null} account + * @return {Promise} + */ + 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) { diff --git a/src/components/index/DesktopHeader.vue b/src/components/index/DesktopHeader.vue index 493adef..ccf0f5a 100644 --- a/src/components/index/DesktopHeader.vue +++ b/src/components/index/DesktopHeader.vue @@ -30,7 +30,7 @@ import { Component, Vue } from 'vue-property-decorator' import { AppModule } from '@/store/modules/app' import { UserModule } from '@/store/modules/user' -import ChainManager from '@/utils/ChainManager' +import ChainManager from '@/chain/ChainManager' declare module 'vue/types/vue' { interface Vue { diff --git a/src/components/main/MainHeader.vue b/src/components/main/MainHeader.vue index 4aebf55..7253890 100644 --- a/src/components/main/MainHeader.vue +++ b/src/components/main/MainHeader.vue @@ -69,9 +69,8 @@ + diff --git a/src/components/market/wallet/WalletPanel.vue b/src/components/market/wallet/WalletPanel.vue index 6b1096d..f693703 100644 --- a/src/components/market/wallet/WalletPanel.vue +++ b/src/components/market/wallet/WalletPanel.vue @@ -4,9 +4,13 @@
Wallet
-
0x42448c...fc2c0231 +
{{showAccount}} icCopy
@@ -17,6 +21,7 @@
+
@@ -26,10 +31,14 @@ import { Component, Vue } from 'vue-property-decorator' import TotalBalance from '@/components/market/wallet/TotalBalance.vue' import CoinCard, { ICoinData } from '@/components/market/wallet/CoinCard.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({ name: 'WalletPanel', components: { + PlaceholderPanel, GameCoinCard, CoinCard, TotalBalance @@ -69,6 +78,34 @@ export default class WalletPanel extends Vue { 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 + }) + } }