-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate CRA to vite for fortune exchange (#363)
* migrate CRA to vite for fortune exchange * clean up fortune package name and scripts * fix global tsconfig * fix dependency * fix fortune tests
- Loading branch information
Showing
56 changed files
with
808 additions
and
4,447 deletions.
There are no files selected for viewing
File renamed without changes.
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,2 @@ | ||
PUBLIC_URL=/ | ||
VITE_APP_WALLETCONNECT_PROJECT_ID=68415bedd1597a33e8e83cc53e52071b |
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,67 @@ | ||
{ | ||
"extends": [ | ||
"plugin:import/recommended", | ||
"plugin:import/typescript", | ||
"plugin:prettier/recommended", | ||
"react-app" | ||
], | ||
"settings": { | ||
"import/resolver": { | ||
"typescript": {}, | ||
"node": { | ||
"extensions": [".js", ".jsx", ".ts", ".tsx", ".d.ts"] | ||
} | ||
}, | ||
"import/parsers": { | ||
"@typescript-eslint/parser": [".ts", ".tsx"] | ||
} | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2020, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"no-console": "warn", | ||
"no-unused-vars": "off", | ||
"import/extensions": [ | ||
"error", | ||
"ignorePackages", | ||
{ | ||
"js": "never", | ||
"jsx": "never", | ||
"ts": "never", | ||
"tsx": "never" | ||
} | ||
], | ||
"import/order": [ | ||
"error", | ||
{ | ||
"pathGroups": [ | ||
{ | ||
"pattern": "~/**", | ||
"group": "external" | ||
} | ||
], | ||
"alphabetize": { | ||
"order": "asc", | ||
"caseInsensitive": true | ||
} | ||
} | ||
], | ||
"@typescript-eslint/no-unused-vars": ["error"], | ||
"prettier/prettier": ["error"] | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": { | ||
"no-undef": "off" | ||
} | ||
} | ||
], | ||
"env": { | ||
"browser": true, | ||
"jest": true, | ||
"node": true | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
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,34 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="theme-color" content="#000000" /> | ||
<meta name="description" content="Human Protocol Fortune Exchange Oracle" /> | ||
<link rel="apple-touch-icon" href="/logo192.png" /> | ||
<!-- | ||
manifest.json provides metadata used when your web app is installed on a | ||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ | ||
--> | ||
<link rel="manifest" href="/manifest.json" /> | ||
<!-- | ||
Notice the use of %PUBLIC_URL% in the tags above. | ||
It will be replaced with the URL of the `public` folder during the build. | ||
Only files inside the `public` folder can be referenced from the HTML. | ||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
work correctly both with client-side routing and a non-root public URL. | ||
Learn how to configure a non-root public URL by running `yarn run build`. | ||
--> | ||
<link | ||
rel="stylesheet" | ||
href="https://fonts.googleapis.com/css?family=Inter:300,400,500,700,800&display=swap" | ||
/> | ||
<title>Human Protocol Fortune Exchange Oracle</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
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,60 @@ | ||
{ | ||
"name": "@human-protocol/fortune-exchange-oracle", | ||
"description": "Fortune Exchange Oracle", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"private": false, | ||
"dependencies": { | ||
"@human-protocol/core": "workspace:*", | ||
"@web3modal/ethereum": "^2.2.1", | ||
"@web3modal/react": "^2.2.1", | ||
"@web3modal/ui": "^2.2.1", | ||
"axios": "^1.1.3", | ||
"ethers": "^5.7.2", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"wagmi": "^0.12.2", | ||
"web-vitals": "^3.1.0", | ||
"web3": "^1.8.1" | ||
}, | ||
"scripts": { | ||
"lint": "eslint '**/*.{ts,tsx}'", | ||
"start": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview", | ||
"start-prod": "serve -s dist", | ||
"test": "vitest run -u", | ||
"format:prettier": "prettier --write '**/*.{ts,tsx}'", | ||
"format:lint": "eslint --fix '**/*.{ts,tsx}'", | ||
"format": "npm run format:prettier && npm run format:lint" | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
}, | ||
"devDependencies": { | ||
"@testing-library/jest-dom": "^5.16.5", | ||
"@testing-library/react": "^13.4.0", | ||
"@testing-library/user-event": "^14.4.3", | ||
"@types/react": "^18.0.25", | ||
"@types/react-dom": "^18.0.9", | ||
"@types/react-test-renderer": "^18.0.0", | ||
"@vitejs/plugin-react": "^3.1.0", | ||
"eslint-config-react-app": "^7.0.1", | ||
"eslint-import-resolver-typescript": "^3.5.4", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-react": "^7.32.2", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"react-test-renderer": "^18.2.0", | ||
"vite": "^4.1.4", | ||
"vitest": "^0.29.2" | ||
} | ||
} |
Binary file not shown.
15 changes: 15 additions & 0 deletions
15
packages/examples/fortune/exchange-oracle/public/manifest.json
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,15 @@ | ||
{ | ||
"short_name": "Fortune Exchange", | ||
"name": "Fortune Exchange Oracle", | ||
"icons": [ | ||
{ | ||
"src": "favicon.ico", | ||
"sizes": "64x64 32x32 24x24 16x16", | ||
"type": "image/x-icon" | ||
} | ||
], | ||
"start_url": ".", | ||
"display": "standalone", | ||
"theme_color": "#000000", | ||
"background_color": "#ffffff" | ||
} |
File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions
30
packages/examples/fortune/exchange-oracle/src/App.test.tsx
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,30 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { act } from 'react-test-renderer'; | ||
import { MockConnector } from 'wagmi/connectors/mock'; | ||
|
||
import App from './App'; | ||
import { Providers, setupClient, getSigners } from 'tests/utils'; | ||
|
||
test('renders correctly', async () => { | ||
const client = setupClient({ | ||
connectors: [ | ||
new MockConnector({ | ||
options: { | ||
signer: getSigners()[0]!, | ||
// Turn on `failConnect` flag to simulate connect failure | ||
}, | ||
}), | ||
], | ||
}); | ||
|
||
await act(async () => { | ||
render(<App />, { | ||
wrapper: ({ children }: { children: React.ReactNode }) => ( | ||
<Providers client={client}>{children}</Providers> | ||
), | ||
}); | ||
}); | ||
|
||
const linkElement = screen.getByText(/Select Network/i); | ||
expect(linkElement).toBeInTheDocument(); | ||
}); |
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
File renamed without changes.
41 changes: 41 additions & 0 deletions
41
packages/examples/fortune/exchange-oracle/src/components/Escrow/Escrow.test.tsx
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,41 @@ | ||
import { screen, render } from '@testing-library/react'; | ||
import { act, create } from 'react-test-renderer'; | ||
import { MockConnector } from 'wagmi/connectors/mock'; | ||
|
||
import { Escrow } from './Escrow'; | ||
import { Providers, setupClient, getSigners } from 'tests/utils'; | ||
|
||
describe('When rendered Escrow component', () => { | ||
it('renders landing page', async () => { | ||
const client = setupClient({ | ||
connectors: [ | ||
new MockConnector({ | ||
options: { | ||
signer: getSigners()[0]!, | ||
// Turn on `failConnect` flag to simulate connect failure | ||
}, | ||
}), | ||
], | ||
}); | ||
await act(async () => { | ||
render(<Escrow />, { | ||
wrapper: ({ children }: { children: React.ReactNode }) => ( | ||
<Providers client={client}>{children}</Providers> | ||
), | ||
}); | ||
}); | ||
|
||
expect(screen.getByTestId('escrowAddress')).toBeInTheDocument(); | ||
expect(screen.getByRole('button', { name: 'Confirm' })).toBeInTheDocument(); | ||
expect( | ||
screen.getByRole('button', { name: 'Send Fortune' }) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should match snapshot', () => { | ||
const component = create(<Escrow />); | ||
let tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
return; | ||
}); | ||
}); |
File renamed without changes.
1 change: 1 addition & 0 deletions
1
packages/examples/fortune/exchange-oracle/src/components/Escrow/index.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 @@ | ||
export { Escrow } from './Escrow'; |
File renamed without changes.
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
File renamed without changes.
6 changes: 2 additions & 4 deletions
6
...s/examples/fortune/exchange/src/index.tsx → ...ples/fortune/exchange-oracle/src/main.tsx
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
File renamed without changes.
File renamed without changes.
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,9 @@ | ||
/// <reference types="vite/client" /> | ||
|
||
interface ImportMetaEnv { | ||
readonly VITE_APP_WALLETCONNECT_PROJECT_ID: string; | ||
} | ||
|
||
interface ImportMeta { | ||
readonly env: ImportMetaEnv; | ||
} |
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,11 @@ | ||
import matchers from '@testing-library/jest-dom/matchers'; | ||
import { cleanup } from '@testing-library/react'; | ||
import { expect, afterEach } from 'vitest'; | ||
|
||
// extends Vitest's expect method with methods from react-testing-library | ||
expect.extend(matchers); | ||
|
||
// runs a cleanup after each test case (e.g. clearing jsdom) | ||
afterEach(() => { | ||
cleanup(); | ||
}); |
Oops, something went wrong.