-
Notifications
You must be signed in to change notification settings - Fork 22
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: change input of name TNS register #978
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
070d48c
feat: change input of name TNS register
VishalRakholiya-iView eb611d3
feat: create common component for TNS and DAOSection
VishalRakholiya-iView f96d3a1
feat: common component for TNS and DAOSection
VishalRakholiya-iView 3038204
fix:remove comment
VishalRakholiya-iView 83b483c
fix: common component UI
VishalRakholiya-iView File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import React from "react"; | ||
import { Control, FieldValues, Path } from "react-hook-form"; | ||
import { TextInputProps, View, ViewStyle } from "react-native"; | ||
|
||
import { TextInputCustom } from "./TextInputCustom"; | ||
import { fontSemibold14 } from "../../utils/style/fonts"; | ||
import { BrandText } from "../BrandText"; | ||
|
||
import { useNSAvailability } from "@/hooks/useNSAvailability"; | ||
import { useSelectedNetworkInfo } from "@/hooks/useSelectedNetwork"; | ||
import { NetworkKind, getCosmosNetwork } from "@/networks"; | ||
import { | ||
neutral33, | ||
neutral77, | ||
primaryColor, | ||
redDefault, | ||
} from "@/utils/style/colors"; | ||
import { NameFinderFormType } from "@/utils/types/tns"; | ||
|
||
interface TextInputCustomProps<T extends FieldValues> | ||
extends Omit<TextInputProps, "accessibilityRole" | "defaultValue"> { | ||
name: Path<T>; | ||
nameValue: string; | ||
label: string; | ||
placeHolder: string; | ||
value?: string; | ||
onChangeText?: (value: string) => void; | ||
onPressEnter?: () => void; | ||
control?: Control<T>; | ||
style?: ViewStyle; | ||
} | ||
|
||
export const AvailableNamesInput = <T extends FieldValues>({ | ||
nameValue, | ||
label, | ||
name, | ||
placeHolder, | ||
value, | ||
onChangeText = () => {}, | ||
onPressEnter = () => {}, | ||
control, | ||
style, | ||
}: TextInputCustomProps<T>) => { | ||
const selectedNetwork = useSelectedNetworkInfo(); | ||
const cosmosNetwork = getCosmosNetwork(selectedNetwork?.id); | ||
const nameAvailability = useNSAvailability(selectedNetwork?.id, nameValue); | ||
const price = | ||
nameAvailability.availability === "mint" | ||
? nameAvailability.prettyPrice | ||
: ""; | ||
const usdPrice = | ||
nameAvailability.availability === "mint" ? nameAvailability?.usdPrice : 0; | ||
|
||
let availabilityInfo = <></>; | ||
if (nameValue && selectedNetwork?.kind === NetworkKind.Cosmos) { | ||
if (nameAvailability.availability === "invalid") { | ||
availabilityInfo = ( | ||
<BrandText style={{ color: redDefault, ...fontSemibold14 }}> | ||
Invalid | ||
</BrandText> | ||
); | ||
} else if (nameAvailability.availability === "mint") { | ||
availabilityInfo = ( | ||
<View style={{ flexDirection: "row" }}> | ||
{!!usdPrice && ( | ||
<> | ||
<BrandText style={{ color: neutral77, ...fontSemibold14 }}> | ||
${usdPrice?.toFixed(2)} | ||
</BrandText> | ||
<BrandText style={{ color: neutral33, ...fontSemibold14 }}> | ||
{" - "} | ||
</BrandText> | ||
</> | ||
)} | ||
<BrandText style={{ color: primaryColor, ...fontSemibold14 }}> | ||
{price} | ||
</BrandText> | ||
</View> | ||
); | ||
} else if ( | ||
nameAvailability.availability === "market" || | ||
nameAvailability.availability === "none" | ||
) { | ||
availabilityInfo = ( | ||
<BrandText style={{ color: redDefault, ...fontSemibold14 }}> | ||
Taken | ||
</BrandText> | ||
); | ||
} | ||
} | ||
|
||
return ( | ||
<TextInputCustom<NameFinderFormType> | ||
noBrokenCorners | ||
isLoading={nameAvailability.availability === "loading"} | ||
variant="labelOutside" | ||
label={`${label}${ | ||
nameValue | ||
? `: ${ | ||
selectedNetwork?.kind === NetworkKind.Gno | ||
? "gno.land/r/demo/" + name | ||
: nameValue + cosmosNetwork?.nameServiceTLD | ||
}` | ||
: "" | ||
}`} | ||
placeHolder={placeHolder} | ||
name={name as "name" | "associatedHandle"} | ||
onChangeText={(val: string) => onChangeText(val)} | ||
onPressEnter={onPressEnter} | ||
value={value} | ||
rules={{ required: true }} | ||
regexp={new RegExp(/^[a-zA-Z]+$/)} | ||
style={style} | ||
control={ | ||
control | ||
? (control as unknown as Control<NameFinderFormType>) | ||
: undefined | ||
} | ||
> | ||
{availabilityInfo} | ||
</TextInputCustom> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't create a specific component, you just copy what they done in
CreateDAOSection.tsx
but it's better to have an input component that check available names, that call theTextInputCustom
etc. and called this component inCreateDAOSection
andTNSNameFinderModal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean use
TextInputCustom
in both file (CreateDAOSection
andTNSNameFinderModal
)?and write logic in
TextInputCustom
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, create a specific input components in
packages/components/inputs
that calledTextInputCustom
and write logic in it. And after that call this specific component inCreateDAOSection
andTNSNameFinderModal