1
0

Blocks.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <main aria-labelledby="announcements-title">
  3. <div class="rounded-lg bg-white overflow-hidden shadow">
  4. <div class="p-6">
  5. <h2 class="text-xl font-bold text-gray-800">
  6. Latest Blocks
  7. </h2>
  8. <h3>
  9. Current height is <span class="font-bold text-lg text-blue-500">{{displayBlockHeight}}</span>
  10. </h3>
  11. <div class="py-0" v-for="block of displayBlocks" :key="block.hash">
  12. <div class="flex justify-end relative top-5 right-5 z-10">
  13. <div class="p-2 text-gray-200 text-base font-bold rounded-full bg-pink-500">
  14. #{{block.index}}
  15. </div>
  16. </div>
  17. <div class="relative p-3 border-2 border-gray-500 bg-gray-300 rounded-xl focus-within:ring-2 focus-within:ring-cyan-500">
  18. <h3 class="text-sm font-semibold text-gray-800">
  19. <a href="javascript://" class="hover:underline focus:outline-none">
  20. <span class="absolute inset-0" aria-hidden="true"></span>
  21. {{shorten(block.hash)}}
  22. </a>
  23. </h3>
  24. <p class="mt-1 text-sm text-gray-600 line-clamp-2">
  25. # Txs: {{block.transactions.length}}
  26. </p>
  27. </div>
  28. </div>
  29. <div class="mt-6">
  30. <a href="javascript://" class="w-full flex justify-center items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50">
  31. View all
  32. </a>
  33. </div>
  34. </div>
  35. </div>
  36. </main>
  37. </template>
  38. <script>
  39. /* Import modules. */
  40. import numeral from 'numeral'
  41. /* Set constants. */
  42. const NUM_BLOCKS_DISPLAYED = 5
  43. export default {
  44. props: {
  45. blockHeight: String,
  46. },
  47. data: () => {
  48. return {
  49. blocks: null,
  50. numTxsProcessed: null,
  51. }
  52. },
  53. watch: {
  54. blockHeight: function (_blockNum) {
  55. if (!_blockNum) return
  56. this.addBlock(_blockNum)
  57. },
  58. },
  59. computed: {
  60. displayBlocks() {
  61. if (!this.blocks) return []
  62. const blocks = this.blocks
  63. return blocks.reverse().slice(0, NUM_BLOCKS_DISPLAYED)
  64. },
  65. displayBlockHeight() {
  66. if (!this.blockHeight) {
  67. return 0
  68. }
  69. return numeral(Number(this.blockHeight)).format('0,0')
  70. }
  71. },
  72. methods: {
  73. async addBlock(_blockNum) {
  74. console.log('add block', _blockNum)
  75. },
  76. shorten(_value) {
  77. return _value.slice(0, 12) + ' ... ' + _value.slice(-12)
  78. },
  79. },
  80. created: async function () {
  81. /* Initialize blocks. */
  82. this.blocks = []
  83. this.numTxsProcessed = 0
  84. },
  85. mounted: function () {
  86. //
  87. },
  88. }
  89. </script>