-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add wagmi, viem, rainbowKit - add providers lib for wagmi context - add .env for wallet connect project id, add to gitignore - update eslint imports rule - add browserlistrc for bigint support
- Loading branch information
Showing
19 changed files
with
2,236 additions
and
130 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,7 @@ | ||
last 1 Chrome version | ||
last 1 Firefox version | ||
last 2 Edge major versions | ||
last 2 Safari major version | ||
last 2 iOS major versions | ||
Firefox ESR | ||
not IE 9-11 |
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 @@ | ||
VITE_WALLET_CONNECT_PROJECT_ID= |
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
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 |
---|---|---|
|
@@ -37,3 +37,6 @@ testem.log | |
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
|
||
# env | ||
.env.local |
Empty file.
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,12 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@nx/react/babel", | ||
{ | ||
"runtime": "automatic", | ||
"useBuiltIns": "usage" | ||
} | ||
] | ||
], | ||
"plugins": [] | ||
} |
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 @@ | ||
{ | ||
"extends": [ | ||
"plugin:@nx/react", | ||
"../../../.eslintrc.json" | ||
], | ||
"ignorePatterns": [ | ||
"!**/*" | ||
], | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"*.ts", | ||
"*.tsx", | ||
"*.js", | ||
"*.jsx" | ||
], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": [ | ||
"*.ts", | ||
"*.tsx" | ||
], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": [ | ||
"*.js", | ||
"*.jsx" | ||
], | ||
"rules": {} | ||
} | ||
] | ||
} |
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 @@ | ||
# shared-providers | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Running unit tests | ||
|
||
Run `nx test shared-providers` to execute the unit tests via [Jest](https://jestjs.io). |
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,20 @@ | ||
{ | ||
"name": "shared-providers", | ||
"$schema": "../../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "libs/shared/providers/src", | ||
"projectType": "library", | ||
"tags": [], | ||
"targets": { | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": [ | ||
"{options.outputFile}" | ||
], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"libs/shared/providers/**/*.{ts,tsx,js,jsx}" | ||
] | ||
} | ||
} | ||
} | ||
} |
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 * from './wagmi'; |
37 changes: 37 additions & 0 deletions
37
libs/shared/providers/src/wagmi/components/AddressLabel.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,37 @@ | ||
import { Skeleton } from '@mui/material'; | ||
import { MiddleTruncated } from '@origin/shared/components'; | ||
import { mainnet, useEnsName } from 'wagmi'; | ||
|
||
import type { MiddleTruncatedProps } from '@origin/shared/components'; | ||
import type { HexAddress } from '@origin/shared/utils'; | ||
|
||
type AddressLabelProps = { | ||
address: HexAddress; | ||
enableEnsName?: boolean; | ||
} & Omit<MiddleTruncatedProps, 'children'>; | ||
|
||
export const AddressLabel = ({ | ||
address, | ||
enableEnsName = false, | ||
...rest | ||
}: AddressLabelProps) => { | ||
const { data: ensName, isLoading: isEnsNameLoading } = useEnsName({ | ||
address, | ||
enabled: enableEnsName, | ||
chainId: mainnet.id, | ||
}); | ||
|
||
return enableEnsName ? ( | ||
isEnsNameLoading ? ( | ||
<Skeleton sx={{ minWidth: 100, ...rest?.sx }} /> | ||
) : ( | ||
<MiddleTruncated textProps={{ fontFamily: 'monospace', ...rest }}> | ||
{ensName ?? address} | ||
</MiddleTruncated> | ||
) | ||
) : ( | ||
<MiddleTruncated textProps={{ fontFamily: 'monospace', ...rest }}> | ||
{address} | ||
</MiddleTruncated> | ||
); | ||
}; |
87 changes: 87 additions & 0 deletions
87
libs/shared/providers/src/wagmi/components/OpenAccountModalButton.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,87 @@ | ||
import { ConnectButton as CustomButton } from '@origin/shared/components'; | ||
import { ConnectButton } from '@rainbow-me/rainbowkit'; | ||
import { useIntl } from 'react-intl'; | ||
|
||
import { AddressLabel } from './AddressLabel'; | ||
|
||
import type { ButtonProps } from '@mui/material'; | ||
import type { HexAddress } from '@origin/shared/utils'; | ||
import type { MouseEvent } from 'react'; | ||
|
||
interface OpenAccountModalButtonProps extends ButtonProps { | ||
connectLabel?: string; | ||
} | ||
|
||
export const OpenAccountModalButton = ({ | ||
connectLabel, | ||
...props | ||
}: OpenAccountModalButtonProps) => { | ||
const intl = useIntl(); | ||
|
||
const handleClick = | ||
(handler: () => void) => (evt: MouseEvent<HTMLButtonElement>) => { | ||
if (props?.onClick) { | ||
props.onClick(evt); | ||
} | ||
handler(); | ||
}; | ||
|
||
return ( | ||
<ConnectButton.Custom> | ||
{({ | ||
account, | ||
chain, | ||
openChainModal, | ||
openConnectModal, | ||
openAccountModal, | ||
mounted, | ||
}) => { | ||
if (!mounted || !account || !chain) { | ||
return ( | ||
<CustomButton | ||
{...props} | ||
connected={false} | ||
onClick={handleClick(openConnectModal)} | ||
> | ||
{connectLabel || | ||
intl.formatMessage({ defaultMessage: 'Connect' })} | ||
</CustomButton> | ||
); | ||
} | ||
|
||
if (chain.unsupported) { | ||
return ( | ||
<CustomButton | ||
{...props} | ||
connected | ||
onClick={handleClick(openChainModal)} | ||
color="warning" | ||
> | ||
{intl.formatMessage({ | ||
defaultMessage: 'Wrong Network', | ||
})} | ||
</CustomButton> | ||
); | ||
} | ||
|
||
return ( | ||
<CustomButton | ||
{...props} | ||
connected | ||
onClick={(evt: MouseEvent<HTMLButtonElement>) => { | ||
if (props?.onClick) { | ||
props.onClick(evt); | ||
} | ||
openAccountModal(); | ||
}} | ||
> | ||
<AddressLabel | ||
address={account.address as HexAddress} | ||
enableEnsName | ||
/> | ||
</CustomButton> | ||
); | ||
}} | ||
</ConnectButton.Custom> | ||
); | ||
}; |
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 @@ | ||
export * from './components/AddressLabel'; | ||
export * from './components/OpenAccountModalButton'; |
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,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"jsx": "react-jsx", | ||
"allowJs": false, | ||
"esModuleInterop": false, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": false | ||
}, | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
} | ||
], | ||
"extends": "../../../tsconfig.base.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,13 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../../dist/out-tsc", | ||
"types": ["node"] | ||
}, | ||
"files": [ | ||
"../../../node_modules/@nx/react/typings/cssmodule.d.ts", | ||
"../../../node_modules/@nx/react/typings/image.d.ts" | ||
], | ||
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.spec.tsx", "src/**/*.test.tsx", "src/**/*.spec.js", "src/**/*.test.js", "src/**/*.spec.jsx", "src/**/*.test.jsx"], | ||
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.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
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
Oops, something went wrong.