currency-detail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <template>
  2. <div class="currency-detail-page">
  3. <v-head :title="currencyInfo.tokenSymbol"
  4. :show_more="false"
  5. :show_refresh="true"
  6. :show_list="true"
  7. :transactionsRouterParams="{
  8. backUrl: 'back'
  9. }"
  10. @on-refresh="onRefresh" />
  11. <div class="top">
  12. <img
  13. class="icon-currency"
  14. :src="currencyInfo.iconPath"/>
  15. <div class="amount">
  16. <div class="balance"
  17. :class="{'direction-column': (currencyInfo.totalBalance.length + currencyInfo.tokenSymbol.length) > 15}">
  18. <a-tooltip :title="currencyInfo.totalBalance">
  19. {{ getBit(currencyInfo.totalBalance) }}
  20. </a-tooltip>
  21. <template v-if="currencyInfo.totalBalance.length + currencyInfo.tokenSymbol.length < 16">
  22. &nbsp;&nbsp;
  23. </template>
  24. <span class="symbol">
  25. {{currencyInfo.tokenSymbol}}
  26. </span>
  27. </div>
  28. <div class="final">
  29. <a-tooltip :title="'$'+currencyInfo.totalUsdEstimateBalance">
  30. ${{ getBit(currencyInfo.totalUsdEstimateBalance) }}
  31. </a-tooltip>
  32. </div>
  33. </div>
  34. </div>
  35. <div class="bottom">
  36. <template v-if="showSendBtn">
  37. <div class="btn send-btn" v-if="showUSDepositBtn" @click="showSendGiveawayDialog(currencyInfo)">
  38. <img :src="require('@/assets/svg/icon-send-giveaway.svg')" />
  39. Send Giveaway
  40. </div>
  41. <div class="btn-wrapper">
  42. <div class="button left" v-if="showUSDepositBtn" @click="clickDeposit">Deposit</div>
  43. <div class="button" @click="clickWithdraw">Withdrawal</div>
  44. </div>
  45. </template>
  46. <template v-else>
  47. <div class="btn deposit-btn" v-if="showUSDepositBtn" @click="clickDeposit">Deposit</div>
  48. <div class="btn withdrawal-btn" @click="clickWithdraw">Withdrawal</div>
  49. </template>
  50. </div>
  51. <template v-if="showCurrencySelect">
  52. <div class="selectDiv">
  53. <currency-select
  54. ref="currencySelectDom"
  55. :list="currenciesData"
  56. @selectCurrency="selectCurrency">
  57. </currency-select>
  58. </div>
  59. <div class="selectBg" @click="showCurrencySelect = false"></div>
  60. </template>
  61. <input-action-sheet
  62. :visible="showDepositInput"
  63. title="Enter the USD amount to be deposited"
  64. position="absolute"
  65. @cancel="cancelDeposit"
  66. @confirm="confirmDeposit"></input-action-sheet>
  67. </div>
  68. </template>
  69. <script setup>
  70. import { ref, onMounted, inject, reactive } from "vue";
  71. import router from "@/router/popup.js";
  72. import Report from "@/log-center/log";
  73. import { getStorage } from "@/uilts/help";
  74. import { getCurrencyInfoBySymbol, syncChainTokenRechargeRecord } from "@/http/publishApi";
  75. import {setChromeStorage} from "@/uilts/chromeExtension"
  76. import VHead from '@/view/popup/components/head.vue'
  77. import currencySelect from "@/view/components/currency-select.vue";
  78. import inputActionSheet from "@/view/components/input-action-sheet.vue";
  79. import { getBit } from "@/uilts/help";
  80. let currenciesData = ref([]);
  81. let currencyInfo = ref({
  82. totalBalance: '',
  83. tokenSymbol: ''
  84. });
  85. let showCurrencySelect = ref(false);
  86. let currencyOpertionType = '';
  87. let showSendBtn = ref(true);
  88. let showUSDepositBtn = ref(true);
  89. let showDepositInput = ref(false);
  90. const selectCurrency = (params) => {
  91. showCurrencySelect.value = false;
  92. if(currencyOpertionType == 'WITHDRAW') {
  93. withdrawHandle(params);
  94. } else if(currencyOpertionType == 'DEPOSIT') {
  95. depositHandle(params);
  96. } else if(currencyOpertionType == 'SEND') {
  97. showSendGiveawayDialog(params);
  98. }
  99. }
  100. let withdraw_info = inject('withdraw_info')
  101. // 点击提现
  102. const clickWithdraw = () => {
  103. Report.reportLog({
  104. pageSource: Report.pageSource.denetHomePage,
  105. businessType: Report.businessType.buttonClick,
  106. objectType: Report.objectType.withdrawButton
  107. });
  108. if(currenciesData.value.length > 1) {
  109. showCurrencySelect.value = true;
  110. currencyOpertionType = "WITHDRAW";
  111. } else if(currenciesData.value.length == 1){
  112. withdrawHandle(currenciesData.value[0]);
  113. }
  114. }
  115. const withdrawHandle = (_params) => {
  116. withdraw_info.chainInfo = _params.chainInfo;
  117. withdraw_info.source = 'home'
  118. withdraw_info.balance = _params.balance
  119. withdraw_info.token_symbol = _params.tokenSymbol || ''
  120. withdraw_info.currency_name = _params.currencyName || ''
  121. withdraw_info.token_chain = _params.tokenChain || ''
  122. withdraw_info.currency_code = _params.currencyCode
  123. withdraw_info.icon_token = _params.iconPath || ''
  124. withdraw_info.icon_net = require('@/assets/svg/icon-BNB.svg')
  125. if (_params.currencyCode == 'USD') {
  126. withdraw_info.currency_code = _params.currencyCode
  127. withdraw_info.paypal.amount_value = _params.balance
  128. router.push('/withdraw/paypal')
  129. } else {
  130. console.log(withdraw_info.chainInfo.iconPath)
  131. router.push('/withdraw/info')
  132. }
  133. }
  134. let top_up_info = inject('top_up_info');
  135. const clickDeposit = () => {
  136. Report.reportLog({
  137. pageSource: Report.pageSource.denetHomePage,
  138. businessType: Report.businessType.buttonClick,
  139. objectType: Report.objectType.topupButton
  140. });
  141. if(currenciesData.value.length > 1) {
  142. showCurrencySelect.value = true;
  143. currencyOpertionType = "DEPOSIT";
  144. } else if(currenciesData.value.length == 1){
  145. let currencyInfo = currenciesData.value[0];
  146. if(currencyInfo.currencyCode == 'USD') {
  147. // 法币充值
  148. showDepositInput.value = true;
  149. } else {
  150. depositHandle(currencyInfo);
  151. }
  152. }
  153. }
  154. const depositHandle = (_params) => {
  155. top_up_info.token = _params.currencyName || ''
  156. top_up_info.token_chain = _params.tokenChain
  157. top_up_info.token_symbol = _params.tokenSymbol || ''
  158. top_up_info.currency_code = _params.currencyCode
  159. top_up_info.icon_token = _params.iconPath || ''
  160. top_up_info.icon_net = require('@/assets/svg/icon-BNB.svg')
  161. top_up_info.chainInfo = {
  162. ..._params.chainInfo
  163. };
  164. router.push('/top-up/info');
  165. };
  166. const asyncTokenRechRecord = (currencyCode = '', cb) => {
  167. syncChainTokenRechargeRecord({
  168. params: {
  169. currencyCode: currencyCode
  170. }
  171. }).then(res => {
  172. cb && cb(res.data)
  173. }).catch((err) => {
  174. cb && cb()
  175. })
  176. }
  177. const onRefresh = () => {
  178. asyncTokenRechRecord('', () => {
  179. getCurrencyInfoBySymbol({
  180. params: {
  181. symbol: currencyInfo.value.tokenSymbol
  182. }
  183. }).then(res => {
  184. if(res.code == 0) {
  185. if(res.data && res.data.currencyCategories && res.data.currencyCategories.length) {
  186. let data = res.data.currencyCategories[0].data;
  187. if(data.length) {
  188. let {totalBalance = '', totalUsdEstimateBalance = ''} = data[0] || {};
  189. currencyInfo.value.totalBalance = totalBalance;
  190. currencyInfo.value.totalUsdEstimateBalance = totalUsdEstimateBalance;
  191. }
  192. }
  193. }
  194. });
  195. })
  196. };
  197. const showSendGiveawayDialog = (params = {}) => {
  198. if(currenciesData.value.length > 1 && currencyOpertionType != 'SEND') {
  199. showCurrencySelect.value = true;
  200. currencyOpertionType = "SEND";
  201. } else {
  202. console.log(params,'params')
  203. setLocalSelectCurrencyInfo(params)
  204. setTimeout(() => {
  205. chrome.runtime.sendMessage({
  206. actionType: "POPUP_SHOW_DENET_PUBLISH_DIALOG",
  207. data: { }
  208. }, () => { });
  209. }, 600)
  210. currencyOpertionType = '';
  211. }
  212. };
  213. const setLocalSelectCurrencyInfo = (params = {}) => {
  214. setChromeStorage({ selectCurrencyInfo : JSON.stringify(params)})
  215. }
  216. const cancelDeposit = () => {
  217. showDepositInput.value = false;
  218. }
  219. const confirmDeposit = (params) => {
  220. let {inputVal} = params;
  221. showDepositInput.value = false;
  222. // chrome.tabs.getCurrent(tab =>{
  223. // console.log(tab);
  224. let achPayInfo = {
  225. amountValue: inputVal
  226. };
  227. let guideUrl = chrome.runtime.getURL('/iframe/ach-cashier.html');
  228. setChromeStorage({ achPayInfo : JSON.stringify(achPayInfo)});
  229. chrome.tabs.create({
  230. url: guideUrl
  231. });
  232. // })
  233. }
  234. onMounted(() => {
  235. let {params = '{}'} = router.currentRoute.value.query;
  236. let {currencies = [], totalBalance = 0, totalUsdEstimateBalance = 0} = JSON.parse(params);
  237. currenciesData.value = currencies;
  238. if(currencies.length) {
  239. currencyInfo.value = {
  240. ...currencies[0],
  241. totalBalance,
  242. totalUsdEstimateBalance
  243. };
  244. if(currencyInfo.value.currencyCode == 'USD') {
  245. //set USD deposit btn show status
  246. }
  247. }
  248. if(window.location.pathname.indexOf('/home.html') > -1) {
  249. showSendBtn.value = false;
  250. } else {
  251. showSendBtn.value = true;
  252. }
  253. })
  254. </script>
  255. <style lang='scss' scoped>
  256. .currency-detail-page {
  257. width: 100%;
  258. height: 100%;
  259. position: relative;
  260. .top {
  261. height: calc(100% - 212px);
  262. display: flex;
  263. flex-direction: column;
  264. align-items: center;
  265. justify-content: center;
  266. .icon-currency {
  267. width: 100px;
  268. margin-bottom: 30px;
  269. }
  270. .amount {
  271. font-weight: 700;
  272. font-size: 28px;
  273. text-align: center;
  274. display: flex;
  275. align-items: center;
  276. justify-content: center;
  277. flex-direction: column;
  278. width: 100%;
  279. .balance {
  280. padding: 0 18px;
  281. box-sizing: border-box;
  282. width: 100%;
  283. word-break: break-word;
  284. display: flex;
  285. align-items: center;
  286. justify-content: center;
  287. .symbol{
  288. word-break: break-all;
  289. }
  290. }
  291. .direction-column {
  292. flex-direction: column;
  293. }
  294. .final {
  295. margin-top: 9px;
  296. font-weight: 500;
  297. font-size: 22px;
  298. color: #a2a2a2;
  299. text-align: center;
  300. }
  301. }
  302. }
  303. .bottom {
  304. height: 162px;
  305. padding: 0 20px;
  306. box-sizing: border-box;
  307. .btn {
  308. width: 100%;
  309. height: 57px;
  310. display: flex;
  311. align-items: center;
  312. justify-content: center;
  313. font-weight: 500;
  314. font-size: 17px;
  315. border-radius: 100px;
  316. cursor: pointer;
  317. }
  318. .deposit-btn {
  319. margin-bottom: 18px;
  320. background: #1d9bf0;
  321. color: #fff;
  322. }
  323. .withdrawal-btn {
  324. background: rgba(244, 244, 244, 0.01);
  325. border: 1px solid #d7e8f4;
  326. box-sizing: border-box;
  327. color: #1d9bf0;
  328. }
  329. .send-btn {
  330. font-weight: 700;
  331. font-size: 18px;
  332. margin-bottom: 18px;
  333. background: #1d9bf0;
  334. color: #fff;
  335. img {
  336. width: 19px;
  337. height: 19px;
  338. margin-right: 8px;
  339. }
  340. }
  341. .btn-wrapper {
  342. width: 100%;
  343. display: flex;
  344. align-items: center;
  345. justify-content: space-between;
  346. .button {
  347. flex: 1;
  348. height: 50px;
  349. border: 1px solid #d7e8f4;
  350. display: flex;
  351. align-items: center;
  352. justify-content: center;
  353. font-weight: 600;
  354. font-size: 16px;
  355. border-radius: 100px;
  356. box-sizing: border-box;
  357. color: #1D9BF0;
  358. cursor: pointer;
  359. }
  360. .left {
  361. margin-right: 20px;
  362. }
  363. }
  364. }
  365. .selectDiv {
  366. position: absolute;
  367. z-index: 1000;
  368. width: 100%;
  369. max-height: 480px;
  370. padding-bottom: 30px;
  371. left: 0;
  372. bottom: 0;
  373. background-color: #fff;
  374. border-radius: 20px 20px 0 0;
  375. overflow-y: auto;
  376. }
  377. .selectBg {
  378. position: absolute;
  379. z-index: 999;
  380. top: 0;
  381. left: 0;
  382. width: 100%;
  383. height: 100%;
  384. background: rgba($color: #000000, $alpha: 0.6);
  385. }
  386. }
  387. </style>