浏览代码

fix 线上and test 环境归集失败的问题

DevYK 3 年之前
父节点
当前提交
8e17f9e7b1
共有 1 个文件被更改,包括 17 次插入5 次删除
  1. 17 5
      model/moralis_sdk.js

+ 17 - 5
model/moralis_sdk.js

@@ -49,10 +49,10 @@ function toJson(code_, obj_, errMsg_) {
 function getTransferRecordGasFree(type, obj, address) {
     logger.log('getTransferRecordGasFree fun in', type, obj, address)
     if (obj && obj.data && obj.data.result && Array.isArray(obj.data.result) && obj.data.result.length > 0) {
-        logger.log('getTransferRecordGasFree fun in',1)
-        for (let index = 0; index <  obj.data.result.length; index++) {
+        logger.log('getTransferRecordGasFree fun in', 1)
+        for (let index = 0; index < obj.data.result.length; index++) {
             const element = obj.data.result[index];
-            logger.log('getTransferRecordGasFree fun in 2',element)
+            logger.log('getTransferRecordGasFree fun in 2', element)
             if (element.type == type && element.to_address.toLowerCase() == address.toLowerCase()) {
                 if (element.gas_price && element.gas && type == 'native') {//native
                     return {
@@ -342,12 +342,17 @@ function reduceNativeValue(nativeValue, rValue) {
  * @returns 
  */
 async function updateNativeBalance(nativeBalance, obj) {
-    var temp = obj
+    var temp = { ...obj }
+    console.log('updateNativeBalance before', temp, nativeBalance)
     var retryCount = 30;
+    if (temp.chain) {
+        temp.chain = utils.getChainName(temp.chain)
+    }
+    console.log('updateNativeBalance after', temp, nativeBalance)
     do {
         //上面转账完 BNB 会减去,这里再获取一次
         var native_ret = await Moralis.Web3API.account.getNativeBalance(temp);
-        logger.log('更新余额 :', native_ret, retryCount)
+        logger.log('更新余额 :', native_ret, native_ret,retryCount)
         if (nativeBalance != native_ret.balance) {
             return native_ret.balance;
         }
@@ -366,6 +371,13 @@ async function transfers(obj, my_account_all_coins) {
         for (let index = 0; index < my_account_all_coins.transfer_arrays.length; index++) {
             var ti = my_account_all_coins.transfer_arrays[index]
             logger.tlog('ti=', ti)
+
+            //fix 归集失败的问题
+            //线上环境和测试环境由于访问快,导致余额未来得及更新,这里做一个 延迟判断
+            if (ti.type == 'native') {
+                await updateNativeBalance(ti.amount, ti);
+            }
+
             var ret = await start_collectCoins(ti)
             //更新 native 金额
             if (isTransferSucceed(ret)) {