@uniswap/conedison
Advanced tools
Comparing version 1.5.0 to 1.5.1
@@ -48,2 +48,3 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
import { poll } from '@ethersproject/web'; | ||
import { getWalletMeta } from './meta'; | ||
@@ -68,3 +69,4 @@ export * from './meta'; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var gasLimit, hash; | ||
var gasLimit, hash, error_1; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
@@ -84,4 +86,28 @@ switch (_a.label) { | ||
hash = _a.sent(); | ||
return [4 /*yield*/, provider.getTransaction(hash)]; | ||
case 4: return [2 /*return*/, _a.sent()]; | ||
_a.label = 4; | ||
case 4: | ||
_a.trys.push([4, 6, , 7]); | ||
return [4 /*yield*/, poll((function () { return __awaiter(_this, void 0, void 0, function () { | ||
var tx; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, provider.getTransaction(hash)]; | ||
case 1: | ||
tx = _a.sent(); | ||
if (tx === null) | ||
return [2 /*return*/, undefined]; | ||
return [2 /*return*/, provider._wrapTransaction(tx, hash)]; | ||
} | ||
}); | ||
}); }), { oncePoll: provider })]; | ||
case 5: | ||
// JSON-RPC only provides an opaque transaction hash, so we poll for the actual transaction. | ||
// Polling continues until a defined value is returned (see https://docs.ethers.org/v5/api/utils/web/#utils-poll). | ||
// NB: sendTransaction is a modified version of JsonRpcProvider.sendTransaction - see the original implementation. | ||
return [2 /*return*/, _a.sent()]; | ||
case 6: | ||
error_1 = _a.sent(); | ||
error_1.transactionHash = hash; | ||
throw error_1; | ||
case 7: return [2 /*return*/]; | ||
} | ||
@@ -88,0 +114,0 @@ }); |
@@ -53,2 +53,3 @@ var __assign = (this && this.__assign) || function () { | ||
describe('sendTransaction', function () { | ||
var getTransaction = jest.fn(); | ||
var sendUncheckedTransaction = jest.fn(); | ||
@@ -59,7 +60,10 @@ var request = { calldata: 'test' }; | ||
var provider = { | ||
once: jest.fn(), | ||
estimateGas: jest.fn().mockResolvedValue(BigNumber.from(10)), | ||
getSigner: jest.fn().mockReturnValue(signer), | ||
getTransaction: jest.fn().mockReturnValue(response), | ||
getTransaction: getTransaction, | ||
_wrapTransaction: jest.fn().mockImplementation(function (tx) { return tx; }), | ||
}; | ||
beforeEach(function () { | ||
getTransaction.mockReturnValueOnce(response); | ||
sendUncheckedTransaction.mockReset(); | ||
@@ -78,2 +82,19 @@ }); | ||
}); }); | ||
it('polls for a response', function () { return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
jest.spyOn(provider, 'once').mockImplementation(function (name, listener) { | ||
listener(); | ||
return provider; | ||
}); | ||
getTransaction.mockReset().mockReturnValueOnce(undefined).mockReturnValueOnce(response); | ||
return [4 /*yield*/, expect(sendTransaction(provider, request)).resolves.toBe(response)]; | ||
case 1: | ||
_a.sent(); | ||
expect(getTransaction).toHaveBeenCalledTimes(2); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
it('sends a transaction with configured gas margin', function () { return __awaiter(void 0, void 0, void 0, function () { | ||
@@ -105,2 +126,3 @@ return __generator(this, function (_a) { | ||
getWalletMeta.mockReturnValueOnce({ name: 'Uniswap Wallet' }); | ||
getTransaction.mockReturnValueOnce(response); | ||
}); | ||
@@ -107,0 +129,0 @@ it('sends a transaction with no gas limit', function () { return __awaiter(void 0, void 0, void 0, function () { |
{ | ||
"name": "@uniswap/conedison", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"description": "Utilities for Uniswap front-end development", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/Uniswap/conedison", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59074
1168