Skip to content

Commit

Permalink
[DEV-1736] Added wallet/account delete
Browse files Browse the repository at this point in the history
  • Loading branch information
davidleomay committed Sep 27, 2023
1 parent 69e4c73 commit f283622
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 39 deletions.
131 changes: 98 additions & 33 deletions app/components/edit/UserEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useForm, useWatch } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { SpacerV } from "../../elements/Spacers";
import { User, UserDetail } from "../../models/User";
import { putUser } from "../../services/ApiService";
import { deleteAccount, deleteWallet, putUser } from "../../services/ApiService";
import Form from "../form/Form";
import Input from "../form/Input";
import PhoneNumber from "../form/PhoneNumber";
Expand All @@ -15,7 +15,10 @@ import ButtonContainer from "../util/ButtonContainer";
import { createRules } from "../../utils/Utils";
import { ApiError } from "../../models/ApiDto";
import { KycData } from "../../models/KycData";
import { Paragraph } from "react-native-paper";
import { Divider, Paragraph } from "react-native-paper";
import Colors from "../../config/Colors";
import NotificationService from "../../services/NotificationService";
import SessionService from "../../services/SessionService";

interface Props {
user?: UserDetail;
Expand All @@ -35,6 +38,8 @@ const UserEdit = ({ user, onUserChanged, onClose }: Props) => {
const [isSaving, setIsSaving] = useState(false);
const [error, setError] = useState<string>();
const [showMergeHint, setShowMergeHint] = useState(false);
const [showDeleteWalletHint, setShowDeleteWalletHint] = useState(false);
const [showDeleteAccountHint, setShowDeleteAccountHint] = useState(false);

const onSubmit = (updatedUser: User & KycData) => {
setIsSaving(true);
Expand All @@ -49,46 +54,106 @@ const UserEdit = ({ user, onUserChanged, onClose }: Props) => {
.finally(() => setIsSaving(false));
};

const onWalletDelete = () => onDelete(deleteWallet);
const onAccountDelete = () => onDelete(deleteAccount);

const onDelete = (method: () => Promise<void>) => {
setIsSaving(true);
method()
.then(() => SessionService.logout())
.catch(() => NotificationService.error(t("feedback.delete_failed")))
.finally(() => setIsSaving(false));
};

const rules: any = createRules({
mail: [Validations.Mail],
});

return showMergeHint ? (
if (showMergeHint) {
return (
<>
<Paragraph>{t("model.user.merge")}</Paragraph>
<SpacerV />

<ButtonContainer>
<DeFiButton mode="contained" onPress={onClose}>
{t("action.ok")}
</DeFiButton>
</ButtonContainer>
</>
);
}

if (showDeleteWalletHint) {
return (
<>
<Paragraph>{t("model.user.delete_wallet_hint")}</Paragraph>
<SpacerV />

<ButtonContainer>
<DeFiButton mode="contained" color={Colors.Grey} onPress={() => setShowDeleteWalletHint(false)}>
{t("action.abort")}
</DeFiButton>
<DeFiButton mode="contained" loading={isSaving} onPress={onWalletDelete}>
{t("action.ok")}
</DeFiButton>
</ButtonContainer>
</>
);
}

if (showDeleteAccountHint) {
return (
<>
<Paragraph>{t("model.user.delete_account_hint")}</Paragraph>
<SpacerV />

<ButtonContainer>
<DeFiButton mode="contained" color={Colors.Grey} onPress={() => setShowDeleteAccountHint(false)}>
{t("action.abort")}
</DeFiButton>
<DeFiButton mode="contained" loading={isSaving} onPress={onAccountDelete}>
{t("action.ok")}
</DeFiButton>
</ButtonContainer>
</>
);
}

return (
<>
<Paragraph>{t("model.user.merge")}</Paragraph>
<SpacerV />
<Form control={control} rules={rules} errors={errors} disabled={isSaving} onSubmit={handleSubmit(onSubmit)}>
<Input name="mail" label={t("model.user.mail")} valueHook={(v: string) => v.trim()} />
<SpacerV />
<PhoneNumber
name="phone"
label={t("model.user.mobile_number")}
placeholder="1761212112"
wrap={!device.SM}
country={country?.symbol}
/>
{error != null && (
<>
<Alert label={`${t("feedback.save_failed")} ${error ? t(error) : ""}`} />
<SpacerV />
</>
)}
<ButtonContainer>
<DeFiButton mode="contained" loading={isSaving} onPress={handleSubmit(onSubmit)}>
{t("action.save")}
</DeFiButton>
</ButtonContainer>
</Form>

<ButtonContainer>
<DeFiButton mode="contained" onPress={onClose}>
{t("action.ok")}
</DeFiButton>
</ButtonContainer>
</>
) : (
<Form control={control} rules={rules} errors={errors} disabled={isSaving} onSubmit={handleSubmit(onSubmit)}>
<Input name="mail" label={t("model.user.mail")} valueHook={(v: string) => v.trim()} />
<SpacerV />
<PhoneNumber
name="phone"
label={t("model.user.mobile_number")}
placeholder="1761212112"
wrap={!device.SM}
country={country?.symbol}
/>

{error != null && (
<>
<Alert label={`${t("feedback.save_failed")} ${error ? t(error) : ""}`} />
<SpacerV />
</>
)}
<SpacerV height={20} />
<Divider style={{ backgroundColor: Colors.LightGrey }} />
<SpacerV height={20} />

<ButtonContainer>
<DeFiButton mode="contained" loading={isSaving} onPress={handleSubmit(onSubmit)}>
{t("action.save")}
</DeFiButton>
<DeFiButton onPress={() => setShowDeleteWalletHint(true)}>{t("model.user.delete_wallet")}</DeFiButton>
<DeFiButton onPress={() => setShowDeleteAccountHint(true)}>{t("model.user.delete_account")}</DeFiButton>
</ButtonContainer>
</Form>
</>
);
};

Expand Down
6 changes: 5 additions & 1 deletion app/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@
"vip_title": "Herzlich willkommen in der Black Squad",
"vip_description": "Die Black Squad ist eine elitäre Gruppe für Großinvestoren über DFX und ermöglicht dir einen direkten Sprachkanal zur Führungsebene von DFX.",
"vip_link": "Die Black Squad versammelt sich in einer Telegram-Gruppe - folge einfach dem Link:",
"merge": "Wie es aussieht, hast du bereits ein Konto bei DFX. Wir haben dir gerade eine E-Mail geschickt. Klicke auf den gesendeten Link, um diese Adresse zu deinem bestehenden Konto hinzuzufügen. Auf diese Weise musst du KYC nicht erneut durchlaufen.\n\nWenn du diese Adresse nicht mit deinem Konto verknüpfen möchtest, ignoriere die E-Mail einfach."
"merge": "Wie es aussieht, hast du bereits ein Konto bei DFX. Wir haben dir gerade eine E-Mail geschickt. Klicke auf den gesendeten Link, um diese Adresse zu deinem bestehenden Konto hinzuzufügen. Auf diese Weise musst du KYC nicht erneut durchlaufen.\n\nWenn du diese Adresse nicht mit deinem Konto verknüpfen möchtest, ignoriere die E-Mail einfach.",
"delete_wallet": "Wallet deaktivieren",
"delete_wallet_hint": "Bist du sicher, dass du diese Wallet für die Verwendung bei DFX deaktivieren willst? Du kannst sie danach bei DFX nicht mehr benutzen.",
"delete_account": "Account löschen",
"delete_account_hint": "Bist du sicher, dass du deinen kompletten DFX Account löschen willst? Sämtliche Wallets welche mit diesem Account verknüpft sind werden dadurch für die Verwendung bei DFX deaktiviert."
},
"kyc": {
"title": "DFX KYC",
Expand Down
6 changes: 5 additions & 1 deletion app/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@
"vip_title": "Welcome to the Black Squad",
"vip_description": "The Black Squad is an elite group for major investors on DFX and gives you a direct voice channel to DFX leadership.",
"vip_link": "The Black Squad gathers in a Telegram group - just follow the link:",
"merge": "It looks like you already have an account with DFX. We have just sent you an E-Mail. Click on the sent link to add this address to your existing account. This way you don't need to go through KYC again.\n\nIf you don't want to link this address to your account, simply ignore the E-Mail."
"merge": "It looks like you already have an account with DFX. We have just sent you an E-Mail. Click on the sent link to add this address to your existing account. This way you don't need to go through KYC again.\n\nIf you don't want to link this address to your account, simply ignore the E-Mail.",
"delete_wallet": "Deactivate wallet",
"delete_wallet_hint": "Are you sure you want to deactivate this wallet for use at DFX? You will not be able to use it on DFX after that.",
"delete_account": "Delete account",
"delete_account_hint": "Are you sure you want to delete your entire DFX account? All wallets associated with this account will be deactivated for use with DFX."
},
"kyc": {
"title": "DFX KYC",
Expand Down
6 changes: 5 additions & 1 deletion app/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@
"vip_title": "Welcome to the Black Squad",
"vip_description": "The Black Squad is an elite group for major investors on DFX and gives you a direct voice channel to DFX leadership.",
"vip_link": "The Black Squad gathers in a Telegram group - just follow the link:",
"merge": "Parece que ya tiene una cuenta en DFX. Acabamos de enviarle un correo electrónico. Haga clic en el enlace enviado para añadir esta dirección a su cuenta existente. De esta manera usted no necesita ir a través de KYC de nuevo.\n\nSi no desea vincular esta dirección a su cuenta, simplemente ignore el correo electrónico."
"merge": "Parece que ya tiene una cuenta en DFX. Acabamos de enviarle un correo electrónico. Haga clic en el enlace enviado para añadir esta dirección a su cuenta existente. De esta manera usted no necesita ir a través de KYC de nuevo.\n\nSi no desea vincular esta dirección a su cuenta, simplemente ignore el correo electrónico.",
"delete_wallet": "Desactivar billetera",
"delete_wallet_hint": "¿Está seguro de que desea desactivar esta billetera para su uso en DFX? Ya no podrá utilizarlo con DFX.",
"delete_account": "Borrar cuenta",
"delete_account_hint": "¿Está seguro de que desea eliminar toda su cuenta DFX? Todos las billeteras vinculadas a esta cuenta serán desactivadas para su uso con DFX."
},
"kyc": {
"title": "DFX KYC",
Expand Down
6 changes: 5 additions & 1 deletion app/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@
"vip_title": "Welcome to the Black Squad",
"vip_description": "The Black Squad is an elite group for major investors on DFX and gives you a direct voice channel to DFX leadership.",
"vip_link": "The Black Squad gathers in a Telegram group - just follow the link:",
"merge": "Il semble que vous ayez déjà un compte chez DFX. Nous venons de vous envoyer un e-mail. Cliquez sur le lien envoyé pour ajouter cette adresse à votre compte existant. De cette façon, vous n'aurez pas besoin de refaire le KYC.\n\nSi vous ne souhaitez pas lier cette adresse à votre compte, ignorez simplement l'e-mail."
"merge": "Il semble que vous ayez déjà un compte chez DFX. Nous venons de vous envoyer un e-mail. Cliquez sur le lien envoyé pour ajouter cette adresse à votre compte existant. De cette façon, vous n'aurez pas besoin de refaire le KYC.\n\nSi vous ne souhaitez pas lier cette adresse à votre compte, ignorez simplement l'e-mail.",
"delete_wallet": "Désactiver le portefeuille",
"delete_wallet_hint": "Êtes-vous sûr de vouloir désactiver ce portefeuille pour l'utiliser avec DFX ? Vous ne pourrez plus l'utiliser avec DFX.",
"delete_account": "Supprimer le compte",
"delete_account_hint": "Êtes-vous sûr de vouloir supprimer l'ensemble de votre compte DFX ? Tous les portefeuilles liés à ce compte seront alors désactivés pour l'utilisation avec DFX."
},
"kyc": {
"title": "DFX KYC",
Expand Down
6 changes: 5 additions & 1 deletion app/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@
"vip_title": "Welcome to the Black Squad",
"vip_description": "The Black Squad is an elite group for major investors on DFX and gives you a direct voice channel to DFX leadership.",
"vip_link": "The Black Squad gathers in a Telegram group - just follow the link:",
"merge": "Sembra che tu abbia già un account con DFX. Le abbiamo appena inviato un'e-mail. Clicca sul link inviato per aggiungere questo indirizzo al tuo conto esistente. In questo modo non sarà necessario ripetere la procedura KYC.\n\nSe non volete collegare questo indirizzo al vostro conto, ignorate semplicemente l'e-mail."
"merge": "Sembra che tu abbia già un account con DFX. Le abbiamo appena inviato un'e-mail. Clicca sul link inviato per aggiungere questo indirizzo al tuo conto esistente. In questo modo non sarà necessario ripetere la procedura KYC.\n\nSe non volete collegare questo indirizzo al vostro conto, ignorate semplicemente l'e-mail.",
"delete_wallet": "Disattivare il portafoglio",
"delete_wallet_hint": "Sei sicuro di voler disattivare questo portafoglio per l'uso su DFX? Non sarà più possibile utilizzarlo con DFX.",
"delete_account": "Elimina conto",
"delete_account_hint": "Siete sicuri di voler cancellare il vostro intero account DFX? Tutti i portafogli collegati a questo account saranno disattivati per l'uso con DFX."
},
"kyc": {
"title": "DFX KYC",
Expand Down
6 changes: 5 additions & 1 deletion app/i18n/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@
"vip_title": "Welcome to the Black Squad",
"vip_description": "The Black Squad is an elite group for major investors on DFX and gives you a direct voice channel to DFX leadership.",
"vip_link": "The Black Squad gathers in a Telegram group - just follow the link:",
"merge": "Parece que já tem uma conta na DFX. Acabámos de lhe enviar um E-Mail. Clique no link enviado para adicionar este endereço à sua conta existente. Desta forma, não precisa de passar novamente pela KYC.\n\nSe não quiser ligar este endereço à sua conta, simplesmente ignore o E-Mail."
"merge": "Parece que já tem uma conta na DFX. Acabámos de lhe enviar um E-Mail. Clique no link enviado para adicionar este endereço à sua conta existente. Desta forma, não precisa de passar novamente pela KYC.\n\nSe não quiser ligar este endereço à sua conta, simplesmente ignore o E-Mail.",
"delete_wallet": "Desativar a carteira",
"delete_wallet_hint": "Tem certeza de que deseja desativar esta carteira para uso no DFX? Você não poderá mais usá-la no DFX.",
"delete_account": "Apagar conta",
"delete_account_hint": "Tem certeza de que deseja excluir toda a sua conta DFX? Todas as carteiras vinculadas a esta conta serão desativadas para uso no DFX."
},
"kyc": {
"title": "DFX KYC",
Expand Down
8 changes: 8 additions & 0 deletions app/services/ApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ export const changeUser = (info: LinkedAddress): Promise<string> => {
return fetchFrom<AuthResponse>(`${UserUrl}/change`, "POST", info).then((resp) => resp.accessToken);
};

export const deleteWallet = (): Promise<void> => {
return fetchFrom<void>(`${UserUrl}`, "DELETE");
};

export const deleteAccount = (): Promise<void> => {
return fetchFrom<void>(`${UserUrl}/account`, "DELETE");
};

// --- KYC --- //
export const putKycData = (data: KycData, code?: string): Promise<KycInfo> => {
return fetchFrom<KycInfo>(`${KycUrl}/${code}/data`, "PUT", toKycDataDto(data));
Expand Down

0 comments on commit f283622

Please sign in to comment.