Skip to content

Commit

Permalink
fix(select-wallet): fix error message handling (#153)
Browse files Browse the repository at this point in the history
* fix(select-wallet): fix errors

* chore(deps): update ordit-sdk to 1.0.5
  • Loading branch information
Nanosync authored Nov 16, 2023
1 parent 73cfe31 commit a080564
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
4 changes: 2 additions & 2 deletions packages/ord-connect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"dependencies": {
"@headlessui/react": "^1.7.17",
"@ordzaar/ordit-sdk": "1.0.4",
"@ordzaar/ordit-sdk": "1.0.5",
"bitcoinjs-lib": "6.1.5",
"boring-avatars": "^1.10.1"
},
Expand All @@ -60,7 +60,7 @@
]
},
"peerDependencies": {
"@ordzaar/ordit-sdk": "1.0.4",
"@ordzaar/ordit-sdk": "1.0.5",
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
Expand Down
39 changes: 22 additions & 17 deletions packages/ord-connect/src/components/SelectWalletModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Dialog, Transition } from "@headlessui/react";
import {
AddressFormat,
BrowserWalletNotInstalledError,
BrowserWalletRequestCancelledByUserError,
} from "@ordzaar/ordit-sdk";
import { getAddresses as getUnisatAddresses } from "@ordzaar/ordit-sdk/unisat";
import { getAddresses as getXverseAddresses } from "@ordzaar/ordit-sdk/xverse";
Expand Down Expand Up @@ -45,22 +46,26 @@ export function SelectWalletModal({
const [errorMessage, setErrorMessage] = useState<string>("");
const isSupportedDevice = !disableMobile || !isMobileDevice();

const onError = useCallback((walletProvider: Wallet, err: unknown) => {
if (err instanceof BrowserWalletNotInstalledError) {
window.open(
WALLET_CHROME_EXTENSION_URL[walletProvider],
"_blank",
"noopener,noreferrer",
);
}
if (err instanceof Error) {
const onError = useCallback(
(
walletProvider: Wallet,
err:
| BrowserWalletNotInstalledError
| BrowserWalletRequestCancelledByUserError
| Error,
) => {
if (err instanceof BrowserWalletNotInstalledError) {
window.open(
WALLET_CHROME_EXTENSION_URL[walletProvider],
"_blank",
"noopener,noreferrer",
);
}
setErrorMessage(err.message ?? err.toString());
} else {
// safeguard as we don't throw string errors
setErrorMessage("Unknown error occurred.");
}
console.error(`Error while connecting to ${walletProvider} wallet`, err);
}, []);
console.error(`Error while connecting to ${walletProvider} wallet`, err);

Check warning on line 65 in packages/ord-connect/src/components/SelectWalletModal/index.tsx

View workflow job for this annotation

GitHub Actions / Build (Apps & Packages)

Unexpected console statement

Check warning on line 65 in packages/ord-connect/src/components/SelectWalletModal/index.tsx

View workflow job for this annotation

GitHub Actions / Lint - Typescript and ESLint

Unexpected console statement

Check warning on line 65 in packages/ord-connect/src/components/SelectWalletModal/index.tsx

View workflow job for this annotation

GitHub Actions / NPM

Unexpected console statement
},
[],
);

const onConnectUnisatWallet = async (readOnly?: boolean) => {
try {
Expand Down Expand Up @@ -100,7 +105,7 @@ export function SelectWalletModal({
);
closeModal();
return true;
} catch (err: unknown) {
} catch (err) {
onError(Wallet.UNISAT, err);
return false;
}
Expand Down Expand Up @@ -137,7 +142,7 @@ export function SelectWalletModal({
});
closeModal();
return true;
} catch (err: unknown) {
} catch (err) {
onError(Wallet.XVERSE, err);
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a080564

Please sign in to comment.