nieyuge 2 år sedan
förälder
incheckning
099e4ec794
5 ändrade filer med 142 tillägg och 25 borttagningar
  1. 21 13
      components/qrcode.vue
  2. 14 0
      package-lock.json
  3. 1 0
      package.json
  4. 94 12
      pages/payment/index.vue
  5. 12 0
      utils/help.js

+ 21 - 13
components/qrcode.vue

@@ -19,7 +19,7 @@ import { Toast } from 'vant';
 
 export default {
     name: 'qrCode',
-    props: ['tokenChain'],
+    props: ['tokenChain', 'rechargeAddress'],
     data() {
         return {
             tokenRechargeAddress: ''
@@ -30,18 +30,26 @@ export default {
     },
     methods: {
         getTokenAddress() {
-            postRequest(Api.getTokenRechargeAddress, {
-                params: {
-                    tokenChain: this.tokenChain
-                }
-            }).then(res => {
-                let { code, data } = res;
-                if (code === 0) {
-                    this.tokenRechargeAddress = data.rechargeAddress;
-                    this.createQRCode(data.rechargeAddress)
-                    this.copyToken()
-                }
-            })
+            if (this.rechargeAddress !== '') {
+                // 有过查询
+                this.tokenRechargeAddress = this.rechargeAddress;
+                this.createQRCode(this.rechargeAddress)
+                this.copyToken()
+            } else {
+                // 没查询过
+                postRequest(Api.getTokenRechargeAddress, {
+                    params: {
+                        tokenChain: this.tokenChain
+                    }
+                }).then(res => {
+                    let { code, data } = res;
+                    if (code === 0) {
+                        this.tokenRechargeAddress = data.rechargeAddress;
+                        this.createQRCode(data.rechargeAddress)
+                        this.copyToken()
+                    }
+                })
+            }
         },
         createQRCode(str) {
             var canvas = document.getElementById('canvas')

+ 14 - 0
package-lock.json

@@ -3586,6 +3586,11 @@
       "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz",
       "integrity": "sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ=="
     },
+    "bignumber.js": {
+      "version": "7.2.1",
+      "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-7.2.1.tgz",
+      "integrity": "sha512-S4XzBk5sMB+Rcb/LNcpzXr57VRTxgAvaAEDAl1AwRx27j00hT84O6OkteE7u8UB3NuaaygCRrEpqox4uDOrbdQ=="
+    },
     "binary-extensions": {
       "version": "2.2.0",
       "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz",
@@ -5651,6 +5656,15 @@
       "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
       "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg=="
     },
+    "eth-url-parser": {
+      "version": "1.0.4",
+      "resolved": "https://registry.npmjs.org/eth-url-parser/-/eth-url-parser-1.0.4.tgz",
+      "integrity": "sha512-2PTTyc9OXNxePTUlYfos1du6hytElYdubJbx2uF3wNMEsvHOg/P7ZpPFERub6vod2T8eGjDZtB8nkGsKEc4tIQ==",
+      "requires": {
+        "bignumber.js": "^7.2.1",
+        "qs": "^6.5.2"
+      }
+    },
     "eventemitter2": {
       "version": "5.0.1",
       "resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-5.0.1.tgz",

+ 1 - 0
package.json

@@ -43,6 +43,7 @@
     "cross-env": "^7.0.3",
     "current-device": "^0.10.2",
     "device": "^0.3.12",
+    "eth-url-parser": "^1.0.4",
     "js-cookie": "^3.0.1",
     "moment": "^2.29.2",
     "nuxt": "^2.15.8",

+ 94 - 12
pages/payment/index.vue

@@ -28,6 +28,7 @@
                         </div>
                     </div>
                     <div class="item" @click="maskPay">
+                        <a class="maskLink" :href="maskUrlLink"></a>
                         <img src="../../static/payment/icon_meta_mask.png" />
                         <span>MetaMask</span>
                     </div>
@@ -72,13 +73,12 @@
                         <img class="icon" :src="currencyInfoData.iconPath" /> <span class="font">{{currencyInfoData.balance}} {{currencyInfoData.tokenSymbol}}</span>
                     </FontZoom>
                 </div>
-                <!-- waitRefresh -->
-                <template v-if="true">
+                <template v-if="waitRefresh">
                     <div class="waitFont">It may take some time to credit the funds into your account.</div>
                     <div
                         @click="checkWaitInfo"
                         class="waitBtn">
-                        <img :class="{ 'icon-refresh-rotate': refreshRotate }" src="../../static/img/icon_refresh.png" />
+                        <img :class="{ 'icon-refresh-rotate': refreshRotate }" src="../../static/img/icon_refresh.svg" />
                     </div>
                 </template>
             </div>
@@ -114,20 +114,24 @@
                         <div class="item column">
                             <div class="l">Deposit</div>
                             <div class="r">
-                                <img :src="currencyInfoData.iconPath" />
-                                <span>{{ salePlans.price - currencyInfoData.balance}} {{currencyInfoData.tokenSymbol}}</span>
+                                <FontZoom width="260">
+                                    <img :src="currencyInfoData.iconPath" />
+                                    <span>{{ salePlans.price - currencyInfoData.balance}} {{currencyInfoData.tokenSymbol}}</span>
+                                </FontZoom>
                             </div>
                         </div>
                         <div class="item column">
                             <div class="l">Network</div>
                             <div class="r">
-                                <img :src="currencyInfoData.chainInfo.iconPath" />
-                                <span>{{ currencyInfoData.chainInfo.chainName }}</span>
+                                <FontZoom width="260">
+                                    <img :src="currencyInfoData.chainInfo.iconPath" />
+                                    <span>{{ currencyInfoData.chainInfo.chainName }}</span>
+                                </FontZoom>
                             </div>
                         </div>
                         <div class="address">
                             <div class="title">Address</div>
-                            <QrCode :tokenChain="currencyInfoData.tokenChain"></QrCode>
+                            <QrCode :tokenChain="currencyInfoData.tokenChain" :rechargeAddress="rechargeAddress"></QrCode>
                         </div>
                         <div class="notice">
                             <div class="icon"><img src="../../static/img/icon_warning.svg" /></div>
@@ -139,7 +143,11 @@
                         <div class="icon">
                             <img src="../../static/img/icon_balance_blue.svg" />
                         </div>
-                        <div class="text">Balance: {{ currencyInfoData.balance }} {{ currencyInfoData.tokenSymbol }}</div>
+                        <div class="text">
+                            <FontZoom width="260">
+                                <span>Balance: {{ currencyInfoData.balance }} {{ currencyInfoData.tokenSymbol }}</span>
+                            </FontZoom>
+                        </div>
                         <div
                             class="refresh"
                             @click="checkCurrencyInfo">
@@ -275,7 +283,8 @@
 import FontZoom from '../../components/FontZoom.vue';
 import QrCode from '../../components/qrcode.vue';
 import { postRequest } from '../../http/index';
-import { Dialog } from 'vant';
+import { maskUrl } from '../../utils/help';
+import { Dialog, Toast } from 'vant';
 import Api from '../../http/api';
 
 export default {
@@ -285,6 +294,7 @@ export default {
             step: 1,        // 1: 支付方式列表 2: 余额支付 3: 充值支付 4: 支付完成
             loading: true,
             salePlans: null,
+            rechargeAddress: '',
             redeemStr: '',
             redeemNext: false,
             redeemLayer: false,
@@ -295,6 +305,7 @@ export default {
             currencyInfoData: {},
             currencyTimer: 0,
             achTimer: 0,
+            maskUrlLink: ``,
             usdAmountData: {},
         }
     },
@@ -324,6 +335,10 @@ export default {
                 if (code === 0) {
                     this.salePlans = data.salePlans[0];
                     this.getCurrencyInfoByCode();
+                    // 获取充值地址
+                    if (this.rechargeAddress === '') {
+                        this.getAddress()
+                    }
                 }
             }).finally(() => {
                 this.loading = false;
@@ -476,6 +491,42 @@ export default {
                 this.redeemNext = true;
             })
         },
+        getAddress() {
+            postRequest(Api.getTokenRechargeAddress, {
+                params: {
+                    tokenChain: this.salePlans.currencyInfo?.tokenChain
+                }
+            }).then(res => {
+                let { code, data } = res;
+                if (code === 0) {
+                    this.rechargeAddress = data.rechargeAddress
+                    this.maskUrlToLink()
+                }
+            })
+        },
+        maskUrlToLink() {
+            // MetaMask Link
+            let url;
+            if (this.salePlans.currencyInfo?.contractAddress) {
+                // 代币
+                url = maskUrl({
+                    target_address: this.salePlans.currencyInfo.contractAddress,
+                    parameters: {
+                        address: this.rechargeAddress,
+                        uint256: `${Number(this.salePlans.price) - Number(this.currencyInfoData.balance)}e${this.salePlans.currencyInfo?.decimalLength || 18}`
+                    }
+                }, false)
+            } else {
+                // 主币
+                url = maskUrl({
+                    target_address: this.rechargeAddress,
+                    parameters: {
+                        value: `${Number(this.salePlans.price) - Number(this.currencyInfoData.balance)}e${this.salePlans.currencyInfo?.decimalLength || 18}`
+                    }
+                })
+            }
+            this.maskUrlLink = url;
+        },
         goNext() {
             this.$router.push({
                 path: `/nft/${this.$route.query.nftProjectId}/${this.$route.query.account}/show`,
@@ -552,7 +603,7 @@ export default {
         deNetPay() {
             if (!this.salePlans) return;
 
-            if (this.salePlans.price > this.currencyInfoData.balance) {
+            if (Number(this.salePlans.price) > Number(this.currencyInfoData.balance)) {
                 // 余额不够
                 this.step = 3;
                 this.currencyInfoTimer();
@@ -562,12 +613,27 @@ export default {
             }
         },
         maskPay() {
-            console.log(111)
+            this.step = 2;
+            this.waitRefresh = true;
+            this.currencyInfoTimer();
+            Dialog({
+                message: `Was the pament successful?`,
+                showCancelButton: true,
+                confirmButtonText: 'YES',
+                confirmButtonColor: '#1D9BF0',
+                cancelButtonText: 'NO',
+                cancelButtonColor: '#1D9BF0',
+            }).then(() => {
+                this.checkWaitInfo()
+            }).catch(() => {
+                this.checkWaitInfo()
+            });
         },
         achPay(modifyStep = true) {
             if (modifyStep) {
                 this.step = 2;
             }
+            this.waitRefresh = true;
             this.currencyInfoTimer();
             Dialog({
                 message: `Was the pament successful?`,
@@ -578,6 +644,8 @@ export default {
                 cancelButtonColor: '#1D9BF0',
             }).then(() => {
                 this.checkWaitInfo()
+            }).catch(() => {
+                this.checkWaitInfo()
             });
 
             this.$nextTick(() => {
@@ -660,6 +728,7 @@ body,
             font-weight: 500;
         }
         .item {
+            position: relative;
             display: flex;
             align-items: center;
             justify-content: center;
@@ -691,6 +760,12 @@ body,
                 text-align: center;
                 margin-top: -2px;
             }
+            .maskLink {
+                position: absolute;
+                z-index: 10;
+                width: 100%;
+                height: 100%;
+            }
         }
     }
 }
@@ -862,6 +937,9 @@ body,
                         height: 21px;
                         margin-right: 4px;
                     }
+                    span {
+                        color: rgba($color: #5E5E5E, $alpha: .7);
+                    }
                 }
             }
             &.usd {
@@ -955,6 +1033,10 @@ body,
             font-size: 14px;
             font-weight: 500;
             line-height: 17px;
+            span {
+                color: #000;
+                margin-right: auto;
+            }
         }
         .refresh {
             width: 24px;

+ 12 - 0
utils/help.js

@@ -1,4 +1,6 @@
 import Cookie from 'js-cookie';
+import { build } from 'eth-url-parser';
+
 //application/vnd.chromium.remoting-viewer 可能为360特有 通过_mine判断是否是360
 export function isBrowser() {
 	var agent = navigator.userAgent.toLowerCase();
@@ -251,3 +253,13 @@ export function detectExtension(extensionId, callback) {
 		callback(false);
 	};
 }
+
+export const maskUrl = (params, isMain = true) => {
+	let url = build({
+		function_name: isMain ? null : `transfer`,
+		...params
+	});
+
+	// url
+	return url.replace(`ethereum:`, `https://metamask.app.link/send/`);
+}