-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[Components] blocknative #10918 #19023
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import app from "../../blocknative.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "blocknative-get-chains", | ||
| name: "Get Chains", | ||
| description: "Get a list of supported chains. [See the documentation](https://docs.blocknative.com/gas-prediction/gas-platform-1)", | ||
| version: "0.0.1", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: true, | ||
| }, | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.app.getChains({ | ||
| $, | ||
| }); | ||
| $.export("$summary", "Successfully retrieved " + response.length + " chains"); | ||
| return response; | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import app from "../../blocknative.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "blocknative-get-gas-prices", | ||
| name: "Get Gas Prices", | ||
| description: "Get gas price estimations with confidence levels. [See the documentation](https://docs.blocknative.com/gas-prediction/gas-platform)", | ||
| version: "0.0.1", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: true, | ||
| }, | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| confidenceLevels: { | ||
| propDefinition: [ | ||
| app, | ||
| "confidenceLevels", | ||
| ], | ||
| }, | ||
| chainid: { | ||
| propDefinition: [ | ||
| app, | ||
| "chainid", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.app.getBlockprices({ | ||
| $, | ||
| params: { | ||
| confidenceLevels: this.confidenceLevels.join(","), | ||
| chainid: this.chainid, | ||
| }, | ||
| }); | ||
| $.export("$summary", "Successfully retrieved " + response.blockPrices[0].estimatedPrices.length + " estimated prices"); | ||
| return response; | ||
| }, | ||
|
Comment on lines
+29
to
+39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add validation for nested response structure. Line 37 accesses deeply nested properties (
Apply this diff to add proper validation: async run({ $ }) {
const response = await this.app.getBlockprices({
$,
params: {
confidenceLevels: this.confidenceLevels.join(","),
chainid: this.chainid,
},
});
- $.export("$summary", "Successfully retrieved " + response.blockPrices[0].estimatedPrices.length + " estimated prices");
+ if (!response.blockPrices?.length || !response.blockPrices[0]?.estimatedPrices) {
+ throw new Error("Unexpected response format: missing blockPrices or estimatedPrices");
+ }
+ $.export("$summary", `Successfully retrieved ${response.blockPrices[0].estimatedPrices.length} estimated prices`);
return response;
},Additionally, prefer template literals over string concatenation. 🤖 Prompt for AI Agents |
||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||||||||||||||||||||||||||||
| import app from "../../blocknative.app.mjs"; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| export default { | ||||||||||||||||||||||||||||||||||||
| key: "blocknative-get-oracles", | ||||||||||||||||||||||||||||||||||||
| name: "Get Oracles", | ||||||||||||||||||||||||||||||||||||
| description: "Get a list of supported oracles. [See the documentation](https://docs.blocknative.com/gas-prediction/gas-platform-2)", | ||||||||||||||||||||||||||||||||||||
| version: "0.0.1", | ||||||||||||||||||||||||||||||||||||
| annotations: { | ||||||||||||||||||||||||||||||||||||
| destructiveHint: false, | ||||||||||||||||||||||||||||||||||||
| openWorldHint: true, | ||||||||||||||||||||||||||||||||||||
| readOnlyHint: true, | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| type: "action", | ||||||||||||||||||||||||||||||||||||
| props: { | ||||||||||||||||||||||||||||||||||||
| app, | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| async run({ $ }) { | ||||||||||||||||||||||||||||||||||||
| const response = await this.app.getOracles({ | ||||||||||||||||||||||||||||||||||||
| $, | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
| $.export("$summary", "Successfully retrieved " + response.length + " results"); | ||||||||||||||||||||||||||||||||||||
| return response; | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+17
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add validation for response structure. The code accesses Consider adding validation: async run({ $ }) {
const response = await this.app.getOracles({
$,
});
- $.export("$summary", "Successfully retrieved " + response.length + " results");
+ if (!Array.isArray(response)) {
+ throw new Error("Unexpected response format: expected an array");
+ }
+ $.export("$summary", `Successfully retrieved ${response.length} results`);
return response;
},Additionally, prefer template literals over string concatenation for improved readability. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,67 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "blocknative", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| confidenceLevels: { | ||
| type: "integer[]", | ||
| label: "confidenceLevels", | ||
| description: "Confidence levels to include in the gas price estimation", | ||
| }, | ||
| chainid: { | ||
| type: "string", | ||
| label: "chainid", | ||
| description: "Blockchain network identifier to query gas prices for", | ||
| async options() { | ||
| const response = await this.getChains(); | ||
| return response.map(({ | ||
| label, chainId, | ||
| }) => ({ | ||
| value: chainId, | ||
| label: label, | ||
GTFalcao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| })); | ||
| }, | ||
| }, | ||
| }, | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://api.blocknative.com"; | ||
| }, | ||
| async _makeRequest(opts = {}) { | ||
| const { | ||
| $ = this, | ||
| path, | ||
| headers, | ||
| ...otherOpts | ||
| } = opts; | ||
| return axios($, { | ||
| ...otherOpts, | ||
| url: this._baseUrl() + path, | ||
| headers: { | ||
| "Authorization": `${this.$auth.api_key}`, | ||
| ...headers, | ||
| }, | ||
| }); | ||
GTFalcao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
|
|
||
| async getBlockprices(args = {}) { | ||
| return this._makeRequest({ | ||
| path: "/gasprices/blockprices", | ||
| ...args, | ||
| }); | ||
| }, | ||
| async getChains(args = {}) { | ||
| return this._makeRequest({ | ||
| path: "/chains", | ||
| ...args, | ||
| }); | ||
| }, | ||
| async getOracles(args = {}) { | ||
| return this._makeRequest({ | ||
| path: "/oracles", | ||
| ...args, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add validation for response structure.
The code accesses
response.lengthwithout validating that the response is an array, which could cause a runtime error if the API returns an unexpected structure.Apply this diff to add validation:
async run({ $ }) { const response = await this.app.getChains({ $, }); - $.export("$summary", "Successfully retrieved " + response.length + " chains"); + if (!Array.isArray(response)) { + throw new Error("Unexpected response format: expected an array"); + } + $.export("$summary", `Successfully retrieved ${response.length} chains`); return response; },Additionally, prefer template literals over string concatenation.
🤖 Prompt for AI Agents