-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Browser file management (#451)
- Loading branch information
Showing
20 changed files
with
2,152 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
NEXT_PUBLIC_GRPC_URL=https://gnfd-testnet-fullnode-tendermint-ap.bnbchain.org | ||
|
||
NEXT_PUBLIC_GREENFIELD_RPC_URL=https://gnfd-testnet-fullnode-tendermint-ap.bnbchain.org | ||
NEXT_PUBLIC_GREEN_CHAIN_ID=5600 | ||
|
||
# BSC End POINT | ||
NEXT_PUBLIC_BSC_RPC_URL=https://data-seed-prebsc-1-s1.binance.org:8545 | ||
NEXT_PUBLIC_BSC_CHAIN_ID=97 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Browser File Management | ||
|
||
```bash | ||
> cp .env.simple .env | ||
``` | ||
|
||
And then fill your account info in `.env`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const _getPublicEnv = (prefix) => { | ||
const envs = process.env; | ||
const res = {}; | ||
|
||
Object.keys(envs).forEach((k) => { | ||
if (k.startsWith(prefix)) { | ||
res[k] = envs[k]; | ||
} | ||
}); | ||
|
||
return res; | ||
}; | ||
|
||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: false, | ||
trailingSlash: true, | ||
publicRuntimeConfig: { | ||
..._getPublicEnv('NEXT_PUBLIC_'), | ||
}, | ||
eslint: { | ||
// Warning: This allows production builds to successfully complete even if | ||
// your project has ESLint errors. | ||
ignoreDuringBuilds: true, | ||
}, | ||
webpack: (config) => { | ||
config.resolve.fallback = { | ||
fs: false, | ||
net: false, | ||
tls: false, | ||
}; | ||
|
||
return config; | ||
}, | ||
}; | ||
|
||
module.exports = nextConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "browser-file-management", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "next dev", | ||
"build": "next build", | ||
"start": "next start", | ||
"lint": "next lint" | ||
}, | ||
"dependencies": { | ||
"@bnb-chain/greenfield-js-sdk": "latest", | ||
"@bnb-chain/reed-solomon": "latest", | ||
"@rainbow-me/rainbowkit": "^1.3.0", | ||
"@types/node": "20.6.0", | ||
"@types/react": "18.2.21", | ||
"@types/react-dom": "18.2.7", | ||
"next": "13.4.19", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"typescript": "5.2.2", | ||
"viem": "^1.19.11", | ||
"wagmi": "^1.4.8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { GREEN_CHAIN_ID, GRPC_URL } from '@/config/env'; | ||
import { Client } from '@bnb-chain/greenfield-js-sdk'; | ||
|
||
export const client = Client.create(GRPC_URL, String(GREEN_CHAIN_ID), { | ||
zkCryptoUrl: 'https://unpkg.com/@bnb-chain/[email protected]/dist/node/zk-crypto.wasm', | ||
}); | ||
|
||
export const getSps = async () => { | ||
const sps = await client.sp.getStorageProviders(); | ||
const finalSps = (sps ?? []).filter((v: any) => v.endpoint.includes('nodereal')); | ||
|
||
return finalSps; | ||
}; | ||
|
||
export const getAllSps = async () => { | ||
const sps = await getSps(); | ||
|
||
return sps.map((sp) => { | ||
return { | ||
address: sp.operatorAddress, | ||
endpoint: sp.endpoint, | ||
name: sp.description?.moniker, | ||
}; | ||
}); | ||
}; | ||
|
||
export const selectSp = async () => { | ||
const finalSps = await getSps(); | ||
|
||
const selectIndex = Math.floor(Math.random() * finalSps.length); | ||
|
||
const secondarySpAddresses = [ | ||
...finalSps.slice(0, selectIndex), | ||
...finalSps.slice(selectIndex + 1), | ||
].map((item) => item.operatorAddress); | ||
const selectSpInfo = { | ||
id: finalSps[selectIndex].id, | ||
endpoint: finalSps[selectIndex].endpoint, | ||
primarySpAddress: finalSps[selectIndex]?.operatorAddress, | ||
sealAddress: finalSps[selectIndex].sealAddress, | ||
secondarySpAddresses, | ||
}; | ||
|
||
return selectSpInfo; | ||
}; |
Oops, something went wrong.