Skip to content

Commit

Permalink
Extract the dropdown menu from VRF v2 cost calculator (smartcontractk…
Browse files Browse the repository at this point in the history
…it#1446)

* extract-dropdown

* remove mainChainName useState

* improve useQueryString hook

* improve getNetworkFromQueryString

* return null

* Remove useless DropdownMenu component + fill dropdown input with latest selected network on reload

* Refactor CostTable component to fix bugs in getting state values

* Fix bug where API call was made with undefined or null input

* Add additional states to reducer state to have a single source of truth

* Implement throttle for API calls

* Remove logging

* WIP to fix API call rate limit bug

* Fixed issue where loading text did not appear when a network was selected for the first time + Added condition to render costTable only when network is defined

* Use env variables to get VRF calculator API url + clean code

* Remove comments in methodCheckbox component

* Fix type errors in CostTable.test.ts file

* Empty commit

* account test

* new email set

* empty commit

* Empty commit

* Use env variable in costTable test file

* Remove env variable use

* fix lint issue

* Update src/features/data/chains.ts

---------

Co-authored-by: Yacine Benichou <[email protected]>
Co-authored-by: Yacine Benichou <[email protected]>
Co-authored-by: Yacine Benichou <[email protected]>
  • Loading branch information
4 people authored and dorianbayart committed Dec 25, 2023
1 parent 518bd39 commit c3e35bd
Show file tree
Hide file tree
Showing 12 changed files with 420 additions and 335 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
},
moduleNameMapper: {
"\\.(css)$": "<rootDir>/src/__mocks__/styleMock.ts",
"^~/(.*)$": "<rootDir>/src/$1",
},
transformIgnorePatterns: ["<rootDir>/node_modules/"],
}
47 changes: 0 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"github-slugger": "^2.0.0",
"nanostores": "^0.8.1",
"preact": "^10.16.0",
"query-string": "^8.1.0",
"react-instantsearch-hooks-web": "^6.47.3"
},
"devDependencies": {
Expand Down
22 changes: 22 additions & 0 deletions src/features/data/chains.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { getNetworkFromQueryString, CHAINS } from "./chains"
import { expect, test } from "@jest/globals"

describe("getNetworkFromQueryString", () => {
test("works with testnet", () => {
const queryString = "ethereum-sepolia"
const chain = CHAINS.filter((chain) => chain.label === "Ethereum")[0]
const chainNetwork = chain.networks.filter((network) => network.name === "Sepolia Testnet")[0]
expect(getNetworkFromQueryString(queryString)).toEqual({ chain, chainNetwork })
})

test("works with mainnet", () => {
const queryString = "polygon-mainnet"
const chain = CHAINS.filter((chain) => chain.label === "Polygon (Matic)")[0]
const chainNetwork = chain.networks.filter((network) => network.name === "Polygon Mainnet")[0]
expect(getNetworkFromQueryString(queryString)).toEqual({ chain, chainNetwork })
})
test("return null when invalid queryString", () => {
const queryString = "falsy-string"
expect(getNetworkFromQueryString(queryString)).toEqual({ chain: null, chainNetwork: null })
})
})
Loading

0 comments on commit c3e35bd

Please sign in to comment.