@privy-io/react-auth 1.2.2 → 1.2.3-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +53 -51
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -50,6 +50,10 @@ var ErrorCodes = {
|
|
|
50
50
|
message: "Signature rejected",
|
|
51
51
|
detail: "Please try connecting again."
|
|
52
52
|
},
|
|
53
|
+
ERROR_TIMED_OUT: {
|
|
54
|
+
message: "Could not log in with wallet",
|
|
55
|
+
detail: "Please try connecting again."
|
|
56
|
+
},
|
|
53
57
|
ERROR_WALLET_CONNECTION: {
|
|
54
58
|
message: "Could not log in with wallet",
|
|
55
59
|
detail: "Please try connecting again."
|
|
@@ -91,10 +95,17 @@ var PrivyConnectorError = class extends PrivyError {
|
|
|
91
95
|
this.type = "connector_error";
|
|
92
96
|
}
|
|
93
97
|
};
|
|
94
|
-
var
|
|
98
|
+
var WalletTimeoutError = class extends PrivyError {
|
|
95
99
|
constructor() {
|
|
96
|
-
super("
|
|
100
|
+
super("Wallet timeout");
|
|
101
|
+
this.type = "wallet_error";
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var SiweSignatureFailedError = class extends PrivyError {
|
|
105
|
+
constructor(reason) {
|
|
106
|
+
super(`Sign-in request ${reason || "timed out" /* TIMED_OUT */}.`);
|
|
97
107
|
this.type = "siwe_error";
|
|
108
|
+
this.reason = reason || "rejected" /* REJECTED */;
|
|
98
109
|
}
|
|
99
110
|
};
|
|
100
111
|
var wrapApiError = (error) => {
|
|
@@ -479,7 +490,7 @@ var SUPPORTED_WALLET_TYPES = ["metamask", "coinbase_wallet", "wallet_connect"];
|
|
|
479
490
|
// src/connector.ts
|
|
480
491
|
var WALLET_TYPE_STORAGE_KEY = "privy:wallet_type";
|
|
481
492
|
var DEFAULT_WALLET_TIMEOUT_MS = 1e4;
|
|
482
|
-
var walletTimeout = (error = new
|
|
493
|
+
var walletTimeout = (error = new WalletTimeoutError(), timeoutMs = DEFAULT_WALLET_TIMEOUT_MS) => new Promise(
|
|
483
494
|
(_, reject) => setTimeout(() => {
|
|
484
495
|
reject(error);
|
|
485
496
|
}, timeoutMs)
|
|
@@ -626,8 +637,9 @@ Resources:
|
|
|
626
637
|
new AsExternalProvider(this.getEthereumProvider())
|
|
627
638
|
);
|
|
628
639
|
const signer = ethersProvider.getSigner();
|
|
629
|
-
return Promise.race([signer.signMessage(message), walletTimeout()]).catch(() => {
|
|
630
|
-
|
|
640
|
+
return Promise.race([signer.signMessage(message), walletTimeout()]).catch((e) => {
|
|
641
|
+
const reason = e instanceof WalletTimeoutError ? "timed out" /* TIMED_OUT */ : "rejected" /* REJECTED */;
|
|
642
|
+
throw new SiweSignatureFailedError(reason);
|
|
631
643
|
});
|
|
632
644
|
}
|
|
633
645
|
prepareMessage(chainId, address, nonce) {
|
|
@@ -1058,10 +1070,12 @@ var ModalHeader = ({ backFn }) => {
|
|
|
1058
1070
|
]
|
|
1059
1071
|
});
|
|
1060
1072
|
};
|
|
1061
|
-
var MiniModalHeader = () => {
|
|
1073
|
+
var MiniModalHeader = ({ backFn }) => {
|
|
1062
1074
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(StyledHeader, {
|
|
1063
1075
|
children: [
|
|
1064
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1076
|
+
backFn ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(BackButton, {
|
|
1077
|
+
backFn
|
|
1078
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Placeholder, {}),
|
|
1065
1079
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Placeholder, {}),
|
|
1066
1080
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CancelButton, {})
|
|
1067
1081
|
]
|
|
@@ -5569,8 +5583,7 @@ var LaterButton2 = import_styled_components12.default.button`
|
|
|
5569
5583
|
var import_react10 = require("react");
|
|
5570
5584
|
var import_styled_components13 = __toESM(require("styled-components"));
|
|
5571
5585
|
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
5572
|
-
var MAX_RETRIES =
|
|
5573
|
-
var GO_BACK_DELAY_MS = 2e3;
|
|
5586
|
+
var MAX_RETRIES = 2;
|
|
5574
5587
|
var WalletMapping = {
|
|
5575
5588
|
metamask: {
|
|
5576
5589
|
name: "MetaMask",
|
|
@@ -5589,7 +5602,7 @@ var ConnectionStatusScreen = () => {
|
|
|
5589
5602
|
var _a;
|
|
5590
5603
|
const [success, setSuccess] = (0, import_react10.useState)(false);
|
|
5591
5604
|
const [errorCode, setErrorCode] = (0, import_react10.useState)(void 0);
|
|
5592
|
-
const { navigate } = usePrivyModal();
|
|
5605
|
+
const { navigate, navigateBack } = usePrivyModal();
|
|
5593
5606
|
const { getAuthMeta, closePrivyModal, loginWithWallet } = usePrivyInternal();
|
|
5594
5607
|
const [numRetries, setNumRetries] = (0, import_react10.useState)(0);
|
|
5595
5608
|
const { user } = usePrivy();
|
|
@@ -5599,8 +5612,12 @@ var ConnectionStatusScreen = () => {
|
|
|
5599
5612
|
console.error(e);
|
|
5600
5613
|
if ((e == null ? void 0 : e.status) === 422) {
|
|
5601
5614
|
setErrorCode(ErrorCodes.ERROR_USER_EXISTS);
|
|
5602
|
-
} else if (e instanceof
|
|
5603
|
-
|
|
5615
|
+
} else if (e instanceof SiweSignatureFailedError) {
|
|
5616
|
+
if (e.reason === "timed out" /* TIMED_OUT */) {
|
|
5617
|
+
setErrorCode(ErrorCodes.ERROR_TIMED_OUT);
|
|
5618
|
+
} else {
|
|
5619
|
+
setErrorCode(ErrorCodes.ERROR_SIGNATURE_REJECTED);
|
|
5620
|
+
}
|
|
5604
5621
|
} else {
|
|
5605
5622
|
setErrorCode(ErrorCodes.ERROR_WALLET_CONNECTION);
|
|
5606
5623
|
}
|
|
@@ -5624,21 +5641,29 @@ var ConnectionStatusScreen = () => {
|
|
|
5624
5641
|
const walletType = ((_a = getAuthMeta()) == null ? void 0 : _a.wallet) || "metamask";
|
|
5625
5642
|
const walletName = WalletMapping[walletType].name;
|
|
5626
5643
|
const WalletLogo = WalletMapping[walletType].component;
|
|
5644
|
+
const isRetryableError = errorCode === ErrorCodes.ERROR_WALLET_CONNECTION || errorCode === ErrorCodes.ERROR_SIGNATURE_REJECTED || errorCode === ErrorCodes.ERROR_TIMED_OUT;
|
|
5627
5645
|
const title = success ? `Successfully connected with ${walletName}` : errorCode ? errorCode.message : `Waiting for ${walletName}`;
|
|
5628
|
-
|
|
5629
|
-
|
|
5646
|
+
let subtitle = "";
|
|
5647
|
+
if (success) {
|
|
5648
|
+
subtitle = "You\u2019re good to go!";
|
|
5649
|
+
} else if (numRetries >= MAX_RETRIES && errorCode) {
|
|
5650
|
+
subtitle = "Unable to connect wallet";
|
|
5651
|
+
} else if (errorCode) {
|
|
5652
|
+
subtitle = errorCode.detail;
|
|
5653
|
+
} else {
|
|
5654
|
+
switch (walletType) {
|
|
5630
5655
|
case "wallet_connect":
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
return `Don't see the signature request? Check your other browser windows.`;
|
|
5656
|
+
subtitle = "Open your mobile wallet app to continue";
|
|
5657
|
+
break;
|
|
5634
5658
|
default:
|
|
5635
|
-
|
|
5659
|
+
subtitle = `Don\u2019t see your wallet modal? Check your other browser windows.`;
|
|
5636
5660
|
}
|
|
5637
|
-
}
|
|
5638
|
-
const subtitle = success ? "You\u2019re good to go!" : errorCode ? errorCode.detail : walletInstructions(walletType);
|
|
5661
|
+
}
|
|
5639
5662
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, {
|
|
5640
5663
|
children: [
|
|
5641
|
-
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(MiniModalHeader, {
|
|
5664
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(MiniModalHeader, {
|
|
5665
|
+
backFn: navigateBack
|
|
5666
|
+
}),
|
|
5642
5667
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(ConnectContainer4, {
|
|
5643
5668
|
children: [
|
|
5644
5669
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(StackedContainer, {
|
|
@@ -5664,10 +5689,13 @@ var ConnectionStatusScreen = () => {
|
|
|
5664
5689
|
})
|
|
5665
5690
|
]
|
|
5666
5691
|
}),
|
|
5667
|
-
!success ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5692
|
+
!success ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(CallToActionButton, {
|
|
5693
|
+
onClick: () => {
|
|
5694
|
+
setNumRetries(numRetries + 1);
|
|
5695
|
+
setErrorCode(void 0);
|
|
5696
|
+
},
|
|
5697
|
+
visible: isRetryableError && numRetries < MAX_RETRIES,
|
|
5698
|
+
children: "Retry"
|
|
5671
5699
|
}) : null
|
|
5672
5700
|
]
|
|
5673
5701
|
}),
|
|
@@ -5675,32 +5703,6 @@ var ConnectionStatusScreen = () => {
|
|
|
5675
5703
|
]
|
|
5676
5704
|
});
|
|
5677
5705
|
};
|
|
5678
|
-
var RetryOrBackButton = ({
|
|
5679
|
-
errorCode,
|
|
5680
|
-
numRetries,
|
|
5681
|
-
setNumRetries
|
|
5682
|
-
}) => {
|
|
5683
|
-
const { navigateBack } = usePrivyModal();
|
|
5684
|
-
const [showCallToAction, setCallToAction] = (0, import_react10.useState)(false);
|
|
5685
|
-
(0, import_react10.useEffect)(() => {
|
|
5686
|
-
const timer = setTimeout(() => {
|
|
5687
|
-
setCallToAction(true);
|
|
5688
|
-
}, GO_BACK_DELAY_MS);
|
|
5689
|
-
return () => clearTimeout(timer);
|
|
5690
|
-
}, []);
|
|
5691
|
-
const isRetryableError = errorCode === ErrorCodes.ERROR_WALLET_CONNECTION || errorCode === ErrorCodes.ERROR_SIGNATURE_REJECTED;
|
|
5692
|
-
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_jsx_runtime25.Fragment, {
|
|
5693
|
-
children: (!errorCode || isRetryableError) && numRetries < MAX_RETRIES ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(CallToActionButton, {
|
|
5694
|
-
onClick: () => setNumRetries(numRetries + 1),
|
|
5695
|
-
visible: showCallToAction,
|
|
5696
|
-
children: "Retry"
|
|
5697
|
-
}) : /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(CallToActionButton, {
|
|
5698
|
-
onClick: navigateBack,
|
|
5699
|
-
visible: showCallToAction,
|
|
5700
|
-
children: "Go back"
|
|
5701
|
-
})
|
|
5702
|
-
});
|
|
5703
|
-
};
|
|
5704
5706
|
var ConnectContainer4 = import_styled_components13.default.div`
|
|
5705
5707
|
display: flex;
|
|
5706
5708
|
flex-direction: column;
|