Skip to content

Commit

Permalink
fix(ui-ux): cfp valid address warning (#4150)
Browse files Browse the repository at this point in the history
* fix(ui-ux): cfp valid address warning

* fix(ui-ux): restrict evm address in cfp
  • Loading branch information
pierregee authored Dec 1, 2023
1 parent 7dd1836 commit 3fbff35
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function AddressRow({
onAddressType,
showQrButton = true,
onlyLocalAddress,
restrictedJellyfishAddressType,
matchedAddress,
setMatchedAddress,
setAddressLabel,
Expand All @@ -63,6 +64,7 @@ export function AddressRow({
onAddressType?: (addressType?: AddressType) => void;
showQrButton?: boolean;
onlyLocalAddress?: boolean;
restrictedJellyfishAddressType?: JellyfishAddressType[];
matchedAddress?: LocalAddress | WhitelistedAddress | undefined;
setMatchedAddress?: (address?: LocalAddress | WhitelistedAddress) => void;
setAddressLabel?: React.Dispatch<React.SetStateAction<string | undefined>>;
Expand All @@ -86,14 +88,24 @@ export function AddressRow({
const [validEvmAddress, setValidEvmAddress] = useState<boolean>(false);

const validLocalAddress = useMemo(() => {
if (
restrictedJellyfishAddressType?.some(
(addressType) => addressType === getAddressType(address, networkName),
)
) {
return false;
}

if (address === "") {
return true;
}

if (onlyLocalAddress) {
return addressType === AddressType.WalletAddress;
}

return true;
}, [onlyLocalAddress, addressType, address]);
}, [onlyLocalAddress, addressType, address, networkName]);

const addressObj = jellyfishWalletAddress.find(
(e: WalletAddressI) => e.dvm === address || e.evm === address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from "@hooks/wallet/Conversion";
import { useSelector } from "react-redux";
import { RootState } from "@store";
import { LocalAddress, WhitelistedAddress } from "@store/userPreferences";
import {
DFITokenSelector,
DFIUtxoSelector,
Expand All @@ -34,6 +35,7 @@ import { AddressRow } from "@screens/AppNavigator/screens/Portfolio/components/A
import { ButtonGroupTabKey } from "@screens/AppNavigator/screens/Portfolio/screens/AddressBookScreen";
import { DomainType } from "@contexts/DomainContext";
import { ConvertDirection } from "@screens/enum";
import { AddressType as JellyfishAddressType } from "@waveshq/walletkit-core";

export function CFPDetailScreen(): JSX.Element {
const logger = useLogger();
Expand All @@ -47,6 +49,9 @@ export function CFPDetailScreen(): JSX.Element {
const proposalFee = getCFPFee(BigNumber(amount ?? 0));
const navigation = useNavigation<NavigationProp<PortfolioParamList>>();
const [isUrlValid, setUrlValid] = useState<boolean>(false);
const [matchedAddress, setMatchedAddress] = useState<
LocalAddress | WhitelistedAddress
>();

const DFIToken = useSelector((state: RootState) =>
DFITokenSelector(state.wallet),
Expand Down Expand Up @@ -268,7 +273,11 @@ export function CFPDetailScreen(): JSX.Element {
await trigger("address");
}}
address={address}
onMatchedAddress={setMatchedAddress}
setMatchedAddress={setMatchedAddress}
matchedAddress={matchedAddress}
onlyLocalAddress
restrictedJellyfishAddressType={[JellyfishAddressType.ETH]}
/>
</View>
)}
Expand Down

0 comments on commit 3fbff35

Please sign in to comment.