Skip to content

Commit

Permalink
v2.11.10: fix loading payment options (rpc settings & rotation)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNe0x1 committed Sep 10, 2024
1 parent 8aa045f commit 612148b
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 113 deletions.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
*** DePay Web3 Payments for WooCommerce Changelog ***

2024-9-10 - version 2.11.10
* fix loading payment options (rpc settings & rotation)

2024-9-5 - version 2.11.9
* fix prevents deadlock: widget loading payment options forever

Expand Down
4 changes: 2 additions & 2 deletions depay-woocommerce-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* WC tested up to: 8.7.0
* Requires at least: 5.8
* Requires PHP: 7.0
* Version: 2.11.9
* Version: 2.11.10
*
* @package DePay\Payments
*/
Expand All @@ -21,7 +21,7 @@
define( 'DEPAY_WC_PLUGIN_FILE', __FILE__ );
define( 'DEPAY_WC_ABSPATH', __DIR__ . '/' );
define( 'DEPAY_MIN_WC_ADMIN_VERSION', '0.23.2' );
define( 'DEPAY_CURRENT_VERSION', '2.11.9' );
define( 'DEPAY_CURRENT_VERSION', '2.11.10' );

require_once DEPAY_WC_ABSPATH . '/vendor/autoload.php';

Expand Down
22 changes: 13 additions & 9 deletions dist/react-token-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,32 @@
const blockchain = props.blockchain.toLowerCase();
const address = props.address;
const id = props.id;
const date = new Date();
const getLocalStorageKey = (blockchain, address)=>{
return [
'react-token-image',
'v5.0.2',
blockchain,
address,
[date.getFullYear(), date.getMonth(), date.getDate()].join('-')
].join('-')
};

const setSource = (src, source)=>{
setSrc(src);
_setSource(source);
if(source != 'unknown') {
localStorage.setItem(getLocalStorageKey(blockchain, address), src);
localStorage.setItem(getLocalStorageKey(blockchain, address), JSON.stringify({ src, expiresAt: Date.now() + (24 * 60 * 60 * 1000) })); // 24 hours
}
};

React.useEffect(()=>{
const storedImage = localStorage.getItem(getLocalStorageKey(blockchain, address));
if(storedImage && storedImage.length && storedImage != UNKNOWN_IMAGE) {
return setSource(storedImage, 'stored')
let storedImage = localStorage.getItem(getLocalStorageKey(blockchain, address));
if(storedImage && storedImage.length) {
try {
storedImage = JSON.parse(storedImage);
} catch (e) {}
}
if(storedImage && storedImage.src && storedImage.expiresAt > Date.now() && storedImage.src != UNKNOWN_IMAGE) {
return setSource(storedImage.src, 'stored')
}
const foundMajorToken = Blockchains__default['default'][blockchain].tokens.find((token)=> token.address.toLowerCase() === _optionalChain([address, 'optionalAccess', _ => _.toLowerCase, 'call', _2 => _2()]));
if(foundMajorToken) {
Expand Down Expand Up @@ -110,7 +114,7 @@
reject('image not found on metaplex');
}

} catch (e) { reject('image not found on metaplex'); }
} catch (e2) { reject('image not found on metaplex'); }
})
};

Expand Down Expand Up @@ -196,15 +200,15 @@

if(src == undefined) {
return(
React__default['default'].createElement('div', { className: props.className , __self: this, __source: {fileName: _jsxFileName, lineNumber: 201}} )
React__default['default'].createElement('div', { className: props.className , __self: this, __source: {fileName: _jsxFileName, lineNumber: 206}} )
)
}

return(
React__default['default'].createElement('img', {
className: props.className ,
src: src ,
onError: handleLoadError , __self: this, __source: {fileName: _jsxFileName, lineNumber: 206}}
onError: handleLoadError , __self: this, __source: {fileName: _jsxFileName, lineNumber: 211}}
)
)
};
Expand Down
61 changes: 35 additions & 26 deletions dist/web3-blockchains.js

Large diffs are not rendered by default.

99 changes: 67 additions & 32 deletions dist/web3-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
const BATCH_INTERVAL$1 = 10;
const CHUNK_SIZE$1 = 99;
const CHUNK_SIZE$1 = 50;
const MAX_RETRY$1 = 5;

class StaticJsonRpcBatchProvider extends ethers.ethers.providers.JsonRpcProvider {
Expand All @@ -48,51 +48,81 @@
this._pendingBatch = [];
}

handleError(error, attempt, chunk) {
if(attempt < MAX_RETRY$1 && error) {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._failover();
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this.requestChunk(chunk, this._endpoint, attempt+1);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
});
}
}

detectNetwork() {
return Promise.resolve(Blockchains__default["default"].findByName(this._network).id)
}

batchRequest(batch, attempt) {
return new Promise((resolve, reject) => {

if (batch.length === 0) resolve([]); // Do nothing if requests is empty

fetch(
this._endpoint,
{
method: 'POST',
body: JSON.stringify(batch),
headers: { 'Content-Type': 'application/json' },
}
).then((response)=>{
if(response.ok) {
response.json().then((parsedJson)=>{
if(parsedJson.find((entry)=>{
return _optionalChain$5([entry, 'optionalAccess', _ => _.error]) && [-32062,-32016].includes(_optionalChain$5([entry, 'optionalAccess', _2 => _2.error, 'optionalAccess', _3 => _3.code]))
})) {
if(attempt < MAX_RETRY$1) {
reject('Error in batch found!');
} else {
resolve(parsedJson);
}
} else {
resolve(parsedJson);
}
}).catch(reject);
} else {
reject(`${response.status} ${response.text}`);
}
}).catch(reject);
})
}

requestChunk(chunk, endpoint, attempt) {

try {
const batch = chunk.map((inflight) => inflight.request);

const request = chunk.map((inflight) => inflight.request);
return ethers.ethers.utils.fetchJson(endpoint, JSON.stringify(request))
try {
return this.batchRequest(batch, attempt)
.then((result) => {
// For each result, feed it to the correct Promise, depending
// on whether it was a success or error
chunk.forEach((inflightRequest, index) => {
const payload = result[index];
if (_optionalChain$5([payload, 'optionalAccess', _ => _.error])) {
if (_optionalChain$5([payload, 'optionalAccess', _4 => _4.error])) {
const error = new Error(payload.error.message);
error.code = payload.error.code;
error.data = payload.error.data;
inflightRequest.reject(error);
} else if(_optionalChain$5([payload, 'optionalAccess', _2 => _2.result])) {
} else if(_optionalChain$5([payload, 'optionalAccess', _5 => _5.result])) {
inflightRequest.resolve(payload.result);
} else {
inflightRequest.reject();
}
});
}).catch((error) => {
if(attempt < MAX_RETRY$1 && error && error.code == 'SERVER_ERROR') {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._failover();
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this.requestChunk(chunk, this._endpoint, attempt+1);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
});
}
})

} catch (e) {

chunk.forEach((inflightRequest) => {
inflightRequest.reject();
});
}
}).catch((error) => this.handleError(error, attempt, chunk))
} catch (error){ this.handleError(error, attempt, chunk); }
}

send(method, params) {
Expand Down Expand Up @@ -259,7 +289,7 @@

function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
const BATCH_INTERVAL = 10;
const CHUNK_SIZE = 99;
const CHUNK_SIZE = 50;
const MAX_RETRY = 10;

class StaticJsonRpcSequentialProvider extends solanaWeb3_js.Connection {
Expand Down Expand Up @@ -730,10 +760,17 @@
})
};

const findFragment = ({ fragments, method, params })=>{
return fragments.find((fragment) => {
return(
fragment.name == method &&
(fragment.inputs && params && typeof(params) === 'object' ? fragment.inputs.length == Object.keys(params).length : true)
)
})
};

const getContractArguments = ({ contract, method, params })=>{
let fragment = contract.interface.fragments.find((fragment) => {
return fragment.name == method
});
let fragment = findFragment({ fragments: contract.interface.fragments, method, params });

if(params instanceof Array) {
return params
Expand Down Expand Up @@ -761,9 +798,7 @@
return provider.estimateGas({ from, to, value })
} else {
let contract = new ethers.ethers.Contract(to, api, provider);
let fragment = contract.interface.fragments.find((fragment) => {
return fragment.name == method
});
let fragment = findFragment({ fragments: contract.interface.fragments, method, params });
let contractArguments = getContractArguments({ contract, method, params });
if(contract[method] === undefined) {
method = `${method}(${fragment.inputs.map((input)=>{
Expand Down
30 changes: 15 additions & 15 deletions dist/widgets.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion languages/depay-woocommerce-payments.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is distributed under the same license as the package.
msgid ""
msgstr ""
"Project-Id-Version: DePay WooCommerce Payments 2.11.9\n"
"Project-Id-Version: DePay WooCommerce Payments 2.11.10\n"
"Report-Msgid-Bugs-To: "
"[email protected]\n"
"MIME-Version: 1.0\n"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/web3-woocommerce-depay-payments",
"moduleName": "WooCommerceDePayPayments",
"version": "2.11.9",
"version": "2.11.10",
"description": "WooCommerce DePay plugin to accept Web3 payments directly into your wallet with on-the-fly conversion.",
"main": "./dist/umd/index.js",
"module": "./dist/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: web3, payments, woocommerce, depay, cryptocurrency
Requires at least: 6.0
Tested up to: 6.5
Requires PHP: 7.2
Stable tag: 2.11.9
Stable tag: 2.11.10
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down
Loading

0 comments on commit 612148b

Please sign in to comment.