Skip to content

Commit 225d781

Browse files
authored
Add ETH estimates (#34)
* Add ETH estimates * Remove mocha.opts * Bump version * Add tests
1 parent 36c9bb4 commit 225d781

File tree

6 files changed

+150
-7
lines changed

6 files changed

+150
-7
lines changed

Diff for: CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.8.0] - 2021-07-20
9+
10+
### Added
11+
12+
- Add support for Ethereum estimates
13+
814
## [1.7.0] - 2021-07-14
915

1016
### Changed

Diff for: package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@patch-technology/patch",
3-
"version": "1.7.0",
3+
"version": "1.8.0",
44
"description": "JavaScript wrapper for the Patch API",
55
"license": "MIT",
66
"repository": {

Diff for: src/api/EstimatesApi.js

+48
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import ApiClient from '../ApiClient';
99
import CreateBitcoinEstimateRequest from '../model/CreateBitcoinEstimateRequest';
10+
import CreateEthereumEstimateRequest from '../model/CreateEthereumEstimateRequest';
1011
import CreateFlightEstimateRequest from '../model/CreateFlightEstimateRequest';
1112
import CreateMassEstimateRequest from '../model/CreateMassEstimateRequest';
1213
import CreateShippingEstimateRequest from '../model/CreateShippingEstimateRequest';
@@ -21,6 +22,9 @@ export default class EstimatesApi {
2122
this.createBitcoinEstimate = this.createBitcoinEstimate.bind(this);
2223
this.createBitcoinEstimateWithHttpInfo =
2324
this.createBitcoinEstimateWithHttpInfo.bind(this);
25+
this.createEthereumEstimate = this.createEthereumEstimate.bind(this);
26+
this.createEthereumEstimateWithHttpInfo =
27+
this.createEthereumEstimateWithHttpInfo.bind(this);
2428
this.createFlightEstimate = this.createFlightEstimate.bind(this);
2529
this.createFlightEstimateWithHttpInfo =
2630
this.createFlightEstimateWithHttpInfo.bind(this);
@@ -83,6 +87,50 @@ export default class EstimatesApi {
8387
return this.createBitcoinEstimateWithHttpInfo(createBitcoinEstimateRequest);
8488
}
8589

90+
createEthereumEstimateWithHttpInfo(createEthereumEstimateRequest) {
91+
let postBody = createEthereumEstimateRequest;
92+
93+
// verify the required parameter 'createEthereumEstimateRequest' is set
94+
if (
95+
createEthereumEstimateRequest === undefined ||
96+
createEthereumEstimateRequest === null
97+
) {
98+
throw new Error(
99+
"Missing the required parameter 'createEthereumEstimateRequest' when calling createEthereumEstimate"
100+
);
101+
}
102+
103+
let pathParams = {};
104+
let queryParams = {};
105+
let headerParams = {};
106+
let formParams = {};
107+
108+
let authNames = ['bearer_auth'];
109+
let contentTypes = ['application/json'];
110+
let accepts = ['application/json'];
111+
let returnType = EstimateResponse;
112+
113+
return this.apiClient.callApi(
114+
'/v1/estimates/crypto/eth',
115+
'POST',
116+
pathParams,
117+
queryParams,
118+
headerParams,
119+
formParams,
120+
postBody,
121+
authNames,
122+
contentTypes,
123+
accepts,
124+
returnType
125+
);
126+
}
127+
128+
createEthereumEstimate(createEthereumEstimateRequest) {
129+
return this.createEthereumEstimateWithHttpInfo(
130+
createEthereumEstimateRequest
131+
);
132+
}
133+
86134
createFlightEstimateWithHttpInfo(createFlightEstimateRequest) {
87135
let postBody = createFlightEstimateRequest;
88136

Diff for: src/model/CreateEthereumEstimateRequest.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Patch API V1
3+
* The core API used to integrate with Patch's service
4+
*
5+
* Contact: [email protected]
6+
*/
7+
8+
import ApiClient from '../ApiClient';
9+
10+
class CreateEthereumEstimateRequest {
11+
constructor() {
12+
CreateEthereumEstimateRequest.initialize(this);
13+
}
14+
15+
static initialize(obj) {}
16+
17+
static constructFromObject(data, obj) {
18+
if (data) {
19+
obj = obj || new CreateEthereumEstimateRequest();
20+
21+
if (data.hasOwnProperty('timestamp')) {
22+
obj['timestamp'] = ApiClient.convertToType(data['timestamp'], 'String');
23+
}
24+
25+
if (data.hasOwnProperty('gas_used')) {
26+
obj['gas_used'] = ApiClient.convertToType(data['gas_used'], 'Number');
27+
}
28+
29+
if (data.hasOwnProperty('project_id')) {
30+
obj['project_id'] = ApiClient.convertToType(
31+
data['project_id'],
32+
'String'
33+
);
34+
}
35+
36+
if (data.hasOwnProperty('create_order')) {
37+
obj['create_order'] = ApiClient.convertToType(
38+
data['create_order'],
39+
'Boolean'
40+
);
41+
}
42+
}
43+
return obj;
44+
}
45+
}
46+
47+
CreateEthereumEstimateRequest.prototype['timestamp'] = undefined;
48+
49+
CreateEthereumEstimateRequest.prototype['gas_used'] = undefined;
50+
51+
CreateEthereumEstimateRequest.prototype['project_id'] = undefined;
52+
53+
CreateEthereumEstimateRequest.prototype['create_order'] = undefined;
54+
55+
export default CreateEthereumEstimateRequest;

Diff for: test/integration/estimates.test.js

+39-5
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,50 @@ describe('Estimates Integration', function () {
6767
expect(estimate.order).to.be.eq(null);
6868
});
6969

70-
it('supports creating bitcoin estimates without an order', async function () {
71-
const createEstimateResponse = await patch.estimates.createBitcoinEstimate({
72-
create_order: false
70+
it('supports creating bitcoin estimates without parameters', async function () {
71+
const { data: estimate } = await patch.estimates.createBitcoinEstimate({
72+
create_order: false // TODO: this should work without this
7373
});
7474

75-
const estimate = createEstimateResponse.data;
76-
7775
expect(estimate.type).to.be.eq('bitcoin');
7876
expect(estimate.mass_g).to.be.above(0);
7977
expect(estimate.production).to.be.eq(false);
8078
expect(estimate.order).to.be.eq(null);
8179
});
80+
81+
it('supports creating bitcoin estimates with a timestamp', async function () {
82+
const { data: estimate1 } = await patch.estimates.createBitcoinEstimate({
83+
timestamp: '2021-06-01T20:31:18.403Z'
84+
});
85+
const { data: estimate2 } = await patch.estimates.createBitcoinEstimate({
86+
timestamp: '2021-07-01T20:31:18.403Z'
87+
});
88+
89+
expect(estimate1.mass_g).to.be.above(estimate2.mass_g); // BTC emitted less in July than in June
90+
});
91+
92+
it('supports creating bitcoin estimates with a transaction value', async function () {
93+
const { data: estimate1 } = await patch.estimates.createBitcoinEstimate({
94+
transaction_value_btc_sats: 2000
95+
});
96+
const { data: estimate2 } = await patch.estimates.createBitcoinEstimate({
97+
transaction_value_btc_sats: 1000
98+
});
99+
100+
expect(estimate1.mass_g).to.be.above(estimate2.mass_g);
101+
});
102+
103+
it('supports creating ethereum estimates with a gas value', async function () {
104+
const createEstimateResponse = await patch.estimates.createEthereumEstimate(
105+
{
106+
gas_used: 1000
107+
}
108+
);
109+
110+
const estimate = createEstimateResponse.data;
111+
112+
expect(estimate.type).to.be.eq('ethereum');
113+
expect(estimate.mass_g).to.be.above(0);
114+
expect(estimate.production).to.be.eq(false);
115+
});
82116
});

0 commit comments

Comments
 (0)