currency-detail.vue 14 KB

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