Skip to content

Commit

Permalink
fix(client): remove reconnecting prefix showing on reload
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalovelo committed Sep 5, 2022
1 parent 01b94e8 commit d7e45b2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ describe('Open State Channel Button', () => {
});

it('should have `Reconnecting` title when there is a stored gameState', async () => {
localStorage.setItem('gameState', '{}');
localStorage.setItem(
'gameState',
JSON.stringify({
keypair: {},
channelRound: 10,
contractCreationChannelRound: 1,
})
);
const channelComp = render(ChannelInitialization, {
global: {
plugins: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import { default as Button } from '../generic-button/generic-button.vue';
import LoadingAnimation from '../loading-animation/loading-animation.vue';
import { useChannelStore } from '../../stores/channel';
import ToggleButton from '../toggle-button/toggle-button.vue';
import { getSavedState } from '../../utils/local-storage/local-storage';
const channelStore = useChannelStore();
const openChannelInitiated = ref(false);
const hasSavedState = ref(!!localStorage.getItem('gameState'));
const hasSavedState = computed(() => {
const savedState = getSavedState();
// in case user was in action, we're clearing the localStorage
// and we consider reconnecting unavailable.
return savedState && !savedState?.gameRound?.userInAction;
});
const channelIsOpening = computed(
() => channelStore.channel?.isOpening || openChannelInitiated.value
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ async function makeSelection(selection: Selections) {
}
function closeChannel() {
localStorage.clear();
channelIsClosing.value = true;
gameChannel.channel?.closeChannel();
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/utils/game-channel/game-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export class GameChannel {
}

async closeChannel() {
localStorage.clear();
if (!this.channelInstance) {
throw new Error('Channel is not open');
}
Expand All @@ -264,7 +265,6 @@ export class GameChannel {
await channelClosing.then(async (canClose) => {
if (!canClose) return;
this.channelIsClosing = true;
localStorage.clear();
await this.getChannelWithoutProxy()
.shutdown((tx: Encoded.Transaction) => this.signTx('channel_close', tx))
.then(async () => {
Expand Down

0 comments on commit d7e45b2

Please sign in to comment.