Skip to content

Commit

Permalink
Simplify adapter loading with new sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
dmihal committed Jul 17, 2022
1 parent 21ae3a2 commit d19e649
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
]
},
"dependencies": {
"@cryptostats/sdk": "^0.2.10",
"@cryptostats/sdk": "^0.2.12",
"@popperjs/core": "^2.9.2",
"@types/react-transition-group": "^4.4.0",
"lucide-react": "^0.68.0",
Expand Down
30 changes: 4 additions & 26 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import List from 'components/List';
import SocialTags from 'components/SocialTags';
import ToggleNavBar from 'components/ToggleNavBar';
import ToggleBar from 'components/ToggleBar';
import { ResultsWithMetadata } from '@cryptostats/sdk';

interface HomeProps {
data: any[];
Expand Down Expand Up @@ -105,40 +104,19 @@ export const Home: NextPage<HomeProps> = ({ data }) => {
};

export const getStaticProps: GetStaticProps<HomeProps> = async () => {
const list = sdk.getCollection('l2-fees');
const collection = sdk.getCollection('l2-fees');
const l1Adapters = sdk.getCollection('l1-fees');
await list.fetchAdapters();
await collection.fetchAdapters();
await l1Adapters.fetchAdapters();

const ethAdapter = l1Adapters.getAdapter('ethereum');
collection.addAdapter(ethAdapter);

const l2Data = await list.executeQueriesWithMetadata(
const data = await collection.executeQueriesWithMetadata(
['feeTransferEth', 'feeTransferERC20', 'feeSwap'],
{ allowMissingQuery: true }
);

const [metadata, xferFee, swapFee] = await Promise.all([
ethAdapter.getMetadata(),
ethAdapter.query('feeTransferEth'),
ethAdapter.query('feeSwap'),
]);

const results = {
feeTransferEth: xferFee,
swapFee: swapFee,
};
const errors = {};

const l1Data = {
id: 'ethereum',
bundle: null,
results,
errors,
metadata,
};

const data: ResultsWithMetadata[] = [...l2Data, l1Data];

return { props: { data }, revalidate: 5 * 60 };
};

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@
exec-sh "^0.3.2"
minimist "^1.2.0"

"@cryptostats/sdk@^0.2.10":
version "0.2.10"
resolved "https://registry.yarnpkg.com/@cryptostats/sdk/-/sdk-0.2.10.tgz#53d11086b447ee9fbe46c8f7ab25aa9d33afe3ea"
integrity sha512-yJc8jmzjQbQQ512fTmIbvdxIBHDZKCg8Naz77QswxQ0F+x1Ttq7f8GAsxqCXc/85nX/Nu74QK4PVN384gZHlWQ==
"@cryptostats/sdk@^0.2.12":
version "0.2.12"
resolved "https://registry.yarnpkg.com/@cryptostats/sdk/-/sdk-0.2.12.tgz#642a89f50c0700593ca5a88397456ce7eab3fddc"
integrity sha512-sMkOhyPdCJiGbB4cuXMNWCcGcfPTKGECStMwBJSxs2ID2MaXZ360l/fl5dqQFYBW81C+dnsUeufMpMsM/iiwEg==
dependencies:
date-fns "^2.22.1"
ethers "^5.4.4"
Expand Down

0 comments on commit d19e649

Please sign in to comment.