Skip to content

Commit

Permalink
Merge branch 'binance' into 'dev'
Browse files Browse the repository at this point in the history
Implement the Binance network

See merge request ergo/rosen-bridge/ui!393
  • Loading branch information
zargarzadehm committed Dec 28, 2024
2 parents 936ec5d + 79a735c commit 32bd402
Show file tree
Hide file tree
Showing 46 changed files with 599 additions and 308 deletions.
6 changes: 6 additions & 0 deletions .changeset/heavy-balloons-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rosen-ui/wallet-api': minor
---

- Implement standardized error messages for wallets to centralize and streamline error reporting
- Implement the isConnected method to verify whether the connection to the wallet extension is established
5 changes: 5 additions & 0 deletions .changeset/proud-suits-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-ui/metamask-wallet': minor
---

Improve MetamaskWallet class to support all EVM chains
4 changes: 3 additions & 1 deletion apps/rosen/.env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
CARDANO_KOIOS_API=''
ERGO_EXPLORER_API=''
BITCOIN_ESPLORA_API=''
ETHEREUM_BLAST_API=
ETHEREUM_RPC_API=''
BINANCE_RPC_API=''
NEXT_PUBLIC_BINANCE_LOCK_ADDRESS=''
NEXT_PUBLIC_ERGO_LOCK_ADDRESS=''
NEXT_PUBLIC_CARDANO_LOCK_ADDRESS=''
NEXT_PUBLIC_BITCOIN_LOCK_ADDRESS=''
Expand Down
57 changes: 33 additions & 24 deletions apps/rosen/app/(bridge)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Alert, styled } from '@rosen-bridge/ui-kit';
import { NETWORKS } from '@rosen-ui/constants';
import { RosenAmountValue } from '@rosen-ui/types';

import { WalletProvider } from '@/_hooks';

import { BridgeForm } from './BridgeForm';
import { BridgeTransaction } from './BridgeTransaction';
import { ConnectOrSubmitButton } from './ConnectOrSubmitButton';
Expand Down Expand Up @@ -79,30 +81,37 @@ const RosenBridge = () => {
<>
<Background />
<FormProvider {...methods}>
<BridgeContainer>
<BridgeForm />
<BridgeTransaction
chooseWalletsModalOpen={chooseWalletsModalOpen}
setChooseWalletsModalOpen={setChooseWalletsModalOpen}
/>
{methods.getValues().source == NETWORKS.ETHEREUM && (
<Alert
severity="warning"
sx={{ gridColumn: '1 / span 2', textAlign: 'justify' }}
>
If you are using Ledger, you may need to enable &apos;Blind
signing&apos; and &apos;Debug data&apos; in the Ledger (Ethereum
&gt; Settings) due to{' '}
<a href="https://github.com/LedgerHQ/app-ethereum/issues/311">
a known issue in Ledger and MetaMask interaction
</a>
.
</Alert>
)}
<ConnectOrSubmitButton
setChooseWalletsModalOpen={setChooseWalletsModalOpen}
/>
</BridgeContainer>
<WalletProvider>
<BridgeContainer>
<BridgeForm />
<BridgeTransaction
chooseWalletsModalOpen={chooseWalletsModalOpen}
setChooseWalletsModalOpen={setChooseWalletsModalOpen}
/>
{/*
TODO: Add a condition that activates this alert specifically when MetaMask is selected
local:ergo/rosen-bridge/ui#486
*/}
{(methods.getValues().source == NETWORKS.BINANCE ||
methods.getValues().source == NETWORKS.ETHEREUM) && (
<Alert
severity="warning"
sx={{ gridColumn: '1 / span 2', textAlign: 'justify' }}
>
If you are using Ledger, you may need to enable &apos;Blind
signing&apos; and &apos;Debug data&apos; in the Ledger (Ethereum
&gt; Settings) due to{' '}
<a href="https://github.com/LedgerHQ/app-ethereum/issues/311">
a known issue in Ledger and MetaMask interaction
</a>
.
</Alert>
)}
<ConnectOrSubmitButton
setChooseWalletsModalOpen={setChooseWalletsModalOpen}
/>
</BridgeContainer>
</WalletProvider>
</FormProvider>
</>
);
Expand Down
5 changes: 1 addition & 4 deletions apps/rosen/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { App as AppBase } from '@rosen-bridge/ui-kit';

import { theme } from '@/_theme/theme';

import { WalletContextProvider } from './_contexts/walletContext';
import { TokenMapProvider } from './_hooks';
import { SideBar } from './SideBar';
import { Toolbar } from './Toolbar';
Expand All @@ -20,9 +19,7 @@ export const App = ({ children }: { children?: React.ReactNode }) => {
return (
<NoSsr>
<AppBase sideBar={<SideBar />} theme={theme} toolbar={<Toolbar />}>
<TokenMapProvider>
<WalletContextProvider>{children}</WalletContextProvider>
</TokenMapProvider>
<TokenMapProvider>{children}</TokenMapProvider>
</AppBase>
</NoSsr>
);
Expand Down
5 changes: 3 additions & 2 deletions apps/rosen/app/_actions/calculateFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { ErgoNetworkType, MinimumFeeBox } from '@rosen-bridge/minimum-fee';
import cardanoKoiosClientFactory from '@rosen-clients/cardano-koios';
import ergoExplorerClientFactory from '@rosen-clients/ergo-explorer';
import { getHeight as ethereumGetHeight } from '@rosen-network/ethereum';
import { EvmChains, getHeight } from '@rosen-network/evm';
import { NETWORKS, NETWORK_VALUES } from '@rosen-ui/constants';
import { Network } from '@rosen-ui/types';
import Joi from 'joi';
Expand All @@ -18,7 +18,8 @@ const ergoExplorerClient = ergoExplorerClientFactory(
);

const GetHeight = {
[NETWORKS.ETHEREUM]: ethereumGetHeight,
[NETWORKS.BINANCE]: () => getHeight(EvmChains.BINANCE),
[NETWORKS.ETHEREUM]: () => getHeight(EvmChains.ETHEREUM),
[NETWORKS.CARDANO]: async () =>
(await cardanoKoiosClient.getTip())[0].block_no,
[NETWORKS.ERGO]: async () =>
Expand Down
58 changes: 0 additions & 58 deletions apps/rosen/app/_contexts/walletContext.tsx

This file was deleted.

13 changes: 6 additions & 7 deletions apps/rosen/app/_hooks/useBridgeForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { Network, RosenAmountValue } from '@rosen-ui/types';
import { getNonDecimalString } from '@rosen-ui/utils';

import { validateAddress } from '@/_actions';
import { WalletContext } from '@/_contexts/walletContext';
import { availableNetworks } from '@/_networks';
import { unwrap } from '@/_safeServerAction';
import { getMaxTransfer, getMinTransfer } from '@/_utils';

import { useTokenMap } from './useTokenMap';
import { useTransactionFormData } from './useTransactionFormData';
import { WalletContext } from './useWallet';

/**
* handles the form field registrations and form state changes
Expand Down Expand Up @@ -67,7 +67,7 @@ export const useBridgeForm = () => {
getNonDecimalString(value, decimals),
) as RosenAmountValue;

if (walletGlobalContext?.state.selectedWallet) {
if (walletGlobalContext?.selectedWallet) {
// prevent user from entering more than token amount

const selectedNetwork =
Expand All @@ -76,15 +76,14 @@ export const useBridgeForm = () => {
const maxTransfer = await getMaxTransfer(
selectedNetwork,
{
balance:
await walletGlobalContext!.state.selectedWallet.getBalance(
tokenField.value,
),
balance: await walletGlobalContext!.selectedWallet.getBalance(
tokenField.value,
),
isNative: tokenField.value.metaData.type === 'native',
},
async () => ({
fromAddress:
await walletGlobalContext!.state.selectedWallet!.getAddress(),
await walletGlobalContext!.selectedWallet!.getAddress(),
toAddress: addressField.value,
toChain: targetField.value as Network,
}),
Expand Down
118 changes: 0 additions & 118 deletions apps/rosen/app/_hooks/useWallet.ts

This file was deleted.

Loading

0 comments on commit 32bd402

Please sign in to comment.