修改ethereum usdt的授权方式,先改为0, 再授权
This commit is contained in:
parent
37089dca15
commit
32d75b4a7c
@ -4,6 +4,7 @@ import { apiPreRecharge } from "./../utils/request.js"
|
||||
import { switchEthereumChain, queryAllowance } from './utils.js'
|
||||
import { FirebaseUtil } from "@/utils/firebase.util";
|
||||
|
||||
const USDT_EHTEREUM = '0xdac17f958d2ee523a2206206994597c13d831ec7'
|
||||
export class BitgetWallet{
|
||||
constructor() {
|
||||
if (BitgetWallet.instance) {
|
||||
@ -84,10 +85,19 @@ export class BitgetWallet{
|
||||
let user = data.account_address
|
||||
if (calls.length > 1) {
|
||||
const contractAddress = calls[1].trans_req.to
|
||||
|
||||
// get calls[1].data last 32 bytes
|
||||
const amount = BigInt(parseInt(calls[0].trans_req.data.slice(-64), 16))
|
||||
let allowance = await queryAllowance(provider, calls[0].trans_req.to, user, contractAddress)
|
||||
if (allowance < amount) {
|
||||
if (calls[0].trans_req.to.toLowerCase() == USDT_EHTEREUM && allowance != amount) {
|
||||
if (allowance != BigInt(0)) {
|
||||
// replace calls[0].trans_req.data last 32 bytes to 0
|
||||
let data = calls[0].trans_req.data.slice(0, -64) + '0'.repeat(64)
|
||||
await this.sendTransaction(provider, {from: user, to: calls[0].trans_req.to, data})
|
||||
}
|
||||
let hash = await this.sendTransaction(provider, {from: user, to: calls[0].trans_req.to, data: calls[0].trans_req.data})
|
||||
resutls.push(hash)
|
||||
} else if (allowance < amount) {
|
||||
let hash = await this.sendTransaction(provider, {from: user, to: calls[0].trans_req.to, data: calls[0].trans_req.data})
|
||||
resutls.push(hash)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user