Skip to content

[RN] Adds ability to delete the ews active account #2199

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

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dirty-camels-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/react-native": patch
---

Adds ability to delete the active ews account
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { utils } from "ethers";
import {
authEndpoint,
customJwt,
deleteActiveAccount,
sendVerificationEmail,
socialLogin,
validateEmailOTP,
Expand Down Expand Up @@ -178,6 +179,10 @@ export class EmbeddedWalletConnector extends Connector<EmbeddedWalletConnectionA
});
}

async deleteActiveAccount() {
return deleteActiveAccount({ clientId: this.options.clientId });
}

private async socialLogin(oauthOption: OauthOption): Promise<AuthResult> {
try {
const { storedToken, email } = await socialLogin(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
SendEmailOtpReturnType,
} from "@thirdweb-dev/wallets";
import {
deleteAccount,
generateAuthTokenFromCognitoEmailOtp,
getEmbeddedWalletUserDetail,
sendUserManagedEmailOtp,
Expand Down Expand Up @@ -372,3 +373,20 @@ export async function authEndpoint(
);
}
}

export async function deleteActiveAccount(options: {
clientId: string;
}): Promise<boolean> {
await verifyClientId(options.clientId);

let result;
try {
result = await deleteAccount({
clientId: options.clientId,
});
} catch (e) {
throw new Error(createErrorMessage("Error deleting the active account", e));
}

return result;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CognitoUserSession } from "amazon-cognito-identity-js";
import {
ROUTE_GET_EMBEDDED_WALLET_DETAILS,
ROUTE_EMBEDDED_WALLET_DETAILS,
ROUTE_STORE_USER_SHARES,
ROUTE_VERIFY_THIRDWEB_CLIENT_ID,
ROUTE_VERIFY_COGNITO_OTP,
Expand Down Expand Up @@ -89,7 +89,7 @@ export async function getEmbeddedWalletUserDetail(args: {
email?: string;
clientId: string;
}) {
const url = new URL(ROUTE_GET_EMBEDDED_WALLET_DETAILS);
const url = new URL(ROUTE_EMBEDDED_WALLET_DETAILS);
if (args) {
if (args.email) {
url.searchParams.append("email", args.email);
Expand Down Expand Up @@ -296,3 +296,22 @@ export async function getUserShares(clientId: string, getShareUrl: URL) {
);
}
}

export async function deleteAccount(args: { clientId: string }) {
const url = new URL(ROUTE_EMBEDDED_WALLET_DETAILS);
const resp = await authFetchEmbeddedWalletUser(
{ clientId: args.clientId },
url.href,
{
method: "DELETE",
},
);
if (!resp.ok) {
const error = await resp.json();
throw new Error(
`Something went wrong deleting the active account: ${error.message}`,
);
}

return await resp.json();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const DOMAIN_URL_2023 = "https://embedded-wallet.thirdweb.com";
const BASE_URL_2023 = `${DOMAIN_URL_2023}/`;
const ROUTE_2023_10_20_API_BASE_PATH = `${BASE_URL_2023}api/2023-10-20`;

export const ROUTE_GET_EMBEDDED_WALLET_DETAILS = `${ROUTE_2023_10_20_API_BASE_PATH}/embedded-wallet/embedded-wallet-user-details`;
export const ROUTE_EMBEDDED_WALLET_DETAILS = `${ROUTE_2023_10_20_API_BASE_PATH}/embedded-wallet/embedded-wallet-user-details`;
export const ROUTE_VERIFY_COGNITO_OTP = `${ROUTE_2023_10_20_API_BASE_PATH}/embedded-wallet/validate-cognito-email-otp`;
export const ROUTE_COGNITO_IDENTITY_POOL_URL = `cognito-idp.${AWS_REGION}.amazonaws.com/${COGNITO_USER_POOL_ID}`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export class EmbeddedWallet extends AbstractClientWallet<
return connector.authenticate(params);
}

async deleteActiveAccount() {
return this.connector?.deleteActiveAccount();
}

getMeta(): WalletMeta {
const strategy = this.connector?.getConnectedAuthStrategy();
const meta = (this.constructor as typeof AbstractClientWallet).meta;
Expand Down