Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(solana): error popup shows whenever an error occurs to prevent infinite loading #3062

Merged
merged 9 commits into from
May 18, 2022
Merged
21 changes: 21 additions & 0 deletions components/ui/Popups/ErrorNetwork/ErrorNetwork.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="error-network-container">
<div class="modal-body">
<div class="custom-modal-content">
<img src="~/assets/svg/mascot/sad_curious.svg" class="mascot" />
<TypographyTitle :text="$t('popups.error_network.title')" class="title" />
<TypographyText
:text="$t('popups.error_network.subtitle')"
:size="6"
class="subtitle"
/>
<InteractablesButton type="primary" class="action" :action="tryAgain">
<refresh-cw-icon size="1.5x" />
<TypographyText
:text="$t('popups.error_network.action')"
:size="6"
class="text"
/>
</InteractablesButton>
</div>
</div>
</div>
45 changes: 45 additions & 0 deletions components/ui/Popups/ErrorNetwork/ErrorNetwork.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.error-network-container {
&:extend(.modal-gradient);
padding: 1rem;

.modal-body {
.custom-modal-content {
padding: 0 1rem;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;

.title {
font-size: 1.9rem;
color: @secondary-text;
margin-top: 2rem;
text-align: center;
}

.subtitle {
color: @secondary-text;
margin-top: 0.5rem;
}

.mascot {
width: 15rem;
height: 15rem;
}

.action {
width: 100%;

.text {
margin: 0 0.5rem;
}
}
}
}
}

@media only screen and (min-width: @mobile-breakpoint) {
.error-network-container {
max-width: 550px;
}
}
56 changes: 56 additions & 0 deletions components/ui/Popups/ErrorNetwork/ErrorNetwork.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<template src="./ErrorNetwork.html" />

<script>
import Vue from 'vue'
import { mapState } from 'vuex'
import { throttle } from 'lodash'

import { RefreshCwIcon } from 'satellite-lucide-icons'

import { Config } from '~/config'

/**
* @component Error
* @description Component that takes an error message to display including source and extra details.
* setTimeout prop is a bool that if true will auto close the modal after 5 seconds
* @example
*/
export default Vue.extend({
name: 'ErrorNetwork',
components: {
RefreshCwIcon,
},
watch: {
$route(to, from) {
if (to !== from) {
this.closeNetworkErrorPopup()
}
},
},
methods: {
/**
* @method toggleNetworkErrorPopup
* @description
* @example
*/
closeNetworkErrorPopup() {
this.$store.commit('ui/toggleErrorNetworkModal', {
state: false,
action: null,
})
},
/**
* @method tryAgain
* @description
* @example
*/
tryAgain: throttle(function () {
this.$store.state.ui.modals.errorNetwork.action()
this.closeNetworkErrorPopup()
}, Config.modal.errorNetworkActionThrottle),
},
})
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" src="./ErrorNetwork.less"></style>
3 changes: 3 additions & 0 deletions config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,7 @@ export const Config = {
android: 10836, // lowest android value, some phones can handle more
electron: 11180, // including for completeness sake
},
modal: {
errorNetworkActionThrottle: 1000,
},
}
3 changes: 3 additions & 0 deletions layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<div id="app" :class="$store.state.ui.theme.base.class">
<UiModal v-if="$store.state.ui.modals.errorNetwork.isOpen" nopad>
<UiPopupsErrorNetwork />
</UiModal>
<Nuxt />
<!-- Sets the global css variable for the theme flair color -->
<v-style>
Expand Down
6 changes: 6 additions & 0 deletions locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ export default {
contact:
'Oops! Something went wrong! Help us improve your experience by sending an error report',
},
error_network: {
title: 'Oops! Please Stand By',
subtitle:
"We're currently in our Alpha stage and working hard on connecting you to a satellite. It looks like we're having some technical issues at the moment. Please re-enter your pin to connect or try again later.",
action: 'Try Again',
},
},
files: {
files: 'Files',
Expand Down
23 changes: 18 additions & 5 deletions pages/auth/register/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,30 @@ export default Vue.extend({
},
watch: {
allPrerequisitesReady(nextValue) {
console.log(nextValue)
if (!nextValue) return
this.$router.replace('/chat/direct')
},
},
mounted() {
if (this.allPrerequisitesReady) {
this.$router.replace('/chat/direct')
}
},
methods: {
async confirm(userData: UserRegistrationData) {
this.$store.dispatch('accounts/registerUser', {
name: userData.username,
image: userData.photoHash,
status: userData.status,
})
try {
await this.$store.dispatch('accounts/registerUser', {
name: userData.username,
image: userData.photoHash,
status: userData.status,
})
} catch (error: any) {
this.$store.commit('ui/toggleErrorNetworkModal', {
state: true,
action: () => this.confirm(userData),
})
}
},
},
})
Expand Down
7 changes: 7 additions & 0 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,17 @@ export default Vue.extend({
} catch (error: any) {
if (error.message === AccountsError.USER_NOT_REGISTERED) {
this.$router.replace('/auth/register')
return
}
if (error.message === AccountsError.USER_DERIVATION_FAILED) {
this.$router.replace('/setup/disclaimer')
return
}

this.$store.commit('ui/toggleErrorNetworkModal', {
state: true,
action: this.loadAccount,
})
}
},
},
Expand Down
4 changes: 4 additions & 0 deletions store/ui/__snapshots__/state.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ Object {
"creategroup": false,
"crop": false,
"error": false,
"errorNetwork": Object {
"action": null,
"isOpen": false,
},
"glyph": false,
"groupInvite": Object {
"isOpen": false,
Expand Down
7 changes: 7 additions & 0 deletions store/ui/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ export default {
// @ts-ignore
state.modals[modal.name] = modal.state
},
toggleErrorNetworkModal(
state: UIState,
modal: { state: boolean; action: Function | null },
) {
// @ts-ignore
state.modals.errorNetwork = { isOpen: modal.state, action: modal.action }
},
setGlyphModalPack(state: UIState, pack: string) {
state.glyphModalPack = pack
},
Expand Down
1 change: 1 addition & 0 deletions store/ui/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const InitialUIState = (): UIState => ({
callToAction: false,
renameFile: false,
crop: false,
errorNetwork: { isOpen: false, action: null },
},
glyphModalPack: '',
chatbarContent: '',
Expand Down
2 changes: 1 addition & 1 deletion store/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export interface UIState {
showSearchResult: boolean
showSidebar: boolean
modals: {
[key: string]: boolean
[key: string]: boolean | object
}
glyphModalPack: string
chatbarContent: string
Expand Down