info.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <script setup lang="ts">
  2. /* Initialize stores. */
  3. import { useProfileStore } from '@/stores/profile'
  4. import { useSystemStore } from '@/stores/system'
  5. import { useWalletStore } from '@/stores/wallet'
  6. const Profile = useProfileStore()
  7. const System = useSystemStore()
  8. const Wallet = useWalletStore()
  9. onBeforeMount(() => {
  10. // TODO Move this block to @nexajs/app
  11. try {
  12. Profile.$state = JSON.parse(localStorage.getItem('profile'), (key, value) => {
  13. if (typeof value === 'string' && /^\d+n$/.test(value)) {
  14. return BigInt(value.slice(0, value.length - 1))
  15. }
  16. return value
  17. })
  18. System.$state = JSON.parse(localStorage.getItem('system'), (key, value) => {
  19. if (typeof value === 'string' && /^\d+n$/.test(value)) {
  20. return BigInt(value.slice(0, value.length - 1))
  21. }
  22. return value
  23. })
  24. // NOTE: This is an "ephemeral" wallet, stored in the Session.
  25. Wallet.$state = JSON.parse(sessionStorage.getItem('wallet'), (key, value) => {
  26. if (typeof value === 'string' && /^\d+n$/.test(value)) {
  27. return BigInt(value.slice(0, value.length - 1))
  28. }
  29. return value
  30. })
  31. // add additional states here...
  32. } catch (err) {
  33. console.error(err)
  34. }
  35. })
  36. // TODO Move this block to @nexajs/app
  37. watch([Profile.$state, System.$state, Wallet.$state], (_state) => {
  38. localStorage.setItem('profile',
  39. JSON.stringify(_state[0], (key, value) =>
  40. typeof value === 'bigint' ? value.toString() + 'n' : value
  41. )
  42. )
  43. localStorage.setItem('system',
  44. JSON.stringify(_state[1], (key, value) =>
  45. typeof value === 'bigint' ? value.toString() + 'n' : value
  46. )
  47. )
  48. // NOTE: This is an "ephemeral" wallet, stored in the Session.
  49. sessionStorage.setItem('wallet',
  50. JSON.stringify(_state[2], (key, value) =>
  51. typeof value === 'bigint' ? value.toString() + 'n' : value
  52. )
  53. )
  54. // watch additional states here...
  55. })
  56. onMounted(() => {
  57. /* Initailize system. */
  58. System.init()
  59. /* Initialize wallet. */
  60. Wallet.init()
  61. })
  62. onBeforeUnmount(() => {
  63. console.log('TODO! Cleanup session.')
  64. // Now is the time to perform all cleanup operations.
  65. })
  66. </script>
  67. <template>
  68. <div class="min-h-full">
  69. <Header />
  70. <main class="-mt-24 pb-8">
  71. <div class="mx-auto max-w-3xl px-4 sm:px-6 lg:max-w-7xl lg:px-8">
  72. <h1 class="sr-only">
  73. Hush Your Money
  74. </h1>
  75. <!-- Main 3 column grid -->
  76. <div class="grid grid-cols-1 items-start gap-4 lg:grid-cols-3 lg:gap-8">
  77. <!-- Left column -->
  78. <div class="grid grid-cols-1 gap-4 lg:col-span-2">
  79. <section aria-labelledby="section-1-title">
  80. <h2 class="sr-only" id="section-1-title">
  81. Dashboard
  82. </h2>
  83. <div class="overflow-hidden rounded-lg bg-white shadow">
  84. <div class="p-6">
  85. <!-- Your content -->
  86. <slot />
  87. </div>
  88. </div>
  89. </section>
  90. </div>
  91. <!-- Right column -->
  92. <div class="grid grid-cols-1 gap-4">
  93. <WealthSummary />
  94. <ActivitySummary />
  95. </div>
  96. </div>
  97. </div>
  98. </main>
  99. <Footer />
  100. </div>
  101. </template>