Skip to content

Commit

Permalink
Merge pull request #140 from Cerebellum-Network/release/0.25.0
Browse files Browse the repository at this point in the history
Release 0.25.0
  • Loading branch information
shamilkhan authored Aug 21, 2023
2 parents 464f9e5 + 3bc1999 commit 4ab2aa9
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## vNext
...

## v0.25.0
- Added ability to select destination address from Polkadot-JS Web Extension or paste it manually.

## v0.24.0
- Migrated to WalletConnect v2

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@Cerebellum-Network/chainbridge-ui",
"version": "0.24.0",
"version": "0.25.0",
"private": true,
"engines": {
"node": "^16.0.0"
Expand Down
31 changes: 31 additions & 0 deletions src/Components/Custom/AddressSelectInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";
import {SelectInput} from "@chainsafe/common-components";
import {useField} from "formik";
import {DestinationChainContext} from "../../Contexts/Adaptors/interfaces";

interface IAddressSelectInput {
addresses: DestinationChainContext["addresses"];
name: string;
};

const AddressSelectInput: React.FC<IAddressSelectInput> =
({
addresses,
name,
}) => {
const [field, meta, helpers] = useField(name);

return (
<SelectInput
value={field.value}
label="Select a destination address from Polkadot.js Extension"
options={addresses}
onChange={(address) => {
helpers.setValue(address);
}}
placeholder="Select a destination address"
/>
);
};

export default AddressSelectInput;
64 changes: 44 additions & 20 deletions src/Components/Pages/TransferPage.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import React, { useEffect, useState } from "react";
import React, { useEffect, useMemo, useState } from "react";
import { makeStyles, createStyles, ITheme } from "@chainsafe/common-theme";
import AboutDrawer from "../../Modules/AboutDrawer";
import ChangeNetworkDrawer from "../../Modules/ChangeNetworkDrawer";
import PreflightModalTransfer from "../../Modules/PreflightModalTransfer";
import {
Button,
Typography,
// QuestionCircleSvg,
SelectInput,
NavLink,
Button,
Typography,
// QuestionCircleSvg,
SelectInput,
NavLink,
CheckboxInput,
} from "@chainsafe/common-components";
import { Form, Formik } from "formik";
import AddressInput from "../Custom/AddressInput";
import AddressSelectInput from "../Custom/AddressSelectInput";
import clsx from "clsx";
import TransferActiveModal from "../../Modules/TransferActiveModal";
import { useChainbridge } from "../../Contexts/ChainbridgeContext";
Expand Down Expand Up @@ -278,6 +280,9 @@ const useStyles = makeStyles(({ constants, palette }: ITheme) =>
marginBottom: constants.generalUnit * 3,
fontSize: 8,
},
destinationAddressCheckbox: {
margin: "24px 0px",
},
addressInput: {
"& > div > input": {
fontSize: "12px !important",
Expand Down Expand Up @@ -411,6 +416,7 @@ const TransferPage = () => {
checkSupplies,
} = useChainbridge();

const [shouldPasteDestinationAddressManually, setShouldPasteDestinationAddressManually] = useState(false);
const { accounts, selectAccount, disconnect } = useHomeBridge();
const [aboutOpen, setAboutOpen] = useState<boolean>(false);
const [walletConnecting, setWalletConnecting] = useState(false);
Expand All @@ -424,6 +430,8 @@ const TransferPage = () => {
tokenSymbol: "",
});

const isDestinationAddressListExists = useMemo(() => Boolean(destinationBridge.addresses.length), [destinationBridge.addresses]);

// This is a workaround for Ethereum networks uncaught exception bug
useEffect(() => {
const unhandledRejection = !!localStorage.getItem(UNHANDLED_REJECTION);
Expand Down Expand Up @@ -750,20 +758,36 @@ const TransferPage = () => {
</section>
</section>
<section>
<AddressInput
disabled={!destinationChainConfig}
name="receiver"
label="Destination Address"
placeholder="Please enter the receiving address..."
className={classes.address}
classNames={{
input: classes.addressInput,
}}
senderAddress={`${address}`}
sendToSameAccountHelper={
destinationChainConfig?.type === homeConfig?.type
}
/>
{!shouldPasteDestinationAddressManually &&
isDestinationAddressListExists ? (
<AddressSelectInput
name="receiver"
addresses={destinationBridge.addresses}
/>
): (
<AddressInput
disabled={!destinationChainConfig}
name="receiver"
label="Destination Address"
placeholder="Please enter the receiving address..."
className={classes.address}
classNames={{
input: classes.addressInput,
}}
senderAddress={`${address}`}
sendToSameAccountHelper={
destinationChainConfig?.type === homeConfig?.type
}
/>
)}
{isDestinationAddressListExists && (
<CheckboxInput
className={classes.destinationAddressCheckbox}
label="Paste a destination address manually"
value={shouldPasteDestinationAddressManually}
onChange={() => setShouldPasteDestinationAddressManually(!shouldPasteDestinationAddressManually)}
/>
)}
</section>
<FeesFormikWrapped
amountFormikName="tokenAmount"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ export const EVMDestinationAdaptorProvider = ({
<DestinationBridgeContext.Provider
value={{
disconnect: async () => {},
addresses: [],
}}
>
{children}
Expand Down
23 changes: 22 additions & 1 deletion src/Contexts/Adaptors/SubstrateDestinationAdaptor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import React, { useCallback, useEffect, useState } from "react";
import {
web3Accounts,
web3Enable,
} from "@polkadot/extension-dapp";
import { DestinationBridgeContext } from "../DestinationBridgeContext";
import { useNetworkManager } from "../NetworkManagerContext";
import {
Expand All @@ -7,7 +11,7 @@ import {
VoteStatus,
getTransferTxHashByNonce,
} from "./SubstrateApis/ChainBridgeAPI";
import { IDestinationBridgeProviderProps } from "./interfaces";
import { DestinationChainContext, IDestinationBridgeProviderProps } from "./interfaces";

import { ApiPromise } from "@polkadot/api";
import {
Expand Down Expand Up @@ -43,6 +47,8 @@ export const SubstrateDestinationAdaptorProvider = ({
} = useNetworkManager();

const [initialising, setInitialising] = useState(false);
const [addresses, setAddresses] = useState<DestinationChainContext["addresses"]>([]);

useEffect(() => {
// Once the chain ID has been set in the network context, the destination configuration will be automatically
// set thus triggering this
Expand Down Expand Up @@ -254,13 +260,28 @@ export const SubstrateDestinationAdaptorProvider = ({
}
}, [transactionStatus, fallback, initFallbackMechanism]);

useEffect(() => {
web3Enable('Cere Bridge').then(() => {
web3Accounts().then((injectedAccountsWithMeta) => {
const transformAddress = (address: string) => `${address.slice(0,5)}...${address.slice(-5)}`;

setAddresses(injectedAccountsWithMeta.map(({address, meta}) => ({
value: address,
label: `${meta.name} ( ${transformAddress(address)} )`,
})));

})
});
}, [web3Accounts, web3Enable])

return (
<DestinationBridgeContext.Provider
value={{
disconnect: async () => {
if (api?.isConnected) await api?.disconnect();
setApi(undefined);
},
addresses,
}}
>
{children}
Expand Down
1 change: 1 addition & 0 deletions src/Contexts/Adaptors/interfaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ export interface HomeChainAdaptorContext {

export interface DestinationChainContext {
disconnect: () => Promise<void>;
addresses: Array<{ value: string; label: string }>;
}
2 changes: 1 addition & 1 deletion src/Contexts/NetworkManagerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ const NetworkManagerProvider = ({ children }: INetworkManagerProviderProps) => {
return (
<DestinationBridgeContext.Provider
value={{
disconnect: async () => {},
disconnect: async () => {}, addresses: [],
}}
>
{children}
Expand Down
2 changes: 1 addition & 1 deletion src/Layouts/AppWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const useStyles = makeStyles(
},
pageArea: {
height: "100%",
overflow: "auto",
overflow: "visible",
boxShadow: "20px 4px 72px rgba(85, 85, 85, 0.15)",
borderRadius: 4,
width: "fit-content",
Expand Down

0 comments on commit 4ab2aa9

Please sign in to comment.