Skip to content

Commit

Permalink
feat: fetch networks from be (#1564)
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanmino authored Jun 17, 2024
1 parent e9cfd99 commit b25b77e
Show file tree
Hide file tree
Showing 65 changed files with 777 additions and 712 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ jobs:
sed -i 's/IS_TESTING.*/IS_TESTING=true/g' .env
- name: Graphql Setup
run: yarn graphql-setup
- name: Fetch networks
run: yarn fetch:networks
- name: Build the extension
run: yarn build:webpack
- name: Upload artifacts
Expand Down Expand Up @@ -413,6 +415,8 @@ jobs:
override: true
- name: Graphql Setup
run: yarn graphql-setup
- name: Fetch networks
run: yarn fetch:networks
- name: Install Anvil
uses: foundry-rs/foundry-toolchain@v1
with:
Expand Down Expand Up @@ -449,6 +453,8 @@ jobs:
run: yarn ds:install
- name: Graphql Setup
run: yarn graphql-setup
- name: Fetch networks
run: yarn fetch:networks
- name: Lint
run: yarn lint
- name: Audit CI
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ anvil*.log

rainbowbx.xpi

.idea/**
.idea/**

static/data
9 changes: 7 additions & 2 deletions lavamoat/build-webpack/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1156,8 +1156,13 @@
"define": true
},
"packages": {
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/sourcemap-codec": true,
"webpack>terser-webpack-plugin>@jridgewell/trace-mapping>@jridgewell/resolve-uri": true
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/resolve-uri": true,
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/sourcemap-codec": true
}
},
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/resolve-uri": {
"globals": {
"define": true
}
},
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/sourcemap-codec": {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"playground:ds": "PLAYGROUND=ds webpack --config ./webpack.config.dev.js --watch",
"lint": "eslint --cache --max-warnings 0",
"typecheck": "tsc --noEmit",
"// Fetch backend networks": "",
"fetch:networks": "node scripts/networks.js",
"// Design System scripts": "",
"// GraphQL scripts": "",
"graphql-setup": "yarn graphql-codegen:install && yarn graphql-codegen",
Expand All @@ -43,7 +45,7 @@
"// Checks the lockfile for changes": "",
"check-lockfile": "./scripts/check-lockfile.sh",
"// Installs deps, runs allowed scripts, patches packages and generates lavamoat policies": "",
"setup": "yarn install && yarn ds:install && yarn graphql-setup && yarn ds:generate-symbols && yarn allow-scripts && yarn patch-package && yarn policy",
"setup": "yarn install && yarn ds:install && yarn graphql-setup && yarn ds:generate-symbols && yarn fetch:networks && yarn allow-scripts && yarn patch-package && yarn policy",
"// runs audit against dep. tree": "",
"audit:ci": "yarn audit-ci --moderate --config audit-ci.jsonc",
"// Generates a zip file based on the build folder ready to upload to the chrome web store": "",
Expand Down
107 changes: 107 additions & 0 deletions scripts/networks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');

const fs = require('fs-extra');

/**
* Fetches data from the GraphQL API and saves it to a JSON file.
*/
async function fetchData() {
const graphqlQuery = `
query getNetworks($device: Device!, $includeTestnets: Boolean!) {
networks(device: $device, includeTestnets: $includeTestnets) {
id
name
label
icons {
badgeURL
}
testnet
opStack
defaultExplorer {
url
label
transactionURL
tokenURL
}
defaultRPC {
enabledDevices
url
}
nativeAsset {
address
name
symbol
decimals
iconURL
colors {
primary
fallback
shadow
}
}
nativeWrappedAsset {
address
name
symbol
decimals
iconURL
colors {
primary
fallback
shadow
}
}
enabledServices {
meteorology {
enabled
}
swap {
enabled
}
addys {
approvals
transactions
assets
positions
}
tokenSearch {
enabled
}
nftProxy {
enabled
}
}
}
}
`;

const response = await fetch('https://metadata.p.rainbow.me/v1/graph', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: graphqlQuery,
variables: { device: 'BX', includeTestnets: true },
}),
});

const { data } = await response.json();
const filePath = path.join(__dirname, '../static/data/networks.json');

await fs.ensureFile(filePath);
await fs.writeJson(filePath, data);
}

async function main() {
try {
console.log('Fetching networks ...');
await fetchData();
console.log('Networks data fetched and available.');
process.exit(0);
} catch (error) {
console.error('Error fetching networks data:', error);
process.exit(1);
}
}

main();
5 changes: 4 additions & 1 deletion src/core/graphql/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ exports.config = {
document: './queries/ens.graphql',
},
metadata: {
schema: {
method: 'GET',
url: 'https://metadata.p.rainbow.me/v1/graph',
},
document: './queries/metadata.graphql',
schema: { method: 'GET', url: 'https://metadata.p.rainbow.me/v1/graph' },
},
};
1 change: 0 additions & 1 deletion src/core/providers/index.ts

This file was deleted.

8 changes: 3 additions & 5 deletions src/core/providers/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaultRPC } from '../references/chains';
import { SUPPORTED_CHAIN_IDS } from '../references/chains';
import { ChainId } from '../types/chains';

export const proxyRpcEndpoint = (endpoint: string, chainId: ChainId) => {
Expand All @@ -8,11 +8,9 @@ export const proxyRpcEndpoint = (endpoint: string, chainId: ChainId) => {
endpoint !== 'http://localhost:8545' &&
!endpoint.includes('http://10.') &&
!endpoint.includes('http://192.168') &&
!endpoint.match(/http:\/\/172.(1[6-9]|2[0-9]|3[0-1])./)
!endpoint.match(/http:\/\/172.(1[6-9]|2[0-9]|3[0-1])./) &&
!SUPPORTED_CHAIN_IDS.includes(chainId)
) {
if (defaultRPC[chainId] === endpoint) {
return `${process.env.RPC_PROXY_BASE_URL}/${chainId}/${process.env.RPC_PROXY_API_KEY}`;
}
return `${process.env.RPC_PROXY_BASE_URL}/${chainId}/${
process.env.RPC_PROXY_API_KEY
}?custom_rpc=${encodeURIComponent(endpoint)}`;
Expand Down
79 changes: 79 additions & 0 deletions src/core/references/assets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import {
arbitrumNova,
aurora,
avalanche,
blast,
blastSepolia,
boba,
canto,
celo,
classic,
cronos,
degen,
dogechain,
fantom,
filecoin,
harmonyOne,
immutableZkEvm,
kava,
klaytn,
linea,
manta,
mantle,
metis,
mode,
moonbeam,
opBNB,
palm,
pgn,
polygonZkEvm,
pulsechain,
rootstock,
scroll,
zkSync,
} from 'viem/chains';

import { ChainId } from '../types/chains';

export const customChainIdsToAssetNames: Record<ChainId, string> = {
[arbitrumNova.id]: 'arbitrumnova',
[aurora.id]: 'aurora',
[avalanche.id]: 'avalanchex',
[blast.id]: 'blast',
[blastSepolia.id]: 'blastsepolia',
[boba.id]: 'boba',
[celo.id]: 'celo',
[classic.id]: 'classic',
[cronos.id]: 'cronos',
[degen.id]: 'degen',
[dogechain.id]: 'dogechain',
[fantom.id]: 'fantom',
[filecoin.id]: 'filecoin',
[harmonyOne.id]: 'harmony',
[immutableZkEvm.id]: 'immutablezkevm',
[kava.id]: 'kavaevm',
[klaytn.id]: 'klaytn',
[linea.id]: 'linea',
957: 'lyra',
[manta.id]: 'manta',
[mantle.id]: 'mantle',
[metis.id]: 'metis',
[mode.id]: 'mode',
[moonbeam.id]: 'moonbeam',
[canto.id]: 'nativecanto',
[opBNB.id]: 'opbnb',
[palm.id]: 'palm',
[pgn.id]: 'pgn',
[polygonZkEvm.id]: 'polygonzkevm',
[pulsechain.id]: 'pulsechain',
1380012617: 'rari',
1918988905: 'raritestnet',
690: 'redstone',
17069: 'redstonegarnet',
17001: 'redstoneholesky',
[rootstock.id]: 'rootstock',
31: 'rootstocktestnet',
[scroll.id]: 'scroll',
100: 'xdai',
[zkSync.id]: 'zksync',
};
Loading

0 comments on commit b25b77e

Please sign in to comment.