Skip to content

Commit

Permalink
Make it actually build
Browse files Browse the repository at this point in the history
  • Loading branch information
noisekit committed May 1, 2024
1 parent 1433c97 commit 0460658
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 41 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module.exports = {
'theme/**/*',
'oracle-manager/ui/**/*',
'governance/ui/**/*',
'ultrasound/ui/**/*',
],

env: {
Expand Down
4 changes: 2 additions & 2 deletions ultrasound/ui/components/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function Main() {
ultrasound.homes
</Heading>
<Heading fontSize="30px" fontWeight={700} color="white">
burning SNX for Kain's mansions
burning SNX for Kain&apos;s mansions
</Heading>
</Flex>
<Flex alignItems="center">
Expand Down Expand Up @@ -53,7 +53,7 @@ export function Main() {
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<g clip-path="url(#clip0_3050_14040)">
<g clipPath="url(#clip0_3050_14040)">
<path
d="M25.7124 25.8147L32.4133 33.75H30.8254L25.0071 26.8599L20.3599 33.75H15L22.0274 23.331L15 15.0096H16.588L22.7324 22.2858L27.6401 15.0096H33L25.7121 25.8147H25.7124ZM23.5375 23.2392L22.8255 24.2767L17.1602 32.5322H19.5992L24.1712 25.8697L24.8832 24.8322L30.8262 16.1721H28.3871L23.5375 23.2388V23.2392Z"
fill="white"
Expand Down
17 changes: 17 additions & 0 deletions ultrasound/ui/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { safeImport } from '@synthetixio/safe-import/safeImport';

async function bootstrap() {
const { bootstrap } = await safeImport(
() => import(/* webpackChunkName: "app" */ './src/index.tsx')
);
bootstrap();
}

bootstrap();

if (module.hot) {
module.hot.accept();
module.hot.dispose(() => {
// do nothing
});
}
1 change: 1 addition & 0 deletions ultrasound/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@snx-v3/useTokenBalance": "workspace:*",
"@snx-v3/useUSDProxy": "workspace:*",
"@snx-v3/withERC7412": "workspace:*",
"@synthetixio/safe-import": "workspace:*",
"@synthetixio/v3-contracts": "workspace:*",
"@synthetixio/v3-theme": "workspace:*",
"@synthetixio/wei": "^2.74.4",
Expand Down
82 changes: 59 additions & 23 deletions ultrasound/ui/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,66 @@
import { createRoot } from 'react-dom/client';
import { ChakraProvider } from '@chakra-ui/react';
import { theme, Fonts } from '@synthetixio/v3-theme';
import { RecoilRoot } from 'recoil';
import { Web3OnboardProvider } from '@web3-onboard/react';
import { Fonts, theme } from '@synthetixio/v3-theme';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import { Web3OnboardProvider } from '@web3-onboard/react';
import ReactDOM from 'react-dom/client';
import { RecoilRoot } from 'recoil';
import { onboard } from '../utils/onboard';
import { App } from './App';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';

if (typeof document !== 'undefined') {
// eslint-disable-next-line no-undef
const element = document.querySelector('#app');
if (element) {
const root = createRoot(element);
root.render(
<RecoilRoot>
<QueryClientProvider client={new QueryClient()}>
<ReactQueryDevtools />
<Web3OnboardProvider web3Onboard={onboard}>
<ChakraProvider theme={theme}>
<Fonts />
<App />
</ChakraProvider>
</Web3OnboardProvider>
</QueryClientProvider>
</RecoilRoot>
);
const container = document.querySelector('#app');

export async function bootstrap() {
if (!container) {
throw new Error('Container #app does not exist');
}

if (process.env.NODE_ENV === 'development') {
const { Wei, wei } = await import('@synthetixio/wei');
const { ethers } = await import('ethers');
// @ts-ignore
window.devtoolsFormatters = window.devtoolsFormatters ?? [];
// @ts-ignore
window.devtoolsFormatters.push({
header: function (obj: any) {
if (obj instanceof ethers.BigNumber) {
return [
'div',
{ style: 'color: #f33' },
['span', {}, 'ethers.BigNumber('],
['span', { style: 'color: #3f3' }, wei(obj).toString()],
['span', {}, ')'],
];
}
if (obj instanceof Wei) {
return [
'div',
{ style: 'color: #f33' },
['span', {}, 'Wei('],
['span', { style: 'color: #3f3' }, obj.toString()],
['span', {}, ')'],
];
}
return null;
},
hasBody: function () {
return false;
},
});
}

const root = ReactDOM.createRoot(container);
root.render(
<RecoilRoot>
<QueryClientProvider client={new QueryClient()}>
<ReactQueryDevtools />
<Web3OnboardProvider web3Onboard={onboard}>
<ChakraProvider theme={theme}>
<Fonts />
<App />
</ChakraProvider>
</Web3OnboardProvider>
</QueryClientProvider>
</RecoilRoot>
);
}
45 changes: 29 additions & 16 deletions ultrasound/ui/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ const babelRule = {
test: /\.(ts|tsx|js|jsx)$/,
include: [
// Need to list all the folders in v3 and outside (if used)
/ultrasound\/ui/,
/theme/,
/contracts/,
/liquidity\/components/,
/theme/,
/liquidity\/lib/,
/liquidity\/components/,

/ultrasound\/ui/,
],
resolve: {
fullySpecified: false,
Expand Down Expand Up @@ -95,10 +96,11 @@ const devServer = {
};

module.exports = {
devtool: isProd ? 'source-map' : isTest ? false : 'eval',
// devtool: isProd ? 'source-map' : isTest ? false : 'eval',
devtool: isTest ? false : 'source-map',
devServer,
mode: isProd ? 'production' : 'development',
entry: './src/index.tsx',
entry: './index.js',

output: {
path: path.resolve(__dirname, 'dist'),
Expand Down Expand Up @@ -130,23 +132,39 @@ module.exports = {
plugins: [htmlPlugin]
.concat(isProd ? [new CopyWebpackPlugin({ patterns: [{ from: 'public', to: '' }] })] : [])

.concat([new webpack.NormalModuleReplacementPlugin(/^bn.js$/, require.resolve('bn.js'))])
.concat([
new webpack.NormalModuleReplacementPlugin(
/^@tanstack\/react-query$/,
require.resolve('@tanstack/react-query')
),
new webpack.NormalModuleReplacementPlugin(/^bn.js$/, require.resolve('bn.js')),
])

.concat([
new webpack.NormalModuleReplacementPlugin(
new RegExp(`^@synthetixio/v3-contracts$`),
path.resolve(path.dirname(require.resolve(`@synthetixio/v3-contracts/package.json`)), 'src')
),
new webpack.NormalModuleReplacementPlugin(
new RegExp(`^@synthetixio/v3-theme$`),
path.resolve(path.dirname(require.resolve(`@synthetixio/v3-theme/package.json`)), 'src')
),
])
.concat([])

.concat([
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
process: 'process/browser.js',
}),
])

.concat(
new webpack.DefinePlugin({
'process.env.INFURA_KEY': JSON.stringify(process.env.INFURA_KEY),
'process.env.WC_PROJECT_ID': JSON.stringify(process.env.WC_PROJECT_ID),
'process.env.PYTH_MAINNET_ENDPOINT': JSON.stringify(process.env.PYTH_MAINNET_ENDPOINT),
'process.env.PYTH_TESTNET_ENDPOINT': JSON.stringify(process.env.PYTH_TESTNET_ENDPOINT),
})
)
.concat(isProd ? [] : isTest ? [] : [new ReactRefreshWebpackPlugin({ overlay: false })])
.concat(
process.env.GENERATE_BUNDLE_REPORT === 'true'
Expand All @@ -159,17 +177,12 @@ module.exports = {
}),
]
: []
)
.concat(
new webpack.DefinePlugin({
'process.env.INFURA_KEY': JSON.stringify(process.env.INFURA_KEY),
'process.env.WC_PROJECT_ID': JSON.stringify(process.env.WC_PROJECT_ID),
'process.env.PYTH_MAINNET_ENDPOINT': JSON.stringify(process.env.PYTH_MAINNET_ENDPOINT),
'process.env.PYTH_TESTNET_ENDPOINT': JSON.stringify(process.env.PYTH_TESTNET_ENDPOINT),
})
),

resolve: {
alias: {
'@synthetixio/v3-contracts/build': '@synthetixio/v3-contracts/src',
},
fallback: {
buffer: require.resolve('buffer'),
stream: require.resolve('stream-browserify'),
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6639,6 +6639,7 @@ __metadata:
"@snx-v3/useTokenBalance": "workspace:*"
"@snx-v3/useUSDProxy": "workspace:*"
"@snx-v3/withERC7412": "workspace:*"
"@synthetixio/safe-import": "workspace:*"
"@synthetixio/v3-contracts": "workspace:*"
"@synthetixio/v3-theme": "workspace:*"
"@synthetixio/wei": "npm:^2.74.4"
Expand Down

0 comments on commit 0460658

Please sign in to comment.