Skip to content

Commit

Permalink
feat: add searching by TNS on wallet address inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
WaDadidou committed Jul 11, 2023
1 parent 3e4361f commit 187ad77
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 63 deletions.
26 changes: 13 additions & 13 deletions packages/components/Search/SearchBarResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,22 @@ const SearchResultsSection: React.FC<{
const isMobile = useIsMobile();
return (
<View style={style}>
<View
style={[
{ backgroundColor: neutral22, paddingVertical: 4 },
isFirstSection &&
!isMobile && { borderTopStartRadius: 6, borderTopEndRadius: 6 },
]}
>
<BrandText
<View

Check warning on line 102 in packages/components/Search/SearchBarResults.tsx

View workflow job for this annotation

GitHub Actions / lint-and-build

Delete `··`
style={[

Check warning on line 103 in packages/components/Search/SearchBarResults.tsx

View workflow job for this annotation

GitHub Actions / lint-and-build

Delete `··`
{ marginLeft: SEARCH_RESULTS_MARGIN, color: neutralA3 },
fontSemibold12,
{ backgroundColor: neutral22, paddingVertical: 4 },

Check warning on line 104 in packages/components/Search/SearchBarResults.tsx

View workflow job for this annotation

GitHub Actions / lint-and-build

Delete `··`
isFirstSection &&

Check warning on line 105 in packages/components/Search/SearchBarResults.tsx

View workflow job for this annotation

GitHub Actions / lint-and-build

Delete `··`
!isMobile && { borderTopStartRadius: 6, borderTopEndRadius: 6 },

Check warning on line 106 in packages/components/Search/SearchBarResults.tsx

View workflow job for this annotation

GitHub Actions / lint-and-build

Delete `··`
]}

Check warning on line 107 in packages/components/Search/SearchBarResults.tsx

View workflow job for this annotation

GitHub Actions / lint-and-build

Delete `··`
>

Check warning on line 108 in packages/components/Search/SearchBarResults.tsx

View workflow job for this annotation

GitHub Actions / lint-and-build

Delete `··`
{title}
</BrandText>
</View>
<BrandText

Check warning on line 109 in packages/components/Search/SearchBarResults.tsx

View workflow job for this annotation

GitHub Actions / lint-and-build

Delete `··`
style={[

Check warning on line 110 in packages/components/Search/SearchBarResults.tsx

View workflow job for this annotation

GitHub Actions / lint-and-build

Delete `··`
{ marginLeft: SEARCH_RESULTS_MARGIN, color: neutralA3 },

Check warning on line 111 in packages/components/Search/SearchBarResults.tsx

View workflow job for this annotation

GitHub Actions / lint-and-build

Delete `··`
fontSemibold12,
]}
>
{title}
</BrandText>
</View>
<View style={{ padding: SEARCH_RESULTS_MARGIN }}>{children}</View>
</View>
);
Expand Down
55 changes: 55 additions & 0 deletions packages/components/inputs/SearchNSInputContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React, { FC } from "react";
import { StyleProp, View, ViewStyle } from "react-native";

import { useNameSearch } from "../../hooks/search/useNameSearch";
import { useSelectedNetworkId } from "../../hooks/useSelectedNetwork";
import { parseUserId } from "../../networks";
import { layout } from "../../utils/style/layout";
import { AvatarWithName } from "../user/AvatarWithName";

// Used as a wrapper on a TextInput or something like. It allows to search a name in TNS and returns the address.
export const SearchNSInputContainer: FC<{
searchText: string;
onPressName: (address: string) => void;
style?: StyleProp<ViewStyle>;
}> = ({ searchText, onPressName, style, children }) => {
const selectedNetworkId = useSelectedNetworkId();
const { names } = useNameSearch({
networkId: selectedNetworkId,
input: searchText,
limit: 12,
});
const hasNames = !!names.length;

const onPress = (userId: string) => {
const [, userAddress] = parseUserId(userId);
onPressName(userAddress);
};

return (
<>
{children}
{hasNames && (
<View
style={[
{
flexDirection: "row",
flexWrap: "wrap",
marginTop: layout.padding_x1_5,
},
style,
]}
>
{names.map((n) => (
<AvatarWithName
key={n}
networkId={selectedNetworkId}
name={n}
onPress={onPress}
/>
))}
</View>
)}
</>
);
};
6 changes: 3 additions & 3 deletions packages/components/user/AvatarWithName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const AvatarWithName: React.FC<
userId: string | undefined;
}
) & {
style: StyleProp<ViewStyle>;
style?: StyleProp<ViewStyle>;
onPress: (userId: string) => void;
}
> = (props) => {
Expand All @@ -31,7 +31,7 @@ export const AvatarWithName: React.FC<
export const AvatarWithNameFromName: React.FC<{
networkId: string | undefined;
name: string | undefined;
style: StyleProp<ViewStyle>;
style?: StyleProp<ViewStyle>;
onPress: (userId: string) => void;
}> = ({ networkId, name, style, onPress }) => {
const { nameOwner } = useNSNameOwner(networkId, name);
Expand All @@ -47,7 +47,7 @@ export const AvatarWithNameFromName: React.FC<{

export const AvatarWithNameFromUserId: React.FC<{
userId: string | undefined;
style: StyleProp<ViewStyle>;
style?: StyleProp<ViewStyle>;
onPress: (userId: string) => void;
}> = ({ userId, style, onPress }) => {
const { primaryAlias } = useNSPrimaryAlias(userId);
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/multisig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export * from "./useCreateMultisig";
export * from "./useApproveTransaction";
export * from "./useDeclineTransaction";
export * from "./useGetTransactionCount";
export * from "./useBrodcastTransaction";
export * from "./useBroadcastTransaction";
export * from "./useMultisigValidator";
export * from "./useCreateUserWallet";
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useMultisigContext } from "../../context/MultisigReducer";
import { completeTransaction } from "../../utils/faunaDB/multisig/multisigGraphql";
import { DbSignature } from "../../utils/faunaDB/multisig/types";

export const useBrodcastTransaction = () => {
export const useBroadcastTransaction = () => {
const { state } = useMultisigContext();
const { setToastError, setToastSuccess } = useFeedbacks();

Expand Down
52 changes: 30 additions & 22 deletions packages/screens/Multisig/MultisigCreateScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SVG } from "../../components/SVG";
import { ScreenContainer } from "../../components/ScreenContainer";
import { PrimaryButton } from "../../components/buttons/PrimaryButton";
import { SecondaryButton } from "../../components/buttons/SecondaryButton";
import { SearchNSInputContainer } from "../../components/inputs/SearchNSInputContainer";
import { TextInputCustom } from "../../components/inputs/TextInputCustom";
import { TextInputOutsideLabel } from "../../components/inputs/TextInputOutsideLabel";
import { SpacerColumn, SpacerRow } from "../../components/spacer";
Expand Down Expand Up @@ -44,7 +45,7 @@ import { layout } from "../../utils/style/layout";
const emptyPubKeyGroup = () => ({ address: "", compressedPubkey: "" });

export const MultisigCreateScreen = () => {
const { control, handleSubmit, watch } =
const { control, handleSubmit, watch, setValue } =
useForm<CreateMultisigWalletFormType>();
const [addressIndexes, setAddressIndexes] = useState([
emptyPubKeyGroup(),
Expand Down Expand Up @@ -155,28 +156,35 @@ export const MultisigCreateScreen = () => {
<SpacerColumn size={3} />
{addressIndexes.map((_, index) => (
<View style={styles.inputContainer} key={index.toString()}>
<TextInputCustom<CreateMultisigWalletFormType>
control={control}
name={`addresses.${index}.address`}
variant="labelOutside"
noBrokenCorners
label={"Address #" + (index + 1)}
rules={{
required: true,
validate: (value) => onAddressChange(index, value),
}}
placeHolder="Account address"
iconSVG={walletInputSVG}
<SearchNSInputContainer
searchText={watch(`addresses.${index}.address`)}
onPressName={(address) =>
setValue(`addresses.${index}.address`, address)
}
>
{addressIndexes.length > 2 && (
<Pressable
style={styles.trashContainer}
onPress={() => removeAddressField(index)}
>
<SVG source={trashSVG} width={12} height={12} />
</Pressable>
)}
</TextInputCustom>
<TextInputCustom<CreateMultisigWalletFormType>
control={control}
name={`addresses.${index}.address`}
variant="labelOutside"
noBrokenCorners
label={"Address #" + (index + 1)}
rules={{
required: true,
validate: (value) => onAddressChange(index, value),
}}
placeHolder="Account address"
iconSVG={walletInputSVG}
>
{addressIndexes.length > 2 && (
<Pressable
style={styles.trashContainer}
onPress={() => removeAddressField(index)}
>
<SVG source={trashSVG} width={12} height={12} />
</Pressable>
)}
</TextInputCustom>
</SearchNSInputContainer>
</View>
))}
<View style={styles.row}>
Expand Down
46 changes: 27 additions & 19 deletions packages/screens/Multisig/components/MultisigTransactionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { BrandText } from "../../../components/BrandText";
import { SVG } from "../../../components/SVG";
import { AnimationExpand } from "../../../components/animations";
import { PrimaryButton } from "../../../components/buttons/PrimaryButton";
import { SearchNSInputContainer } from "../../../components/inputs/SearchNSInputContainer";
import { GeneralSelect } from "../../../components/select/GeneralSelect";
import { SpacerColumn } from "../../../components/spacer";
import { useMultisigContext } from "../../../context/MultisigReducer";
Expand Down Expand Up @@ -48,7 +49,7 @@ export const MultisigTransactionForm: React.FC<
} = useRoute<AppRouteType<"MultisigTransfer" | "MultisigDelegate">>();
const selectedNetworkId = useSelectedNetworkId();
const { isLoading, data } = useGetMultisigAccount(address);
const { control, handleSubmit, setValue } =
const { control, handleSubmit, setValue, watch } =
useForm<MultisigTransactionDelegateFormType>();
const { coinSimplified, participantAddressesFromMultisig } =
useMultisigHelpers();
Expand Down Expand Up @@ -152,24 +153,31 @@ export const MultisigTransactionForm: React.FC<
{!isFetching && (
<>
{type === "transfer" ? (
<MultisigFormInput<MultisigTransactionDelegateFormType>
control={control}
label=""
hideLabel
name="recipientAddress"
isDisabled={!membersAddress?.length}
rules={{
required: true,
validate: (value) =>
validateMultisigAddress(
value,
type === "transfer"
? state.chain?.addressPrefix || ""
: state.chain?.validatorPrefix || ""
),
}}
placeHolder="E.g : torix23Jkj1ZSQJ128D928XJSkL2K30Dld1ksl"
/>
<SearchNSInputContainer
searchText={watch("recipientAddress")}
onPressName={(address) =>
setValue("recipientAddress", address)
}
>
<MultisigFormInput<MultisigTransactionDelegateFormType>
control={control}
label=""
hideLabel
name="recipientAddress"
isDisabled={!membersAddress?.length}
rules={{
required: true,
validate: (value) =>
validateMultisigAddress(
value,
type === "transfer"
? state.chain?.addressPrefix || ""
: state.chain?.validatorPrefix || ""
),
}}
placeHolder="E.g : torix23Jkj1ZSQJ128D928XJSkL2K30Dld1ksl"
/>
</SearchNSInputContainer>
) : (
<GeneralSelect
data={activeValidators.map((v) => v.moniker)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { MainConnectWalletButton } from "../../../components/connectWallet/MainC
import { SpacerRow } from "../../../components/spacer";
import {
useApproveTransaction,
useBrodcastTransaction,
useBroadcastTransaction,
useDeclineTransaction,
} from "../../../hooks/multisig";
import useSelectedWallet from "../../../hooks/useSelectedWallet";
Expand Down Expand Up @@ -66,7 +66,7 @@ export const TransactionItemButtons: React.FC<TransactionItemButtonsProps> = ({
mutate: broadcast,
isLoading: isBroacasting,
data: resTxHash,
} = useBrodcastTransaction();
} = useBroadcastTransaction();
const { copyToClipboard } = useCopyToClipboard();

const hasSigned = useMemo(
Expand Down Expand Up @@ -110,7 +110,7 @@ export const TransactionItemButtons: React.FC<TransactionItemButtonsProps> = ({
addDecliner,
});

const onBrodcast = () =>
const onBroadcast = () =>
broadcast({
tx: {
fee,
Expand Down Expand Up @@ -198,7 +198,7 @@ export const TransactionItemButtons: React.FC<TransactionItemButtonsProps> = ({
color={successColor}
borderColor={successColor}
isLoading={isBroacasting}
onPress={onBrodcast}
onPress={onBroadcast}
/>
</AnimationFadeIn>
);
Expand Down

0 comments on commit 187ad77

Please sign in to comment.