App.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <div id="app">
  3. <!-- <Header @reload="reload"></Header> -->
  4. <router-view class="router"
  5. v-if="loadRouter" />
  6. </div>
  7. </template>
  8. <script>
  9. import { mapState } from 'vuex';
  10. import { simpleRpcProvider } from '@/utils/provider';
  11. import Header from '@/components/Header.vue';
  12. import BottomNavigation from '@/components/BottomNavigation.vue';
  13. import Sidebar from '@/components/Sidebar.vue';
  14. export default {
  15. name: 'App',
  16. data () {
  17. return {
  18. loadRouter: true,
  19. };
  20. },
  21. components: {
  22. Header,
  23. BottomNavigation,
  24. Sidebar,
  25. },
  26. beforeCreate () {
  27. this.$store.dispatch('setWebProvider');
  28. // localStorage.setItem('lang', "zh-CN");
  29. },
  30. computed: {
  31. ...mapState(['account', 'provider', 'gasPrice', 'slippage', 'deadline', 'transactions', 'block', 'expert']),
  32. },
  33. async created () {
  34. const blockNumber = await simpleRpcProvider.eth.getBlockNumber();
  35. this.$store.commit('SETBLOCK', blockNumber);
  36. this.timer = setInterval(async () => {
  37. const blockNumber = await simpleRpcProvider.eth.getBlockNumber();
  38. this.$store.commit('SETBLOCK', blockNumber);
  39. }, 6000);
  40. },
  41. watch: {
  42. block () {
  43. this.handleUpdateTransactions();
  44. },
  45. },
  46. beforeDestroy () {
  47. window.clearInterval(this.timer);
  48. },
  49. methods: {
  50. async handleUpdateTransactions () {
  51. if (!this.account) {
  52. return;
  53. }
  54. const allTransactions = Object.values(this.transactions);
  55. const pendTransactions = allTransactions.filter(item => {
  56. return !item.receipt && item.from.toLowerCase() == this.account.toLowerCase();
  57. });
  58. pendTransactions.forEach((item, index) => {
  59. simpleRpcProvider.eth.getTransactionReceipt(item.hash).then(receipt => {
  60. if (receipt) {
  61. this.$store.commit('SETTRANSACTIONSRECEIPT', {
  62. hash: item.hash,
  63. receipt,
  64. });
  65. if (document.documentElement.clientWidth < 400) {
  66. if (receipt.status) {
  67. this.$message({ type: 'success', title: item.title, message: item.message, hash: receipt.hash });
  68. } else {
  69. this.$message({ type: 'error', title: item.title, message: item.message, hash: receipt.hash });
  70. }
  71. } else {
  72. if (receipt.status) {
  73. this.$message({
  74. position: 'top-right',
  75. type: 'success',
  76. title: item.title,
  77. message: item.message,
  78. hash: receipt.hash,
  79. });
  80. } else {
  81. this.$message({
  82. position: 'top-right',
  83. type: 'error',
  84. title: item.title,
  85. message: item.message,
  86. hash: receipt.hash,
  87. });
  88. }
  89. }
  90. }
  91. });
  92. });
  93. },
  94. async reload () {
  95. this.loadRouter = false;
  96. this.$nextTick(() => {
  97. this.loadRouter = true;
  98. });
  99. },
  100. },
  101. };
  102. </script>
  103. <style lang="less" scoped>
  104. #app {
  105. // font-family: Roboto, Segoe UI, sans-serif;
  106. font-family: 'PingFang';
  107. -webkit-font-smoothing: antialiased;
  108. -moz-osx-font-smoothing: grayscale;
  109. color: #fff;
  110. // background: #091224;
  111. // height: 100%;
  112. image-rendering: -webkit-optimize-contrast;
  113. .router {
  114. }
  115. }
  116. </style>