detail.vue 15 KB

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