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

feat: Some ui updates & Header chain switch update #38

Merged
merged 31 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
101199d
feat: Some ui updates & Header chain switch update
aiden-cao Oct 23, 2024
36beeb4
feat: Release new alpha version
wenty22 Oct 23, 2024
7271850
chore: Add change log
wenty22 Oct 23, 2024
04a95fa
Merge branch 'main' into feat/update-switch-network
wenty22 Oct 23, 2024
99e6e07
chore: Test release
wenty22 Oct 23, 2024
9a52a22
Merge branch 'main' into feat/update-switch-network
wenty22 Oct 23, 2024
c090bb9
chore: Test release
wenty22 Oct 23, 2024
5946352
chore: Update versions (alpha)
github-actions[bot] Oct 23, 2024
8d16a93
Merge pull request #44 from bnb-chain/changeset-release/feat/update-s…
wenty22 Oct 23, 2024
d2c4330
chore: Add change log
wenty22 Oct 23, 2024
da29147
chore: Add command to publish alpha packages
wenty22 Oct 23, 2024
66ec1c0
feat: Update switch network copy
aiden-cao Oct 23, 2024
d8b47c6
Merge branch 'main' into feat/update-switch-network
aiden-cao Oct 24, 2024
50c8a09
fix: Fix input focus issue
Halibao-Lala Oct 25, 2024
784dafd
Merge pull request #67 from bnb-chain/fix/meson
Halibao-Lala Oct 25, 2024
04279ef
fix: Fix checkbox styling
Halibao-Lala Oct 25, 2024
f68313e
Merge pull request #68 from bnb-chain/fix/meson
Halibao-Lala Oct 25, 2024
8dc4f60
chore: Update version
Halibao-Lala Oct 25, 2024
a6f15d4
chore: Remove input icon
Halibao-Lala Oct 29, 2024
718feb6
Merge pull request #70 from bnb-chain/fix/meson
Halibao-Lala Oct 29, 2024
b53c9e6
chore: Test server cicd
wenty22 Oct 24, 2024
7df2257
chore: Update timeout to 30m
wenty22 Oct 24, 2024
c80c95e
feat(canonical-bridge-widget): Update widget ui
aiden-cao Oct 29, 2024
aed642a
feat(canonical-bridge-widget): Update widget ui
aiden-cao Nov 1, 2024
46a47b2
Merge branch 'main' into feat/update-switch-network
aiden-cao Nov 1, 2024
cf6063a
feat(canonical-bridge-widget): Update widget ui
aiden-cao Nov 3, 2024
ee4e63e
feat(canonical-bridge-widget): Update widget ui
aiden-cao Nov 3, 2024
743e39d
feat(canonical-bridge-widget): Update widget ui
aiden-cao Nov 3, 2024
0473c82
feat(canonical-bridge-widget): Update widget ui
aiden-cao Nov 3, 2024
8b2bcfe
feat(canonical-bridge-widget): Update widget ui
aiden-cao Nov 4, 2024
3f1f337
feat(canonical-bridge-widget): Update widget ui
aiden-cao Nov 4, 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
5 changes: 5 additions & 0 deletions .release/.changeset/polite-monkeys-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bnb-chain/canonical-bridge-widget": patch
---

Update unknown network title
13 changes: 13 additions & 0 deletions .release/.changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"mode": "pre",
"tag": "alpha",
"initialVersions": {
"@bnb-chain/canonical-bridge-sdk": "0.1.2",
"@bnb-chain/canonical-bridge-widget": "0.1.4"
},
"changesets": [
"polite-monkeys-share",
"rare-grapes-act",
"sixty-scissors-protect"
]
}
5 changes: 5 additions & 0 deletions .release/.changeset/rare-grapes-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bnb-chain/canonical-bridge-widget": patch
---

Some ui updates & Header chain switch update
5 changes: 5 additions & 0 deletions .release/.changeset/sixty-scissors-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bnb-chain/canonical-bridge-widget": patch
---

Update ui
6 changes: 6 additions & 0 deletions packages/canonical-bridge-widget/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @bnb-chain/canonical-bridge-widget

## 0.3.2-alpha.0

### Patch Changes

- Update ui

## 0.3.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/canonical-bridge-widget/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bnb-chain/canonical-bridge-widget",
"version": "0.3.1",
"version": "0.3.2-alpha.0",
"description": "canonical bridge widget",
"author": "bnb-chain",
"private": false,
Expand Down
2 changes: 2 additions & 0 deletions packages/canonical-bridge-widget/src/core/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export const en = {
'select-modal.destination.incompatible.tooltip':
'The token you’ve selected is incompatible with this network. Please select another token.',

'wallet.network.switch-network': 'Please switch the network',
'wallet.network.unknown-network': 'Unsupported Network',
'wallet.button.connect-wallet': 'Connect Wallet',
'wallet.network.wrong-network': 'Wrong network',
'wallet.error.switch-network':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect } from 'react';
import { useAccount } from 'wagmi';

import { useAppDispatch } from '@/modules/store/StoreProvider';
import { setSendValue } from '@/modules/transfer/action';
Expand All @@ -9,12 +10,13 @@ export function useDefaultSelectedInfo() {
const { isReady, defaultSelectedInfo } = useAggregator();
const { selectDefault } = useSelection();
const dispatch = useAppDispatch();
const { chainId } = useAccount();

useEffect(() => {
if (isReady) {
selectDefault(defaultSelectedInfo);
dispatch(setSendValue(defaultSelectedInfo.amount));
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isReady]);
}, [isReady, chainId]);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useChains } from 'wagmi';
import { useChains, useAccount } from 'wagmi';
import { useCallback } from 'react';

import { useAggregator } from '@/modules/aggregator/components/AggregatorProvider';
Expand All @@ -18,7 +18,9 @@ import { useTronWeb } from '@/core/hooks/useTronWeb';
import { useCurrentWallet } from '@/modules/wallet/CurrentWalletProvider';

export function useSelection() {
const { getFromChains, getToChains, getTokens, getToToken, adapters } = useAggregator();
const { chainId } = useAccount();
const { getFromChains, getToChains, getTokens, getToToken, adapters, defaultSelectedInfo } =
useAggregator();

const fromChain = useAppSelector((state) => state.transfer.fromChain);
const toChain = useAppSelector((state) => state.transfer.toChain);
Expand Down Expand Up @@ -79,6 +81,38 @@ export function useSelection() {
});
};

const selectFromChain = async (tmpFromChain: IBridgeChain) => {
// After selecting fromChain, if toChain becomes incompatible, reselect the first compatible network in toChain list.
const toChains = getToChains({
fromChainId: tmpFromChain.id,
});
const tmpToChain =
toChains.find((c) => isChainOrTokenCompatible(c) && c.id === toChain?.id) ??
toChains.find((c) => isChainOrTokenCompatible(c) && c.chainType !== 'link');

const tmpTokens = await getSortedTokens({
chainType: tmpFromChain.chainType,
fromChainId: tmpFromChain.id,
tokens: getTokens({
fromChainId: tmpFromChain.id,
toChainId: tmpToChain?.id,
}),
});

const newToken =
tmpTokens.find(
(t) =>
isChainOrTokenCompatible(t) &&
t.displaySymbol.toUpperCase() === selectedToken?.displaySymbol.toUpperCase(),
) ?? tmpTokens.find((t) => isChainOrTokenCompatible(t));

updateSelectedInfo({
tmpToken: newToken,
tmpFromChain,
tmpToChain,
});
};

return {
async selectDefault({
fromChainId,
Expand All @@ -94,6 +128,15 @@ export function useSelection() {
bridgeTypes.map((item) => [item, { symbol: tokenSymbol }]),
) as any as IBridgeToken;

if (chainId && chainId !== defaultSelectedInfo.fromChainId) {
const fromChains = getFromChains({});
const chain = fromChains.find((chain) => chain.id === chainId);
if (chain) {
selectFromChain(chain);
return;
}
}

const fromChains = getFromChains({
toChainId,
token,
Expand Down Expand Up @@ -123,44 +166,11 @@ export function useSelection() {
token: newToken,
});
},

async selectFromChain(tmpFromChain: IBridgeChain) {
// After selecting fromChain, if toChain becomes incompatible, reselect the first compatible network in toChain list.
const toChains = getToChains({
fromChainId: tmpFromChain.id,
});
const tmpToChain =
toChains.find((c) => isChainOrTokenCompatible(c) && c.id === toChain?.id) ??
toChains.find((c) => isChainOrTokenCompatible(c) && c.chainType !== 'link');

const tmpTokens = await getSortedTokens({
chainType: tmpFromChain.chainType,
fromChainId: tmpFromChain.id,
tokens: getTokens({
fromChainId: tmpFromChain.id,
toChainId: tmpToChain?.id,
}),
});

const newToken =
tmpTokens.find(
(t) =>
isChainOrTokenCompatible(t) &&
t.displaySymbol.toUpperCase() === selectedToken?.displaySymbol.toUpperCase(),
) ?? tmpTokens.find((t) => isChainOrTokenCompatible(t));

updateSelectedInfo({
tmpToken: newToken,
tmpFromChain,
tmpToChain,
});
},

selectFromChain,
async selectToChain(tmpToChain: IBridgeChain) {
const fromChainId = fromChain!.id;

const tmpTokens = await getSortedTokens({
chainType: fromChain?.chainType,
fromChainId,
tokens: getTokens({
fromChainId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Button, useColorMode, useIntl, useTheme } from '@bnb-chain/space';
import { Button, useColorMode, useIntl, useTheme, ButtonProps } from '@bnb-chain/space';

import { useAppSelector } from '@/modules/store/StoreProvider';
import { reportEvent } from '@/core/utils/gtm';
import { useCurrentWallet } from '@/modules/wallet/CurrentWalletProvider';

export const SwitchNetworkButton = () => {
export const SwitchNetworkButton = (props: ButtonProps) => {
const { formatMessage } = useIntl();

const fromChain = useAppSelector((state) => state.transfer.fromChain);
Expand Down Expand Up @@ -36,6 +36,7 @@ export const SwitchNetworkButton = () => {
},
});
}}
{...props}
>
{formatMessage({ id: 'transfer.button.switch-network' })}
</Button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import {
Flex,
Typography,
useBreakpointValue,
useColorMode,
useDisclosure,
useIntl,
useTheme,
} from '@bnb-chain/space';
import { Flex, Typography, useColorMode, useDisclosure, useIntl, useTheme } from '@bnb-chain/space';

import { SelectButton } from '@/modules/transfer/components/SelectButton';
import { useAppSelector } from '@/modules/store/StoreProvider';
Expand All @@ -16,26 +8,27 @@ import { SourceNetworkModal } from '@/modules/aggregator/components/SelectModal/
export function FromSection() {
const { colorMode } = useColorMode();
const { isOpen, onClose, onOpen } = useDisclosure();
const isBase = useBreakpointValue({ base: true, md: false }) ?? false;
const { formatMessage } = useIntl();

const fromChain = useAppSelector((state) => state.transfer.fromChain);
const theme = useTheme();

return (
<Flex flexDir="column" gap={'12px'} w={'100%'} flex={1} h={'64px'}>
{isBase ? (
<Flex alignItems="center" justifyContent={'space-between'}>
<Typography
variant="body"
lineHeight={'16px'}
size={'sm'}
color={theme.colors[colorMode].text.placeholder}
>
{formatMessage({ id: 'from.section.title' })}
</Typography>
</Flex>
) : null}
<Flex
alignItems="center"
justifyContent={'space-between'}
display={{ base: 'flex', md: 'none' }}
>
<Typography
variant="body"
lineHeight={'16px'}
size={'sm'}
color={theme.colors[colorMode].text.placeholder}
>
{formatMessage({ id: 'from.section.title' })}
</Typography>
</Flex>

<SelectButton
isActive={isOpen}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
Flex,
Typography,
useBreakpointValue,
useColorMode,
useIntl,
useTheme,
} from '@bnb-chain/space';
import { Flex, Typography, useColorMode, useIntl, useTheme } from '@bnb-chain/space';

import { TransferToIcon } from '@/core/components/icons/TransferToIcon';
import { FromSection } from '@/modules/transfer/components/FromSection';
Expand All @@ -15,36 +8,37 @@ export const NetWorkSection = () => {
const { formatMessage } = useIntl();
const { colorMode } = useColorMode();
const theme = useTheme();
const isBase = useBreakpointValue({ base: true, md: false }) ?? false;

return (
<Flex flexDir={'column'} gap={'12px'}>
{!isBase ? (
<>
<Flex flexDir={'row'}>
<Flex alignItems="center" justifyContent={'space-between'} flex={1}>
<Typography
variant="body"
size={'sm'}
lineHeight={'16px'}
color={theme.colors[colorMode].text.placeholder}
>
{formatMessage({ id: 'from.section.title' })}
</Typography>
</Flex>
<Flex alignItems="center" justifyContent={'space-between'} flex={1} ml="49px">
<Typography
variant="body"
lineHeight={'16px'}
size={'sm'}
color={theme.colors[colorMode].text.placeholder}
>
{formatMessage({ id: 'to.section.title' })}
</Typography>
</Flex>
</Flex>{' '}
</>
) : null}
<Flex flexDir={'row'} display={{ base: 'none', md: 'flex' }}>
<Flex alignItems="center" justifyContent={'space-between'} flex={1}>
<Typography
variant="body"
size={'sm'}
lineHeight={'16px'}
color={theme.colors[colorMode].text.placeholder}
>
{formatMessage({ id: 'from.section.title' })}
</Typography>
</Flex>
<Flex
alignItems="center"
justifyContent={'space-between'}
flex={1}
ml="49px"
display={{ base: 'none', md: 'flex' }}
>
<Typography
variant="body"
lineHeight={'16px'}
size={'sm'}
color={theme.colors[colorMode].text.placeholder}
>
{formatMessage({ id: 'to.section.title' })}
</Typography>
</Flex>
</Flex>{' '}
<Flex
flexDir={['column', 'column', 'row']}
justifyContent={'space-between'}
Expand All @@ -53,7 +47,7 @@ export const NetWorkSection = () => {
minW={0}
>
<FromSection />
<TransferToIcon w={'24px'} h={'24px'} transform={!isBase ? '' : 'rotate(90deg)'} />
<TransferToIcon w={'24px'} h={'24px'} transform={{ base: 'rotate(90deg)', md: 'none' }} />
<ToSection />
</Flex>
</Flex>
Expand Down
Loading