info.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <!-- 公共组件 -->
  3. <div class="info">
  4. <v-head :title="'Withdraw'" :show_more="true"></v-head>
  5. <!-- 内容 -->
  6. <div class="content">
  7. <div class="area-input-1">
  8. <div class="token">
  9. <div class="title">Crypto</div>
  10. <div class="box">
  11. <img :src="withdraw_info.icon_token" alt="">
  12. <span>{{ withdraw_info.token_symbol }}</span>
  13. </div>
  14. </div>
  15. <div class="net">
  16. <div class="title">Withdrawal Network</div>
  17. <div class="box">
  18. <img :src="withdraw_info.icon_net" alt="">
  19. <!-- <span>{{ withdraw_info.token_chain }}</span> -->
  20. <span>BNB Smart Chain (BEP20)</span>
  21. <!-- <img :src="require('@/assets/svg/icon-botton-up.svg')" alt="" class="up"> -->
  22. </div>
  23. </div>
  24. </div>
  25. <div class="area-input-2">
  26. <div class="title">Wallet Address</div>
  27. <div class="box">
  28. <input type="text" placeholder="Click to enter" v-model="state.input_address" @input="inputText">
  29. </div>
  30. </div>
  31. <div class="area-input-3">
  32. <div class="title">
  33. <span>Withdrawal Amount</span>
  34. <span>Balance: {{ state.balance || 0 }}</span>
  35. </div>
  36. <div class="box">
  37. <input type="number" placeholder="0" @input="inputText" v-model="state.input_amount" :max="state.balance">
  38. <span @click="clickWithdrawalAll">Withdrawal All</span>
  39. </div>
  40. <div class="error">{{ state.error_msg }}</div>
  41. </div>
  42. <div class="tips">
  43. <div class="tips-icon">
  44. <img :src="require('@/assets/svg/icon-top-up-tips-warning.svg')" alt="">
  45. </div>
  46. <div class="tips-content">
  47. <p>Select the same network on the platform where you are depositing funds to. Otherwise, you'll lose your
  48. assets.</p>
  49. <p>As the withdrawal is transferred out, you can check the transaction history.</p>
  50. </div>
  51. </div>
  52. </div>
  53. <!-- 底部 -->
  54. <div class="footer">
  55. <div class="left">
  56. <div class="txt">Receive Amount</div>
  57. <div class="money">{{ state.amount || 0 }} {{ state.currency_code }}</div>
  58. <div class="txt"> Network Fee: {{ state.fee_amount }} {{ withdraw_info.token_symbol }} </div>
  59. </div>
  60. <div class="right">
  61. <div class="btn" @click="clickBtn" :class="{ enter: state.is_enter_state }">Confirm</div>
  62. </div>
  63. </div>
  64. </div>
  65. </template>
  66. <script setup>
  67. import VHead from '@/view/popup/components/head.vue'
  68. import router from "@/router/popup.js";
  69. import { reactive, onMounted, inject } from 'vue'
  70. import { getWithdrawConfig } from "@/http/account";
  71. import { withdrawCalcFee } from "@/http/pay";
  72. import Report from "@/log-center/log";
  73. let withdraw_info = inject('withdraw_info')
  74. let state = reactive({
  75. input_address: '',
  76. input_amount: '',
  77. is_enter_state: false,
  78. error_msg: 'Please enter wallet address'
  79. })
  80. const inputWithdrawCalcFee = () => {
  81. withdrawCalcFee({
  82. params: {
  83. "amountValue": state.input_amount,
  84. "currencyCode": withdraw_info.currency_code,
  85. "withdrawNetwork": withdraw_info.token_chain
  86. }
  87. }).then((res) => {
  88. if (res.code == 0) {
  89. if (res.data) {
  90. state.currency_code = res.data.currencyCode || ''
  91. state.fee_amount = res.data.feeAmountValue || 0
  92. state.amount = res.data.finalAmountValue || 111
  93. state.is_enter_state = true
  94. inputText()
  95. }
  96. }
  97. })
  98. }
  99. const inputText = () => {
  100. if (!state.withdraw_switch) {
  101. return
  102. }
  103. if (!state.input_amount == undefined || state.input_amount < 0) {
  104. state.input_amount = 0
  105. }
  106. if (state.input_address.trim().length == 0) {
  107. state.error_msg = 'Please enter wallet address'
  108. state.is_enter_state = false
  109. return
  110. }
  111. console.log(state.input_address.trim().length)
  112. if (state.input_address.trim().length != 42 || state.input_address.trim().substring(0, 2).toLowerCase() != '0x') {
  113. state.error_msg = 'Incorrect wallet address input'
  114. state.is_enter_state = false
  115. return
  116. }
  117. if (Number(state.input_amount) > Number(state.balance)) {
  118. state.error_msg = `Insufficient ${withdraw_info.token_symbol} balance`
  119. state.is_enter_state = false
  120. state.amount = 0
  121. return
  122. }
  123. if (Number(state.input_amount) < Number(state.min_amount)) {
  124. state.error_msg = `Minimum amount: ${state.min_amount} ${withdraw_info.token_symbol}`
  125. state.is_enter_state = false
  126. state.amount = 0
  127. return
  128. } else {
  129. state.error_msg = ''
  130. inputWithdrawCalcFee()
  131. }
  132. }
  133. const clickBtn = () => {
  134. if (state.is_enter_state) {
  135. withdraw_info.data = state
  136. router.push('/withdraw/confirm')
  137. }
  138. }
  139. const initConfig = () => {
  140. state.balance = withdraw_info.balance
  141. if (withdraw_info.source == 'confirm') {
  142. state.withdraw_switch = withdraw_info.data.withdraw_switch
  143. state.input_address = withdraw_info.data.input_address
  144. state.input_amount = withdraw_info.data.input_amount
  145. state.amount = withdraw_info.data.amount
  146. state.withdraw_fee_desc = withdraw_info.data.withdraw_fee_desc
  147. inputText()
  148. } else {
  149. getWithdrawConfig({
  150. params: {
  151. "currencyCode": withdraw_info.currency_code,
  152. "withdrawNetwork": withdraw_info.token_chain
  153. }
  154. }).then((res) => {
  155. switch (res.code.toString()) {
  156. case '0':
  157. state.withdraw_switch = res.data.withdrawSwitch
  158. // 关闭提现功能
  159. if (!res.data.withdrawSwitch) {
  160. state.error_msg = 'Withdrawal function temporarily closed'
  161. return
  162. }
  163. state.fee_amount = res.data.withdrawFee
  164. // 单次提现最小金额
  165. state.min_amount = res.data.withdrawPerMinAmount
  166. state.withdraw_fee_desc = res.data.withdrawFeeDesc
  167. break;
  168. default:
  169. break;
  170. }
  171. })
  172. }
  173. }
  174. onMounted(() => {
  175. initConfig();
  176. Report.reportLog({
  177. pageSource: Report.pageSource.denetWithdrawForm,
  178. businessType: Report.businessType.pageView,
  179. });
  180. withdraw_info.enter_state = false
  181. })
  182. const clickWithdrawalAll = () => {
  183. state.input_amount = state.balance
  184. inputText()
  185. }
  186. </script>
  187. <style lang='scss' scoped>
  188. .info {
  189. position: relative;
  190. height: 100%;
  191. .content {
  192. height: calc(100% - 48px - 80px);
  193. overflow: auto;
  194. padding: 13px 16px 0 13px;
  195. .area-input-1 {
  196. .token {
  197. // padding-right: 7px;
  198. }
  199. .net {
  200. // padding-left: 7px;
  201. margin-top: 16px;
  202. }
  203. .token,
  204. .net {
  205. .title {
  206. font-weight: 500;
  207. font-size: 12px;
  208. margin-bottom: 6px;
  209. color: #8B8B8B;
  210. }
  211. .box {
  212. border: 1px solid #DBDBDB;
  213. border-radius: 8px;
  214. height: 44px;
  215. display: flex;
  216. align-items: center;
  217. padding: 0 15px 0 10px;
  218. display: flex;
  219. flex-wrap: nowrap;
  220. justify-content: space-between;
  221. img {
  222. width: 20px;
  223. height: 20px;
  224. }
  225. .up {
  226. width: 13px;
  227. height: 12px;
  228. cursor: pointer;
  229. }
  230. span {
  231. flex: 1;
  232. margin-left: 6px;
  233. font-size: 14px;
  234. font-weight: 500;
  235. }
  236. }
  237. }
  238. }
  239. .area-input-2,
  240. .area-input-3 {
  241. margin-top: 16px;
  242. .title {
  243. font-weight: 500;
  244. font-size: 12px;
  245. color: #8B8B8B;
  246. margin-bottom: 6px;
  247. display: flex;
  248. justify-content: space-between;
  249. }
  250. .box {
  251. border: 1px solid #DBDBDB;
  252. border-radius: 8px;
  253. height: 44px;
  254. display: flex;
  255. align-items: center;
  256. input {
  257. outline: none;
  258. border: 0;
  259. flex: 1;
  260. height: 18px;
  261. padding: 0 16px;
  262. font-weight: 500;
  263. font-size: 15px;
  264. }
  265. input::-webkit-outer-spin-button,
  266. input::-webkit-inner-spin-button {
  267. -webkit-appearance: none;
  268. }
  269. input[type="number"] {
  270. -moz-appearance: textfield;
  271. }
  272. span {
  273. display: block;
  274. color: #1D9BF0;
  275. font-size: 13px;
  276. cursor: pointer;
  277. margin-right: 16px;
  278. }
  279. }
  280. .error {
  281. margin-top: 10px;
  282. color: #FFA621;
  283. font-weight: 400;
  284. font-size: 12px;
  285. }
  286. }
  287. .tips {
  288. margin-top: 12px;
  289. font-size: 13px;
  290. height: 118;
  291. overflow: auto;
  292. background: #FCF5E5;
  293. display: flex;
  294. padding: 10px;
  295. border-radius: 10px;
  296. .tips-icon {
  297. width: 30px;
  298. img {
  299. width: 20px;
  300. height: 20px;
  301. }
  302. }
  303. .tips-content {
  304. flex: 1;
  305. }
  306. p {
  307. margin: 0;
  308. padding: 0;
  309. }
  310. }
  311. }
  312. .footer {
  313. z-index: 11;
  314. background: #fff;
  315. border-top: 1px solid #DBDBDB;
  316. bottom: 0;
  317. height: 80px;
  318. display: flex;
  319. position: absolute;
  320. justify-content: space-between;
  321. width: 100%;
  322. bottom: 0;
  323. align-items: center;
  324. .left {
  325. margin-left: 16px;
  326. .txt {
  327. color: #9D9D9D;
  328. font-weight: 400;
  329. font-size: 12px;
  330. }
  331. .money {
  332. color: #000000;
  333. font-weight: 500;
  334. font-size: 15px;
  335. }
  336. }
  337. .right {
  338. margin-right: 16px;
  339. .btn {
  340. cursor: pointer;
  341. width: 140px;
  342. height: 46px;
  343. line-height: 46px;
  344. text-align: center;
  345. font-weight: 600;
  346. font-size: 18px;
  347. color: #FFFFFF;
  348. background: #D2D2D2;
  349. border-radius: 100px;
  350. }
  351. .enter {
  352. background: #1D9BF0;
  353. }
  354. }
  355. }
  356. }
  357. </style>