Skip to content
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

Fix error handling on sign message flow #1127

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- [Fix error handling on sign message flow](https://github.com/multiversx/mx-sdk-dapp/pull/1127)

## [[v2.29.0-beta.28]](https://github.com/multiversx/mx-sdk-dapp/pull/1126)] - 2024-04-04
- [ExperimentalWebviewProvider: fix cancel action on sign transactions flow](https://github.com/multiversx/mx-sdk-dapp/pull/1125)
Expand Down
29 changes: 15 additions & 14 deletions src/hooks/signMessage/useSignMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,13 @@ export const useSignMessage = (options?: { hasConsentPopup?: boolean }) => {
return;
}

try {
const isProviderInitialized = await provider?.init?.();
const isProviderInitialized = await provider?.init?.();

if (!isProviderInitialized) {
return;
}
} catch (error) {
const errorMessage =
(error as Error)?.message ||
(error as string) ||
PROVIDER_NOT_INITIALIZED;

console.error(errorMessage);
if (!isProviderInitialized) {
return;
}

return isProviderInitialized;
};

const signMessageWithWallet = async ({
Expand Down Expand Up @@ -189,8 +182,15 @@ export const useSignMessage = (options?: { hasConsentPopup?: boolean }) => {
try {
await checkProviderIsInitialized();
} catch (error) {
const errorMessage =
(error as Error)?.message ||
(error as string) ||
PROVIDER_NOT_INITIALIZED;

console.error(errorMessage);

onCancel({
errorMessage: String(error),
errorMessage: PROVIDER_NOT_INITIALIZED,
callbackRoute
});

Expand Down Expand Up @@ -227,9 +227,10 @@ export const useSignMessage = (options?: { hasConsentPopup?: boolean }) => {
} catch (error) {
const errorMessage =
(error as Error)?.message || (error as string) || ERROR_SIGNING;
console.error(errorMessage);

onCancel({
errorMessage,
errorMessage: ERROR_SIGNING,
callbackRoute
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/transactions/useSignTransactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export const useSignTransactions = () => {
PROVIDER_NOT_INITIALIZED;
console.error(errorMessage);

onCancel(errorMessage);
onCancel(PROVIDER_NOT_INITIALIZED, sessionId);
return;
}

Expand Down
5 changes: 3 additions & 2 deletions src/hooks/transactions/useSignTransactionsCommonData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export const useSignTransactionsCommonData = () => {
const isExtensionProvider = provider instanceof ExtensionProvider;
const isCrossWindowProvider = provider instanceof CrossWindowProvider;
const isMetamaskProvider = provider instanceof MetamaskProvider;
const isWebviewProvider = provider instanceof ExperimentalWebviewProvider;
const isExperimentalWebviewProvider =
provider instanceof ExperimentalWebviewProvider;

dispatch(clearAllTransactionsToSign());
dispatch(clearTransactionsInfoForSessionId(sessionId));
Expand All @@ -92,7 +93,7 @@ export const useSignTransactionsCommonData = () => {
CrossWindowProvider.getInstance()?.cancelAction?.();
}

if (isWebviewProvider) {
if (isExperimentalWebviewProvider) {
ExperimentalWebviewProvider.getInstance()?.cancelAction?.();
}
}
Expand Down