Wallet.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <script setup>
  2. /* Import modules. */
  3. import numeral from 'numeral'
  4. import { reverseHex } from '@nexajs/utils'
  5. /* Initialize stores. */
  6. import { useProfileStore } from '@/stores/profile'
  7. import { useWalletStore } from '@/stores/wallet'
  8. const Profile = useProfileStore()
  9. const Wallet = useWalletStore()
  10. const isShowingDeposit = ref(false)
  11. const isShowingHistory = ref(false)
  12. const isShowingCashout = ref(false)
  13. const displayBalance = computed(() => {
  14. /* Validate asset. */
  15. if (!Wallet.asset || !Wallet.asset.amount) {
  16. return '0.00'
  17. }
  18. let decimalValue
  19. let bigIntValue
  20. if (Wallet.asset.group === '0') {
  21. decimalValue = Wallet.asset.satoshis * BigInt(1e4)
  22. } else {
  23. decimalValue = Wallet.asset.amount * BigInt(1e4)
  24. }
  25. if (Wallet.asset.decimal_places > 0) {
  26. bigIntValue = decimalValue / BigInt(10**Wallet.asset.decimal_places)
  27. } else {
  28. bigIntValue = decimalValue
  29. }
  30. return numeral(parseFloat(bigIntValue) / 1e4).format('0,0[.]00[0000]')
  31. })
  32. const displayBalanceUsd = computed(() => {
  33. /* Validate asset. */
  34. if (!Wallet.asset || !Wallet.asset.fiat || !Wallet.asset.fiat.USD) {
  35. return '0.00'
  36. }
  37. /* Initialize locals. */
  38. let balanceUsd
  39. /* Set balance. */
  40. balanceUsd = Wallet.asset.fiat.USD || 0.00
  41. /* Return formatted value. */
  42. return numeral(balanceUsd).format('$0,0.00[0000]')
  43. })
  44. // const displayBalance = computed(() => {
  45. // if (!Wallet.coins) {
  46. // return '0.00'
  47. // }
  48. //
  49. // const satoshis = Wallet.coins.reduce(
  50. // (totalSatoshis, coin) => (totalSatoshis + coin.satoshis), BigInt(0)
  51. // )
  52. //
  53. // /* Calculate (NEX) total. */
  54. // const nex = (parseInt(satoshis) / 100.0)
  55. //
  56. // /* Return formatted value. */
  57. // return numeral(nex).format('0,0.00')
  58. // })
  59. // const displayBalanceUsd = computed(() => {
  60. // if (!Wallet.coins) {
  61. // return '0.00'
  62. // }
  63. //
  64. // const satoshis = Wallet.coins.reduce(
  65. // (totalSatoshis, coin) => (totalSatoshis + coin.satoshis), BigInt(0)
  66. // )
  67. //
  68. // /* Calculate (NEX) total. */
  69. // const mex = (parseInt(satoshis) / 10**8)
  70. //
  71. // const mexUsd = mex * System.usd
  72. //
  73. // /* Return formatted value. */
  74. // return numeral(mexUsd).format('$0,0.00')
  75. // })
  76. /**
  77. * Set Tab
  78. */
  79. const setTab = (_tab) => {
  80. /* Clear all tabs. */
  81. isShowingDeposit.value = false
  82. isShowingHistory.value = false
  83. isShowingCashout.value = false
  84. if (_tab === 'deposit') {
  85. isShowingDeposit.value = true
  86. }
  87. if (_tab === 'history') {
  88. isShowingHistory.value = true
  89. }
  90. if (_tab === 'withdraw') {
  91. isShowingCashout.value = true
  92. }
  93. }
  94. onMounted(() => {
  95. setTab('deposit')
  96. })
  97. // onBeforeUnmount(() => {
  98. // console.log('Before Unmount!')
  99. // })
  100. </script>
  101. <template>
  102. <main v-if="!Wallet.isReady" class="flex flex-col gap-5">
  103. <p class="px-3 py-2 bg-yellow-100 text-base font-medium border-2 border-yellow-200 rounded-lg shadow-md">
  104. Welcome to your Wally Dice game wallet.
  105. Click the button below to create a new wallet and begin playing.
  106. </p>
  107. <button @click="Wallet.createWallet" class="px-3 py-2 text-2xl text-blue-100 font-medium bg-blue-500 border-2 border-blue-700 rounded-lg shadow hover:bg-blue-400">
  108. Create New Wallet
  109. </button>
  110. </main>
  111. <main v-else class="">
  112. <section class="px-5 py-3 bg-yellow-200 border-2 border-yellow-400 rounded-lg shadow">
  113. <h3 class="text-sm text-yellow-700 font-medium uppercase">
  114. Available Balance
  115. </h3>
  116. <h2 class="text-3xl font-medium">
  117. {{displayBalance}}
  118. {{displayBalanceUsd}}
  119. </h2>
  120. </section>
  121. <div class="mt-10">
  122. <div class="block">
  123. <nav class="isolate flex divide-x divide-gray-200 rounded-lg shadow" aria-label="Tabs">
  124. <!-- Current: "text-gray-900", Default: "text-gray-500 hover:text-gray-700" -->
  125. <button @click="setTab('deposit')" class="bg-gray-700 text-gray-100 rounded-l-lg group relative min-w-0 flex-1 overflow-hidden py-4 px-4 text-center text-lg font-medium hover:bg-gray-50 hover:text-gray-600 focus:z-10" aria-current="page">
  126. <span>Deposit</span>
  127. <span aria-hidden="true" class="bg-indigo-500 absolute inset-x-0 bottom-0 h-0.5"></span>
  128. </button>
  129. <button @click="setTab('withdraw')" class="bg-gray-700 text-gray-400 hover:text-gray-700 group relative min-w-0 flex-1 overflow-hidden py-4 px-4 text-center text-lg font-medium hover:bg-gray-50 hover:text-gray-600 focus:z-10">
  130. <span>Cashout</span>
  131. <span aria-hidden="true" class="bg-transparent absolute inset-x-0 bottom-0 h-0.5"></span>
  132. </button>
  133. <button @click="setTab('history')" class="bg-gray-700 text-gray-400 hover:text-gray-700 rounded-r-lg group relative min-w-0 flex-1 overflow-hidden py-4 px-4 text-center text-lg font-medium hover:bg-gray-50 hover:text-gray-600 focus:z-10">
  134. <span>History</span>
  135. <span aria-hidden="true" class="bg-transparent absolute inset-x-0 bottom-0 h-0.5"></span>
  136. </button>
  137. </nav>
  138. </div>
  139. </div>
  140. <div class="my-5">
  141. <MenuWalletDeposit v-if="isShowingDeposit" />
  142. <MenuWalletHistory v-if="isShowingHistory" />
  143. <MenuWalletCashout v-if="isShowingCashout" />
  144. </div>
  145. </main>
  146. </template>