currency-detail.vue 13 KB

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