Skip to content

Commit

Permalink
fix(): throw error
Browse files Browse the repository at this point in the history
  • Loading branch information
santiago-ab committed Dec 11, 2024
1 parent 67062bf commit 36847ae
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 71 deletions.
52 changes: 28 additions & 24 deletions src/components/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,61 +17,61 @@ export const LoginForm = ({loginMethods, redirectUrl, customProps}: {loginMethod
const [showEmail, setShowEmail] = useState<boolean>(false);
const [isVisible, setIsVisible] = useState<boolean>(false);
const [email, setEmail] = useState<string>("");
const [errorText, setErrorText] = useState<string>("");

const makeLogin = async (provider: AuthProvider, redirectUrl: string, redirect: boolean, email?: string) => {
try {
const url = await login(provider, redirectUrl, email);
if (url) {
redirect ?

Check failure on line 26 in src/components/LoginForm.tsx

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Expected an assignment or function call and instead saw an expression
window.location.href = url
:
QRCodeModal.open(url, () => {});
}
} catch (error) {
setErrorText((error as Error).message);
}
}

const options: TLoginOptions = [
{
label: LoginMethods.Google,
icon: <GoogleLogo />,
disabled: false,
onClick: async () => {
const url = await login(AuthProvider.GOOGLE, redirectUrl);
if (url) {
window.location.href = url;
}
await makeLogin(AuthProvider.GOOGLE, redirectUrl, true);
},
},
{
label: LoginMethods.Discord,
icon: <TwitterLogo />,
disabled: false,
onClick: async () => {
const url = await login(AuthProvider.DISCORD, redirectUrl);
if (url) {
window.location.href = url;
}
await makeLogin(AuthProvider.DISCORD, redirectUrl, true);
},
},
{
label: LoginMethods.Twitter,
icon: <DiscordLogo />,
disabled: false,
onClick: async () => {
const url = await login(AuthProvider.TWITTER, redirectUrl);
if (url) {
window.location.href = url;
}
await makeLogin(AuthProvider.TWITTER, redirectUrl, true);
},
},
{
label: LoginMethods.Metamask,
icon: <MetamaskLogo />,
disabled: false,
onClick: async () => {
const url = await login(AuthProvider.METAMASK, redirectUrl);
if (url) {
window.location.href = url;
}
await makeLogin(AuthProvider.METAMASK, redirectUrl, true);
},
},
{
label: LoginMethods.WalletConnect,
icon: <WalletConnectLogo />,
disabled: false,
onClick: async () => {
const url = await login(AuthProvider.WALLET_CONNECT, redirectUrl);
if(!url) return;

QRCodeModal.open(url, () => {});
await makeLogin(AuthProvider.WALLET_CONNECT, redirectUrl, false);
},
},
{
Expand Down Expand Up @@ -136,10 +136,7 @@ export const LoginForm = ({loginMethods, redirectUrl, customProps}: {loginMethod
/>
<button
onClick={async () => {
const url = await login(AuthProvider.EMAIL, redirectUrl, email);
if (url) {
window.location.href = url;
}
await makeLogin(AuthProvider.EMAIL, redirectUrl, true, email);
}
}
style={{
Expand All @@ -165,6 +162,8 @@ export const LoginForm = ({loginMethods, redirectUrl, customProps}: {loginMethod
const buttonsContainerStyle = customProps?.buttonsContainerStyle ? customProps.buttonsContainerStyle : defaultStyles.buttonsContainer;
const buttonStyle = customProps?.buttonStyle ? customProps.buttonStyle : defaultStyles.button;
const buttonText = customProps?.buttonText ? customProps.buttonText : "Continue with";
const errorContainerStyle = customProps?.errorContainerStyle ? customProps.errorContainerStyle : defaultStyles.errorContainer;
const errorTextStyle = customProps?.errorTextStyle ? customProps.errorTextStyle : defaultStyles.errorStyle;

return (
<div style={containerStyle}>
Expand Down Expand Up @@ -192,6 +191,11 @@ export const LoginForm = ({loginMethods, redirectUrl, customProps}: {loginMethod
</button>
))}
</section>
<section style={errorContainerStyle}>
<span style={errorTextStyle}>
{errorText}
</span>
</section>
</div>
);
};
14 changes: 13 additions & 1 deletion src/components/LoginFormStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export type TCustomProps = {
tittleStyle?: React.CSSProperties;
tittleText?: string;
buttonText?: string;
errorContainerStyle?: React.CSSProperties;
errorTextStyle?: React.CSSProperties;
};

const container: React.CSSProperties = {
Expand Down Expand Up @@ -60,10 +62,20 @@ const tittle: React.CSSProperties = {
color: "#fff",
}

const errorContainer: React.CSSProperties = {
marginTop: "1rem",
}

const errorStyle: React.CSSProperties = {
color: "red",
}

export const defaultStyles = {
container,
buttonsContainer,
button,
buttonText,
tittle
tittle,
errorContainer,
errorStyle,
}
9 changes: 3 additions & 6 deletions src/hooks/useBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ export const useBalance = (address?: Address, chainId?: ChainId) => {
queryFn: async () => {
if (!chainId || !address) throw new Error("Missing chainId or address");
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}

const response = await sdk.Wallet.getPortfolio(address, chainId);
Expand All @@ -23,8 +22,7 @@ export const useBalance = (address?: Address, chainId?: ChainId) => {

const getBalances = async (address: Address, chainId: ChainId) => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
const response = await sdk.Wallet.getPortfolio(address, chainId);
return response?.portfolio || [];
Expand All @@ -35,8 +33,7 @@ export const useBalance = (address?: Address, chainId?: ChainId) => {
chainId: ChainId,
): Promise<IWalletPortfolio | undefined> => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return await sdk.Wallet.getPortfolio(address, chainId);
};
Expand Down
15 changes: 5 additions & 10 deletions src/hooks/useTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export const useTransaction = () => {
transaction: ITransactionSigned | ITransactionUnsigned,
): Promise<ITransaction | undefined> => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return await sdk.Transaction.createTransaction(transaction);
};
Expand All @@ -23,16 +22,14 @@ export const useTransaction = () => {
id: string,
): Promise<ITransaction | undefined> => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return await sdk.Transaction.getTransactionById(id);
};

const cancelTransaction = async (id: string): Promise<void | undefined> => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return await sdk.Transaction.cancelTransaction(id);
};
Expand All @@ -44,8 +41,7 @@ export const useTransaction = () => {
fromOrigin: string,
): Promise<ISignTransactionResponse | undefined> => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return await sdk.Transaction.approveSignTransaction(
id,
Expand All @@ -62,8 +58,7 @@ export const useTransaction = () => {
fromOrigin: string,
): Promise<ISignTransactionResponse | undefined> => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return await sdk.Transaction.rejectSignTransaction(
id,
Expand Down
6 changes: 2 additions & 4 deletions src/hooks/useUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export const useUser = () => {

const authenticateUser = (jwt: string) => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}

sdk.authenticateUser(jwt);
Expand All @@ -21,8 +20,7 @@ export const useUser = () => {
email?: string,
) => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}

let uri;
Expand Down
39 changes: 13 additions & 26 deletions src/hooks/useWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export const useWallet = () => {

const createWallet = async (data: IWallet): Promise<IWallet | undefined> => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return await sdk.Wallet.createWallet(data);
};
Expand All @@ -30,8 +29,7 @@ export const useWallet = () => {
queryKey: ["wallets"],
queryFn: async () => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return (await sdk.Wallet.getWallets()) as IWallet[];
},
Expand All @@ -43,8 +41,7 @@ export const useWallet = () => {
fromOrigin: string,
): Promise<IWalletSignTransactionResponse | undefined> => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return await sdk.Wallet.signTransaction(address, data, fromOrigin);
};
Expand All @@ -56,8 +53,7 @@ export const useWallet = () => {
fromOrigin: string,
): Promise<IWalletSignTransactionResponse | undefined> => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return await sdk.Wallet.approveTransaction(
address,
Expand All @@ -74,8 +70,7 @@ export const useWallet = () => {
fromOrigin: string,
): Promise<IWalletSignTransactionResponse | undefined> => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return await sdk.Wallet.rejectTransaction(
address,
Expand All @@ -94,8 +89,7 @@ export const useWallet = () => {
{ transactions: Partial<ITransaction>[]; currentPage: number } | undefined
> => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return await sdk.Wallet.getTransactionHistory(
address,
Expand All @@ -110,8 +104,7 @@ export const useWallet = () => {
chainId: ChainId,
): Promise<IWalletGasConfiguration | undefined> => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return await sdk.Wallet.getGasConfig(address, chainId);
};
Expand All @@ -122,8 +115,7 @@ export const useWallet = () => {
configuration: IWalletGasConfiguration,
): Promise<IWalletGasConfigurationAPI | undefined> => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return await sdk.Wallet.setGasConfig(address, chainId, configuration);
};
Expand All @@ -136,8 +128,7 @@ export const useWallet = () => {
data: string,
): Promise<IWalletGasEstimation | undefined> => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return await sdk.Wallet.getGasFees(chainId, from, to, value, data);
};
Expand All @@ -147,8 +138,7 @@ export const useWallet = () => {
chainId: ChainId,
): Promise<number | undefined> => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return await sdk.Wallet.getNonce(address, chainId);
};
Expand All @@ -157,8 +147,7 @@ export const useWallet = () => {
address: Address,
): Promise<IWalletRecovery | undefined> => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return await sdk.Wallet.initRecovery(address);
};
Expand All @@ -171,8 +160,7 @@ export const useWallet = () => {
fromOrigin: string,
): Promise<IExecRecovery | undefined> => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return await sdk.Wallet.execRecovery(
organizationId,
Expand All @@ -185,8 +173,7 @@ export const useWallet = () => {

const getNotifications = async (address: Address, chainId: ChainId) => {
if (!sdk) {
console.error("AppId is not loaded");
return;
throw new Error("AppId is not valid");
}
return (await sdk.Notifications.getNotifications(address, chainId)) as
| TNotifications
Expand Down

0 comments on commit 36847ae

Please sign in to comment.