0xProject / tools

Other
97 stars 64 forks source link

Fix detection for `provider.send(payload,cb)` to use replaceAll inste… #57

Closed sunwrobert closed 2 years ago

sunwrobert commented 2 years ago

…ad of replace

Description

Using just replace leads to the following string:

'function(payload, callback) {
    var _this = this;
    var request = this._prepareRequest();
    request.onreadystatechange = function () {
        if (request.readyState === 4 && request.timeout !== 1) {
            var result = request.responseText;
            var error = null;
            try {
                result = JSON.parse(result);
            }
            catch (e) {
                error = errors.InvalidResponse(request.responseText);
            }
            _this.connected = true;
            callback(error, result);
        }
    };
    request.ontimeout = function () {
        _this.connected = false;
        callback(errors.ConnectionTimeout(this.timeout));
    };
    try {
        request.send(JSON.stringify(payload));
    }
    catch (error) {
        this.connected = false;
        callback(errors.InvalidConnection(this.host));
    }
}'

which doesn't check correctly for 'function(payload,callback)'

Testing instructions

Types of changes

Checklist: