Skip to content

Commit

Permalink
feat: tns update proposal preview (#1413)
Browse files Browse the repository at this point in the history
Signed-off-by: Norman Meier <[email protected]>
  • Loading branch information
n0izn0iz authored Nov 28, 2024
1 parent 9ad9c4f commit 70d7f4a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 10 deletions.
27 changes: 19 additions & 8 deletions packages/components/teritoriNameService/MediaPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as DocumentPicker from "expo-document-picker";
import { DocumentPickerResult } from "expo-document-picker";
import React, { Dispatch, SetStateAction, useState } from "react";
import { ActivityIndicator, View, ViewStyle } from "react-native";
import { ActivityIndicator, StyleProp, View, ViewStyle } from "react-native";
import { useSelector } from "react-redux";

import tnsProfileAvatar from "../../../assets/default-images/default-name-nft.png";
Expand All @@ -26,15 +26,17 @@ import { SVG } from "../SVG";
import { TextInputCustom } from "../inputs/TextInputCustom";

export const MediaPreview: React.FC<{
style: ViewStyle;
style?: StyleProp<ViewStyle>;
textInputsStyle?: StyleProp<ViewStyle>;
avatarImageUrl: string;
setAvatarImageUrl: Dispatch<SetStateAction<string>>;
setAvatarImageUrl?: Dispatch<SetStateAction<string>>;
bannerImageUrl: string;
setBannerImageUrl: Dispatch<SetStateAction<string>>;
setBannerImageUrl?: Dispatch<SetStateAction<string>>;
variant?: "regular" | "labelOutside" | "noStyle";
hasPadding?: boolean;
}> = ({
style,
textInputsStyle,
avatarImageUrl,
setAvatarImageUrl,
bannerImageUrl,
Expand Down Expand Up @@ -77,6 +79,9 @@ export const MediaPreview: React.FC<{
};

const onPressUploadAvatar = async () => {
if (!setAvatarImageUrl) {
return;
}
const documentPickerResult = await DocumentPicker.getDocumentAsync({
multiple: false,
});
Expand All @@ -86,6 +91,9 @@ export const MediaPreview: React.FC<{
};

const onPressUploadBanner = async () => {
if (!setBannerImageUrl) {
return;
}
const documentPickerResult = await DocumentPicker.getDocumentAsync({
multiple: false,
});
Expand All @@ -104,16 +112,18 @@ export const MediaPreview: React.FC<{
marginBottom: layout.spacing_x1,
padding: layout.spacing_x1_5,
},
style,
]}
>
<TextInputCustom<Metadata>
name="image"
style={style}
style={textInputsStyle}
label="Avatar URL"
noBrokenCorners
variant={variant}
placeHolder="https://website.com/avatar.jpg"
onPressChildren={onPressUploadAvatar}
disabled={!onPressUploadAvatar}
value={avatarImageUrl}
onChangeText={setAvatarImageUrl}
squaresBackgroundColor={neutral17}
Expand All @@ -127,10 +137,11 @@ export const MediaPreview: React.FC<{

<TextInputCustom<Metadata>
name="public_profile_header"
style={style}
style={textInputsStyle}
label="Cover Image URL"
noBrokenCorners
onPressChildren={onPressUploadBanner}
disabled={!onPressUploadBanner}
variant={variant}
placeHolder="https://website.com/coverimage.jpg"
value={bannerImageUrl}
Expand All @@ -152,8 +163,8 @@ export const MediaPreview: React.FC<{
>
<OptimizedImage
sourceURI={bannerImageUrl || tnsProfileCover}
width={410}
height={120}
width={820}
height={240}
style={{
width: "100%",
height: 120,
Expand Down
2 changes: 1 addition & 1 deletion packages/components/teritoriNameService/NameDataForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const NameDataForm: React.FC<{
squaresBackgroundColor={neutral17}
/>
<MediaPreview
style={inputStyle}
textInputsStyle={inputStyle}
avatarImageUrl={avatarImageUrl}
bannerImageUrl={bannerImageUrl}
setAvatarImageUrl={setAvatarImageUrl}
Expand Down
40 changes: 40 additions & 0 deletions packages/components/tx/getTxInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { tinyAddress } from "../../utils/text";
import { BrandText } from "../BrandText";
import { SocialMessageContent } from "../socialFeed/SocialCard/SocialMessageContent";
import { SpacerColumn } from "../spacer";
import { MediaPreview } from "../teritoriNameService/MediaPreview";
import { Username } from "../user/Username";

import { cosmosTypesRegistry } from "@/networks/cosmos-types";
Expand Down Expand Up @@ -396,6 +397,45 @@ export const getTxInfo = (
</View>
);
};
} else if (
network?.kind === NetworkKind.Cosmos &&
contractAddress === network.nameServiceContractAddress &&
method === "update_metadata"
) {
icon = feedWhiteSVG;
name = "Update profile";
preview = () => {
return (
<View>
<BrandText>Update {execMsg[method].token_id}</BrandText>
<SpacerColumn size={2.5} />
<BrandText style={brandTextNormalStyle}>
Display name:{" "}
<Text style={{ color: "white" }}>
{execMsg[method].metadata.public_name}
</Text>
</BrandText>
<SpacerColumn size={1} />
<BrandText style={brandTextNormalStyle}>
Bio:{" "}
<Text style={{ color: "white" }}>
{execMsg[method].metadata.public_bio}
</Text>
</BrandText>
<SpacerColumn size={1} />
<MediaPreview
hasPadding={false}
textInputsStyle={{ marginBottom: 12 }}
style={{ width: 410, backgroundColor: "black" }}
variant="regular"
avatarImageUrl={execMsg[method].metadata.image}
bannerImageUrl={
execMsg[method].metadata.public_profile_header
}
/>
</View>
);
};
}
if (!preview) {
preview = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/user/forms/EditProfileForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export const EditProfileForm: React.FC<{
render={({ field: { onChange } }) => (
<MediaPreview
hasPadding={false}
style={{ marginBottom: 12, width: "100%" }}
textInputsStyle={{ marginBottom: 12, width: "100%" }}
variant="regular"
avatarImageUrl={getValues("avatarURL") || ""}
bannerImageUrl={getValues("bannerURL") || ""}
Expand Down

0 comments on commit 70d7f4a

Please sign in to comment.