default.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <div class="wrapper">
  3. <Navbar />
  4. <div v-show="mismatchNetwork" class="network has-background-warning">
  5. {{ $t('pleaseChangeNetwork', { network: netId }) }}
  6. <b-button type="is-warning is-dark" class="ml-3" @click="changeNetwork">{{
  7. $t('changeNetwork')
  8. }}</b-button>
  9. </div>
  10. <section class="main-content section">
  11. <div class="container">
  12. <nuxt />
  13. </div>
  14. </section>
  15. <Footer />
  16. <Loader />
  17. <Notices />
  18. <v-idle
  19. v-if="isSetupAccount && !isOpen"
  20. v-show="false"
  21. :loop="true"
  22. :duration="300"
  23. @idle="handleOpenModal"
  24. />
  25. </div>
  26. </template>
  27. <script>
  28. /* eslint-disable no-console */
  29. import { mapGetters, mapActions } from 'vuex'
  30. import Navbar from '@/components/Navbar'
  31. import Footer from '@/components/Footer'
  32. import Loader from '@/components/Loaders/Loader'
  33. import Settings from '@/components/Settings'
  34. import Notices from '@/components/Notices'
  35. import { openConfirmModal } from '@/modules/account'
  36. import NetworkModal from '@/components/NetworkModal'
  37. export default {
  38. middleware: 'provider',
  39. components: {
  40. Navbar,
  41. Footer,
  42. Loader,
  43. Notices
  44. },
  45. data() {
  46. return {
  47. isOpen: false
  48. }
  49. },
  50. computed: {
  51. ...mapGetters('encryptedNote', ['isSetupAccount']),
  52. ...mapGetters('metamask', ['netId', 'mismatchNetwork']),
  53. ...mapGetters('encryptedNote', ['accounts'])
  54. },
  55. watch: {
  56. netId(value, oldValue) {
  57. if (value !== oldValue) {
  58. this.checkRecoveryKey()
  59. }
  60. }
  61. },
  62. created() {
  63. this.checkRecoveryKey()
  64. this.newNotify()
  65. this.$store.dispatch('gasPrices/setDefault')
  66. },
  67. mounted() {
  68. this.$preventMultitabs()
  69. window.addEventListener('focus', this.$preventMultitabs)
  70. if (process.browser) {
  71. window.onNuxtReady(() => {
  72. setTimeout(async () => {
  73. await this.selectRpc({ netId: this.netId, action: this.checkCurrentRpc })
  74. if (this.netId !== 1) {
  75. await this.selectRpc({ netId: 1, action: this.preselectRpc })
  76. }
  77. this.$store.dispatch('gasPrices/fetchGasPrice')
  78. this.$store.dispatch('price/fetchTokenPrice', {}, { root: true })
  79. try {
  80. this.$store.dispatch('application/loadAllNotesData')
  81. this.$nextTick(() => {
  82. this.$nuxt.$loading.start()
  83. let progress = 0
  84. const increase = () => {
  85. progress++
  86. setTimeout(() => {
  87. this.$nuxt.$loading.increase(5)
  88. if (progress < 15) {
  89. increase()
  90. }
  91. }, 500)
  92. }
  93. increase()
  94. this.$nuxt.$loading.finish()
  95. })
  96. } catch (e) {
  97. console.error('default', e)
  98. }
  99. this.$store.dispatch('relayer/runAllJobs')
  100. this.$store.dispatch('governance/gov/checkActiveProposals')
  101. }, 500)
  102. })
  103. }
  104. },
  105. beforeDestroy() {
  106. window.removeEventListener('focus', this.$preventMultitabs)
  107. },
  108. methods: {
  109. ...mapActions('settings', ['checkCurrentRpc', 'preselectRpc']),
  110. checkRecoveryKey() {
  111. this.$store.dispatch('encryptedNote/checkRecoveryKey', {}, { root: true })
  112. },
  113. changeNetwork() {
  114. this.$buefy.modal.open({
  115. parent: this,
  116. component: NetworkModal,
  117. hasModalCard: true,
  118. width: 440
  119. })
  120. },
  121. newNotify() {
  122. const hasNotify = window.localStorage.getItem('hasNotify')
  123. if (!hasNotify) {
  124. this.$store.dispatch(
  125. 'notice/addNotice',
  126. {
  127. notice: {
  128. untranslatedTitle: 'New version',
  129. type: 'info',
  130. nova: true
  131. },
  132. interval: 10000
  133. },
  134. { root: true }
  135. )
  136. window.localStorage.setItem('hasNotify', true)
  137. }
  138. },
  139. handleOpenModal() {
  140. const recoveryKey = this.$sessionStorage.getItem(this.accounts.encrypt)
  141. if (recoveryKey) {
  142. this.isOpen = true
  143. openConfirmModal({
  144. onCancel: () => {
  145. this.isOpen = false
  146. this.$sessionStorage.clear()
  147. this.checkRecoveryKey()
  148. },
  149. onConfirm: () => {
  150. this.isOpen = false
  151. },
  152. parent: this
  153. })
  154. }
  155. },
  156. async selectRpc({ netId, action }) {
  157. try {
  158. await action({ netId })
  159. } catch (e) {
  160. console.error(e)
  161. this.$buefy.snackbar.open({
  162. message: this.$t('rpcSelectError'),
  163. type: 'is-danger',
  164. duration: 10000,
  165. indefinite: true,
  166. position: 'is-top',
  167. actionText: 'Open Settings',
  168. onAction: () => {
  169. this.$buefy.modal.open({
  170. parent: this,
  171. component: Settings,
  172. hasModalCard: true,
  173. width: 440,
  174. customClass: 'is-pinned',
  175. props: {
  176. netId
  177. },
  178. onCancel: () => {
  179. this.selectRpc({ netId, action })
  180. }
  181. })
  182. }
  183. })
  184. }
  185. }
  186. }
  187. }
  188. </script>
  189. <style lang="scss" scoped>
  190. .network {
  191. color: white;
  192. display: flex;
  193. align-items: center;
  194. justify-content: center;
  195. padding: 5px;
  196. margin-top: 1rem;
  197. ::v-deep .is-dark {
  198. background-color: darken(#ff8a00, 15);
  199. font-size: 0.9rem;
  200. &:hover {
  201. background-color: darken(#ff8a00, 10);
  202. }
  203. }
  204. }
  205. </style>