Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to change network and use custom rpc on each one #288

Merged
merged 41 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
72dc139
Merge pull request #149 from invariant-labs/dev
p6te Jun 28, 2024
8d0a02d
Merge pull request #150 from invariant-labs/staging
p6te Jun 28, 2024
300b925
Merge pull request #158 from invariant-labs/dev
wojciech-cichocki Jul 2, 2024
1279912
Merge pull request #159 from invariant-labs/staging
p6te Jul 2, 2024
d99fa1e
Merge pull request #163 from invariant-labs/dev
wojciech-cichocki Jul 4, 2024
c864395
Merge pull request #191 from invariant-labs/dev
wojciech-cichocki Jul 12, 2024
2302145
Merge pull request #195 from invariant-labs/dev
wojciech-cichocki Jul 13, 2024
a55b545
Merge pull request #196 from invariant-labs/staging
wojciech-cichocki Jul 13, 2024
f9a77a1
Merge pull request #215 from invariant-labs/dev
wojciech-cichocki Jul 21, 2024
24453f3
Merge pull request #216 from invariant-labs/staging
wojciech-cichocki Jul 21, 2024
6869f62
Merge pull request #241 from invariant-labs/dev
wojciech-cichocki Jul 28, 2024
9d63d4e
Merge pull request #242 from invariant-labs/staging
wojciech-cichocki Jul 28, 2024
84e84a9
Merge pull request #249 from invariant-labs/dev
wojciech-cichocki Jul 29, 2024
056a5fa
Merge pull request #250 from invariant-labs/staging
wojciech-cichocki Jul 29, 2024
bc72f9a
Merge pull request #253 from invariant-labs/dev
wojciech-cichocki Jul 31, 2024
2a55dff
Merge pull request #254 from invariant-labs/staging
wojciech-cichocki Jul 31, 2024
cbc7b2f
Merge pull request #257 from invariant-labs/dev
wojciech-cichocki Aug 4, 2024
912bf6f
Merge pull request #258 from invariant-labs/staging
wojciech-cichocki Aug 4, 2024
c1d8e90
Merge pull request #263 from invariant-labs/dev
p6te Aug 6, 2024
117bcbb
Merge pull request #264 from invariant-labs/staging
p6te Aug 6, 2024
37315e6
Merge pull request #276 from invariant-labs/dev
p6te Aug 9, 2024
bf2ff72
Merge pull request #277 from invariant-labs/staging
p6te Aug 9, 2024
0ebd656
Merge pull request #279 from invariant-labs/dev
wojciech-cichocki Aug 15, 2024
862ebe7
Merge pull request #280 from invariant-labs/staging
wojciech-cichocki Aug 15, 2024
40e4714
Merge pull request #282 from invariant-labs/dev
p6te Aug 27, 2024
3b1cb5d
Merge pull request #283 from invariant-labs/staging
p6te Aug 27, 2024
7506bed
Merge pull request #285 from invariant-labs/dev
p6te Aug 28, 2024
0e04bd2
Merge pull request #286 from invariant-labs/staging
p6te Aug 28, 2024
39bd123
add ability to change network and use custom rpc on each one
zielvna Aug 28, 2024
9a0cc5e
add ability to switch between networks
zielvna Aug 29, 2024
a7b1da6
fix build
zielvna Aug 29, 2024
8c30227
fix default rpc when changing networks
zielvna Aug 30, 2024
40c0b86
prevent app from refreshing on rpc address change
zielvna Aug 30, 2024
4f248d6
add faucet to mainnet
zielvna Aug 30, 2024
6c4870c
add faucet and rpc to mobile menu on mainnet and make initial tokens …
zielvna Aug 30, 2024
6be4397
Merge pull request #291 from invariant-labs/dev
wojciech-cichocki Aug 31, 2024
703b756
Merge pull request #292 from invariant-labs/staging
wojciech-cichocki Aug 31, 2024
fd766b4
change rpcs names
zielvna Sep 2, 2024
430927d
Merge branch 'master' into mainnet-support
zielvna Sep 2, 2024
b95c005
fix build
zielvna Sep 2, 2024
1598b7a
fix calculate amount in with slippage function
zielvna Sep 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@invariant-labs/a0-sdk": "^0.2.17",
"@invariant-labs/a0-sdk": "^0.2.19",
"@mui/icons-material": "^5.15.15",
"@mui/material": "^5.15.15",
"@nightlylabs/wallet-selector-polkadot": "^0.2.5",
Expand Down
4 changes: 3 additions & 1 deletion src/components/Header/Header.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export const Primary: Story = {
name: Chain.AlephZero,
address: 'https://azero.invariant.app/swap'
},
onChainSelect: fn()
onChainSelect: fn(),
network: Network.Testnet,
defaultMainnetRPC: 'https://rpc.moonbeam.network'
}
}
74 changes: 53 additions & 21 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Network } from '@invariant-labs/a0-sdk'
import SelectChainButton from './HeaderButton/SelectChainButton'
import { ISelectChain } from '@store/consts/types'
import SelectChain from '@components/Modals/SelectChain/SelectChain'
import SelectMainnetRPC from '@components/Modals/SelectMainnetRPC/SelectMainnetRPC'

export interface IHeader {
address: string
Expand All @@ -35,6 +36,8 @@ export interface IHeader {
onChangeWallet: () => void
activeChain: ISelectChain
onChainSelect: (chain: ISelectChain) => void
network: Network
defaultMainnetRPC: string
}

export const Header: React.FC<IHeader> = ({
Expand All @@ -51,7 +54,9 @@ export const Header: React.FC<IHeader> = ({
onCopyAddress,
onChangeWallet,
activeChain,
onChainSelect
onChainSelect,
network,
defaultMainnetRPC
}) => {
const { classes } = useStyles()
const buttonStyles = useButtonStyles()
Expand Down Expand Up @@ -81,7 +86,15 @@ export const Header: React.FC<IHeader> = ({
{
networkType: Network.Testnet,
rpc: RPC.TEST,
rpcName: 'Aleph Zero'
rpcName: 'Aleph Zero Testnet'
}
]

const mainnetRPCs = [
{
networkType: Network.Mainnet,
rpc: RPC.MAIN,
rpcName: 'Aleph Zero Mainnet'
}
]

Expand Down Expand Up @@ -148,22 +161,23 @@ export const Header: React.FC<IHeader> = ({

<Grid container item className={classes.buttons} wrap='nowrap'>
<Grid container className={classes.leftButtons}>
{typeOfNetwork === Network.Testnet ? (
<Box sx={{ display: { xs: 'none', md: 'block' } }}>
<Button
className={buttonStyles.classes.headerButton}
variant='contained'
sx={{ '& .MuiButton-label': buttonStyles.classes.label }}
onClick={onFaucet}>
Faucet
</Button>
</Box>
) : null}
{typeOfNetwork === Network.Testnet ? (
<Box sx={{ display: { xs: 'none', md: 'block' } }}>
<SelectRPCButton rpc={rpc} networks={testnetRPCs} onSelect={onNetworkSelect} />
</Box>
) : null}
<Box sx={{ display: { xs: 'none', md: 'block' } }}>
<Button
className={buttonStyles.classes.headerButton}
variant='contained'
sx={{ '& .MuiButton-label': buttonStyles.classes.label }}
onClick={onFaucet}>
Faucet
</Button>
</Box>
<Box sx={{ display: { xs: 'none', md: 'block' } }}>
<SelectRPCButton
rpc={rpc}
networks={network === Network.Testnet ? testnetRPCs : mainnetRPCs}
onSelect={onNetworkSelect}
network={network}
/>
</Box>
<Box sx={{ display: { xs: 'none', md: 'block' } }}>
<SelectChainButton
activeChain={activeChain}
Expand All @@ -179,6 +193,12 @@ export const Header: React.FC<IHeader> = ({
rpc: defaultTestnetRPC,
rpcName:
testnetRPCs.find(data => data.rpc === defaultTestnetRPC)?.rpcName ?? 'Custom'
},
{
networkType: Network.Mainnet,
rpc: defaultMainnetRPC,
rpcName:
mainnetRPCs.find(data => data.rpc === defaultMainnetRPC)?.rpcName ?? 'Custom'
}
]}
onSelect={onNetworkSelect}
Expand Down Expand Up @@ -231,9 +251,9 @@ export const Header: React.FC<IHeader> = ({
setRoutesModalOpen(false)
unblurContent()
}}
onFaucet={typeOfNetwork === Network.Testnet && isMdDown ? onFaucet : undefined}
onFaucet={isMdDown ? onFaucet : undefined}
onRPC={
typeOfNetwork === Network.Testnet && isMdDown
isMdDown
? () => {
setRoutesModalOpen(false)
setTestnetRpcsOpen(true)
Expand Down Expand Up @@ -261,7 +281,19 @@ export const Header: React.FC<IHeader> = ({
}}
activeRPC={rpc}
/>
) : null}
) : (
<SelectMainnetRPC
zielvna marked this conversation as resolved.
Show resolved Hide resolved
networks={mainnetRPCs}
open={testnetRpcsOpen}
anchorEl={routesModalAnchor}
onSelect={onNetworkSelect}
handleClose={() => {
setTestnetRpcsOpen(false)
unblurContent()
}}
activeRPC={rpc}
/>
)}
<SelectChain
chains={CHAINS}
open={chainSelectOpen}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const Primary: Story = {
rpcName: 'Testnet'
}
],
onSelect: (networkType, rpc) => action('chosen: ' + networkType + ' ' + rpc)()
onSelect: (networkType, rpc) => action('chosen: ' + networkType + ' ' + rpc)(),
network: Network.Testnet
}
}
32 changes: 23 additions & 9 deletions src/components/Header/HeaderButton/SelectRPCButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ import { Button } from '@mui/material'
import SelectTestnetRPC from '@components/Modals/SelectTestnetRPC/SelectTestnetRPC'
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'
import { Network } from '@invariant-labs/a0-sdk'
import SelectMainnetRPC from '@components/Modals/SelectMainnetRPC/SelectMainnetRPC'

export interface IProps {
rpc: string
networks: ISelectNetwork[]
onSelect: (networkType: Network, rpcAddress: string, rpcName?: string) => void
disabled?: boolean
network: Network
}
export const SelectRPCButton: React.FC<IProps> = ({
rpc,
networks,
onSelect,
disabled = false
disabled = false,
network
}) => {
const { classes } = useStyles()
const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(null)
Expand Down Expand Up @@ -45,14 +48,25 @@ export const SelectRPCButton: React.FC<IProps> = ({
onClick={handleClick}>
RPC
</Button>
<SelectTestnetRPC
networks={networks}
open={openTestnetRpcs}
anchorEl={anchorEl}
onSelect={onSelect}
handleClose={handleClose}
activeRPC={rpc}
/>
{network === Network.Testnet ? (
<SelectTestnetRPC
networks={networks}
open={openTestnetRpcs}
anchorEl={anchorEl}
onSelect={onSelect}
handleClose={handleClose}
activeRPC={rpc}
/>
) : (
<SelectMainnetRPC
networks={networks}
open={openTestnetRpcs}
anchorEl={anchorEl}
onSelect={onSelect}
handleClose={handleClose}
activeRPC={rpc}
/>
)}
</>
)
}
Expand Down
27 changes: 27 additions & 0 deletions src/components/Modals/SelectMainnetRPC/SelectMainnetRPC.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Meta, StoryObj } from '@storybook/react'
import SelectMainnetRPC from './SelectMainnetRPC'
import { Network } from '@invariant-labs/a0-sdk'

const meta = {
title: 'Modals/SelectRPC',
component: SelectMainnetRPC,
args: {
activeRPC: 'https://mainnet-mock.com',
anchorEl: null,
handleClose: () => {},
networks: [
{
networkType: Network.Mainnet,
rpc: 'https://mainnet-mock.com',
rpcName: 'Mainnet'
}
],
onSelect: () => {},
open: true
}
} satisfies Meta<typeof SelectMainnetRPC>

export default meta
type Story = StoryObj<typeof meta>

export const Primary: Story = {}
Loading
Loading