From 69c04c4cce96c8eb31ea50c1a872d76690044434 Mon Sep 17 00:00:00 2001 From: Kalovelo Date: Fri, 15 Jul 2022 11:32:58 +0300 Subject: [PATCH] refactor(client): use channel in store --- client/src/App.vue | 25 ++++-- .../src/components/ChannelInitialization.vue | 6 +- client/src/components/Header.vue | 15 ++-- client/src/components/PlayerInfo.vue | 12 ++- client/src/components/TransactionsList.vue | 5 +- client/src/sdk/sdkService.ts | 89 +++++++++++-------- client/src/stores/channel.ts | 20 ++--- client/tests/player-info.test.ts | 7 +- server/src/services/bot/bot.service.ts | 6 +- 9 files changed, 107 insertions(+), 78 deletions(-) diff --git a/client/src/App.vue b/client/src/App.vue index 5fccaa2..c4789dd 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -5,20 +5,27 @@ import Header from './components/Header.vue'; import RockPaperScissor from './components/RockPaperScissor.vue'; import PopUp from './components/PopUp.vue'; import { useChannelStore } from './stores/channel'; -import { onBeforeUnmount, shallowRef } from 'vue'; -import { returnCoinsToFaucet } from './sdk/sdk'; -import { SdkService } from './sdk/sdkService'; +import { onBeforeUnmount, onMounted, toRaw } from 'vue'; +import { getSdk, returnCoinsToFaucet } from './sdk/sdk'; +import { ChannelService } from './sdk/sdkService'; +import { AeSdk } from '@aeternity/aepp-sdk'; const channelStore = useChannelStore(); -const sdkService = shallowRef(new SdkService()); async function initChannel() { - await sdkService.value.initializeChannel(); + if (!channelStore.channelService) { + throw new Error('SDK is not initialized'); + } + await channelStore.channelService.initializeChannel(); } +onMounted(async () => { + channelStore.channelService = new ChannelService(await getSdk()); +}); + onBeforeUnmount(async () => { - if (sdkService.value.sdk) { - await returnCoinsToFaucet(sdkService.value.sdk); + if (channelStore.channelService?.sdk) { + await returnCoinsToFaucet(toRaw(channelStore.channelService.sdk) as AeSdk); } }); @@ -27,10 +34,10 @@ onBeforeUnmount(async () => {
- + diff --git a/client/src/components/ChannelInitialization.vue b/client/src/components/ChannelInitialization.vue index d0805f3..4a9c80a 100644 --- a/client/src/components/ChannelInitialization.vue +++ b/client/src/components/ChannelInitialization.vue @@ -15,8 +15,8 @@ const title = computed(() => ); const errorMessage = computed(() => - channelStore.error - ? `Error ${channelStore.error.status}: ${channelStore.error.statusText}, ${channelStore.error.message}` + channelStore.channelService?.error + ? `Error ${channelStore.channelService?.error.status}: ${channelStore.channelService?.error.statusText}, ${channelStore.channelService?.error.message}` : '' ); @@ -54,7 +54,7 @@ async function openStateChannel(): Promise { text="Start game" /> - +

{{ errorMessage }}

diff --git a/client/src/components/Header.vue b/client/src/components/Header.vue index de8fa90..3b97a1f 100644 --- a/client/src/components/Header.vue +++ b/client/src/components/Header.vue @@ -1,15 +1,20 @@ diff --git a/client/src/components/PlayerInfo.vue b/client/src/components/PlayerInfo.vue index cea79fb..afb2768 100644 --- a/client/src/components/PlayerInfo.vue +++ b/client/src/components/PlayerInfo.vue @@ -1,7 +1,9 @@ @@ -9,7 +11,7 @@ defineProps<{
{{ name }} {{ balance }} ae{{ balance.dividedBy(1e18) }} ae
@@ -27,8 +29,10 @@ defineProps<{ } .balance { - font-size: 20px; - color: #de3f6b; + font-size: 30px; + text-align: right; + font-weight: 500; + color: var(--pink); } } diff --git a/client/src/components/TransactionsList.vue b/client/src/components/TransactionsList.vue index 7fdcf50..196ceed 100644 --- a/client/src/components/TransactionsList.vue +++ b/client/src/components/TransactionsList.vue @@ -2,10 +2,9 @@ import { computed, ref } from 'vue'; import { useChannelStore } from '../stores/channel'; import SingleTransaction, { Transaction } from './SingleTransaction.vue'; - const transactions = ref([]); const channelStore = useChannelStore(); -const isMinimized = computed(() => !channelStore.channelIsOpen); +const isMinimized = computed(() => !channelStore.channelService?.isOpen);