Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throttle ui #120

Merged
merged 3 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<script crossorigin src="https://cdn.jsdelivr.net/npm/@depay/[email protected]"></script>
<script crossorigin src="https://cdn.jsdelivr.net/npm/@depay/[email protected]"></script>
<script crossorigin src="https://cdn.jsdelivr.net/npm/@depay/web3-assets@7"></script>
<script crossorigin src="https://cdn.jsdelivr.net/npm/@depay/web3-exchanges@13"></script>
<script crossorigin src="https://cdn.jsdelivr.net/npm/@depay/web3-payments@13"></script>
<script crossorigin src="https://cdn.jsdelivr.net/npm/@depay/web3-exchanges@13.8.4"></script>
<script crossorigin src="https://cdn.jsdelivr.net/npm/@depay/web3-payments@13.9.2"></script>
<script crossorigin src="https://cdn.jsdelivr.net/npm/qr-code-styling@1"></script>
<script crossorigin src="https://cdn.jsdelivr.net/npm/fuse.js@6"></script>
<script crossorigin src="https://cdn.jsdelivr.net/npm/react-rangeslider@2/umd/rangeslider.js"></script>
Expand Down
20 changes: 10 additions & 10 deletions dist/esm/index.bundle.js

Large diffs are not rendered by default.

33 changes: 18 additions & 15 deletions dist/esm/index.evm.js
Original file line number Diff line number Diff line change
Expand Up @@ -26728,40 +26728,40 @@ var PaymentProvider = (function (props) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
setPaymentState('paying');
setUpdatable(false);
_context2.next = 4;
return wallet.account();

case 2:
case 4:
account = _context2.sent;
_context2.next = 5;
_context2.next = 7;
return payment.route.getTransaction({
from: account
});

case 5:
case 7:
transaction = _context2.sent;

if (!before) {
_context2.next = 12;
_context2.next = 14;
break;
}

_context2.next = 9;
_context2.next = 11;
return before(transaction, account);

case 9:
case 11:
stop = _context2.sent;

if (!(stop === false)) {
_context2.next = 12;
_context2.next = 14;
break;
}

return _context2.abrupt("return");

case 12:
setPaymentState('paying');
setUpdatable(false);
case 14:
_context2.next = 16;
return request({
blockchain: transaction.blockchain,
Expand Down Expand Up @@ -26835,9 +26835,9 @@ var PaymentProvider = (function (props) {
}();

var approve = function approve() {
setPaymentState('approving');
setClosable(false);
setUpdatable(false);
setPaymentState('approving');
wallet.sendTransaction(Object.assign({}, payment.route.approvalTransaction, {
succeeded: function succeeded() {
setUpdatable(true);
Expand Down Expand Up @@ -27645,6 +27645,9 @@ var Footer = (function () {
secondsLeftCountdown = _useState4[0],
setSecondsLeftCountdown = _useState4[1];

var throttledUpdateRouteWithNewPrice = lodash.throttle(updateRouteWithNewPrice, 2000);
var throttledPay = lodash.throttle(pay, 2000);
var throttledApprove = lodash.throttle(approve, 2000);
useEffect(function () {
if (confirmationsRequired) {
var interval = setInterval(function () {
Expand Down Expand Up @@ -27801,7 +27804,7 @@ var Footer = (function () {
}, /*#__PURE__*/React.createElement("button", {
type: "button",
className: "ButtonPrimary",
onClick: approve,
onClick: throttledApprove,
title: "Allow ".concat(payment.symbol, " to be used as payment")
}, "Approve use of ", payment.symbol));
} else if (paymentState == 'approving') {
Expand All @@ -27827,7 +27830,7 @@ var Footer = (function () {
type: "button",
className: "ButtonPrimary",
onClick: function onClick() {
updateRouteWithNewPrice();
throttledUpdateRouteWithNewPrice();
}
}, "Reload"));
} else if (paymentValueLoss) {
Expand All @@ -27846,7 +27849,7 @@ var Footer = (function () {
return;
}

pay();
throttledPay();
}
}, "Pay");
} else if (paymentState == 'paying') {
Expand Down
2 changes: 1 addition & 1 deletion dist/esm/index.evm.js.map

Large diffs are not rendered by default.

33 changes: 18 additions & 15 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26691,40 +26691,40 @@ var PaymentProvider = (function (props) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
setPaymentState('paying');
setUpdatable(false);
_context2.next = 4;
return wallet.account();

case 2:
case 4:
account = _context2.sent;
_context2.next = 5;
_context2.next = 7;
return payment.route.getTransaction({
from: account
});

case 5:
case 7:
transaction = _context2.sent;

if (!before) {
_context2.next = 12;
_context2.next = 14;
break;
}

_context2.next = 9;
_context2.next = 11;
return before(transaction, account);

case 9:
case 11:
stop = _context2.sent;

if (!(stop === false)) {
_context2.next = 12;
_context2.next = 14;
break;
}

return _context2.abrupt("return");

case 12:
setPaymentState('paying');
setUpdatable(false);
case 14:
_context2.next = 16;
return request({
blockchain: transaction.blockchain,
Expand Down Expand Up @@ -26798,9 +26798,9 @@ var PaymentProvider = (function (props) {
}();

var approve = function approve() {
setPaymentState('approving');
setClosable(false);
setUpdatable(false);
setPaymentState('approving');
wallet.sendTransaction(Object.assign({}, payment.route.approvalTransaction, {
succeeded: function succeeded() {
setUpdatable(true);
Expand Down Expand Up @@ -27608,6 +27608,9 @@ var Footer = (function () {
secondsLeftCountdown = _useState4[0],
setSecondsLeftCountdown = _useState4[1];

var throttledUpdateRouteWithNewPrice = lodash.throttle(updateRouteWithNewPrice, 2000);
var throttledPay = lodash.throttle(pay, 2000);
var throttledApprove = lodash.throttle(approve, 2000);
useEffect(function () {
if (confirmationsRequired) {
var interval = setInterval(function () {
Expand Down Expand Up @@ -27764,7 +27767,7 @@ var Footer = (function () {
}, /*#__PURE__*/React.createElement("button", {
type: "button",
className: "ButtonPrimary",
onClick: approve,
onClick: throttledApprove,
title: "Allow ".concat(payment.symbol, " to be used as payment")
}, "Approve use of ", payment.symbol));
} else if (paymentState == 'approving') {
Expand All @@ -27790,7 +27793,7 @@ var Footer = (function () {
type: "button",
className: "ButtonPrimary",
onClick: function onClick() {
updateRouteWithNewPrice();
throttledUpdateRouteWithNewPrice();
}
}, "Reload"));
} else if (paymentValueLoss) {
Expand All @@ -27809,7 +27812,7 @@ var Footer = (function () {
return;
}

pay();
throttledPay();
}
}, "Pay");
} else if (paymentState == 'paying') {
Expand Down
2 changes: 1 addition & 1 deletion dist/esm/index.js.map

Large diffs are not rendered by default.

57 changes: 36 additions & 21 deletions dist/esm/index.solana.js
Original file line number Diff line number Diff line change
Expand Up @@ -26729,40 +26729,40 @@ var PaymentProvider = (function (props) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
setPaymentState('paying');
setUpdatable(false);
_context2.next = 4;
return wallet.account();

case 2:
case 4:
account = _context2.sent;
_context2.next = 5;
_context2.next = 7;
return payment.route.getTransaction({
from: account
});

case 5:
case 7:
transaction = _context2.sent;

if (!before) {
_context2.next = 12;
_context2.next = 14;
break;
}

_context2.next = 9;
_context2.next = 11;
return before(transaction, account);

case 9:
case 11:
stop = _context2.sent;

if (!(stop === false)) {
_context2.next = 12;
_context2.next = 14;
break;
}

return _context2.abrupt("return");

case 12:
setPaymentState('paying');
setUpdatable(false);
case 14:
_context2.next = 16;
return request$1({
blockchain: transaction.blockchain,
Expand Down Expand Up @@ -26836,9 +26836,9 @@ var PaymentProvider = (function (props) {
}();

var approve = function approve() {
setPaymentState('approving');
setClosable(false);
setUpdatable(false);
setPaymentState('approving');
wallet.sendTransaction(Object.assign({}, payment.route.approvalTransaction, {
succeeded: function succeeded() {
setUpdatable(true);
Expand Down Expand Up @@ -27646,6 +27646,9 @@ var Footer = (function () {
secondsLeftCountdown = _useState4[0],
setSecondsLeftCountdown = _useState4[1];

var throttledUpdateRouteWithNewPrice = lodash.throttle(updateRouteWithNewPrice, 2000);
var throttledPay = lodash.throttle(pay, 2000);
var throttledApprove = lodash.throttle(approve, 2000);
useEffect(function () {
if (confirmationsRequired) {
var interval = setInterval(function () {
Expand Down Expand Up @@ -27802,7 +27805,7 @@ var Footer = (function () {
}, /*#__PURE__*/React.createElement("button", {
type: "button",
className: "ButtonPrimary",
onClick: approve,
onClick: throttledApprove,
title: "Allow ".concat(payment.symbol, " to be used as payment")
}, "Approve use of ", payment.symbol));
} else if (paymentState == 'approving') {
Expand All @@ -27828,7 +27831,7 @@ var Footer = (function () {
type: "button",
className: "ButtonPrimary",
onClick: function onClick() {
updateRouteWithNewPrice();
throttledUpdateRouteWithNewPrice();
}
}, "Reload"));
} else if (paymentValueLoss) {
Expand All @@ -27847,7 +27850,7 @@ var Footer = (function () {
return;
}

pay();
throttledPay();
}
}, "Pay");
} else if (paymentState == 'paying') {
Expand Down Expand Up @@ -29383,7 +29386,7 @@ const getConfiguration$1 = () =>{
function _optionalChain$3$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$1$1 = 10;
const CHUNK_SIZE$1$1 = 99;
const MAX_RETRY$1 = 3;
const MAX_RETRY$1$1 = 3;

class StaticJsonRpcBatchProvider$1 extends ethers.providers.JsonRpcProvider {

Expand Down Expand Up @@ -29423,7 +29426,7 @@ class StaticJsonRpcBatchProvider$1 extends ethers.providers.JsonRpcProvider {
}
});
}).catch((error) => {
if(attempt < MAX_RETRY$1 && error && error.code == 'SERVER_ERROR') {
if(attempt < MAX_RETRY$1$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];
Expand Down Expand Up @@ -33402,6 +33405,7 @@ const getPrice = async ({
// This method is cached and is only to be used to generally existing pools every 24h
// Do not use for price calulations, fetch accounts for pools individually in order to calculate price
let getAccounts = async (base, quote) => {
if(quote === Blockchains.solana.wrapped.address) { return [] } // WSOL is base not QUOTE!
let accounts = await request(`solana://whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc/getProgramAccounts`, {
params: { filters: [
{ dataSize: WHIRLPOOL_LAYOUT.span },
Expand Down Expand Up @@ -35324,8 +35328,18 @@ const getBestPool = async ({ blockchain, exchange, path, amountIn, amountOut, bl
let amount;
if(amountIn) {
amount = await getOutputAmount({ exchange, pool, inputAmount: amountIn });
const amountScaled = await getOutputAmount({ exchange, pool, inputAmount: ethers.BigNumber.from(amountIn).mul(ethers.BigNumber.from(10)).toString() });
const amountScaledDown = amountScaled.div(ethers.BigNumber.from(10));
const difference = amountScaledDown.sub(amount).abs();
const enoughLiquidity = !difference.gt(amount.div(ethers.BigNumber.from(100)));
if(!enoughLiquidity) { return }
} else {
amount = await getInputAmount({ exchange, pool, outputAmount: amountOut });
const amountScaled = await getInputAmount({ exchange, pool, outputAmount: ethers.BigNumber.from(amountOut).mul(ethers.BigNumber.from(10)).toString() });
const amountScaledDown = amountScaled.div(ethers.BigNumber.from(10));
const difference = amountScaledDown.sub(amount).abs();
const enoughLiquidity = !difference.gt(amount.div(ethers.BigNumber.from(100)));
if(!enoughLiquidity) { return }
}

return { ...pool, amountIn: amountIn || amount, amountOut: amountOut || amount }
Expand Down Expand Up @@ -36540,6 +36554,7 @@ const getConfiguration = () =>{
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$1 = 10;
const CHUNK_SIZE$1 = 99;
const MAX_RETRY$1 = 3;

class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider {

Expand All @@ -36556,7 +36571,7 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider {
return Promise.resolve(Blockchains.findByName(this._network).id)
}

requestChunk(chunk, endpoint) {
requestChunk(chunk, endpoint, attempt) {

try {

Expand All @@ -36579,11 +36594,11 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider {
}
});
}).catch((error) => {
if(error && error.code == 'SERVER_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);
this.requestChunk(chunk, this._endpoint, attempt+1);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
Expand Down Expand Up @@ -36637,7 +36652,7 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider {
chunks.forEach((chunk)=>{
// Get the request as an array of requests
chunk.map((inflight) => inflight.request);
return this.requestChunk(chunk, this._endpoint)
return this.requestChunk(chunk, this._endpoint, 1)
});
}, getConfiguration().batchInterval || BATCH_INTERVAL$1);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/esm/index.solana.js.map

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions dist/umd/index.bundle.js

Large diffs are not rendered by default.

Loading
Loading