@depay/widgets 6.0.1 → 6.2.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/umd/index.js CHANGED
@@ -991,12 +991,25 @@
991
991
  });
992
992
 
993
993
  var ConnectingWalletDialog = (function (props) {
994
+ var _useState = React.useState(false),
995
+ _useState2 = _slicedToArray(_useState, 2),
996
+ showConnectButton = _useState2[0],
997
+ setShowConnectButton = _useState2[1];
998
+
994
999
  var _useContext = React.useContext(reactDialogStack.NavigateStackContext),
995
1000
  navigate = _useContext.navigate;
996
1001
 
997
1002
  var wallet = props.wallet;
998
1003
  wallet !== null && wallet !== void 0 && wallet.name ? wallet.name : 'wallet';
999
1004
  var walletLogo = wallet !== null && wallet !== void 0 && wallet.logo ? wallet.logo : undefined;
1005
+ React.useEffect(function () {
1006
+ var timeout = setTimeout(function () {
1007
+ return setShowConnectButton(true);
1008
+ }, 10000);
1009
+ return function () {
1010
+ return clearTimeout(timeout);
1011
+ };
1012
+ }, []);
1000
1013
 
1001
1014
  if (props.pending) {
1002
1015
  return /*#__PURE__*/React__default$1["default"].createElement(Dialog$1, {
@@ -1036,7 +1049,7 @@
1036
1049
  },
1037
1050
  className: "TextButton"
1038
1051
  }, "Connect with another wallet")))),
1039
- footer: /*#__PURE__*/React__default$1["default"].createElement("div", {
1052
+ footer: showConnectButton && /*#__PURE__*/React__default$1["default"].createElement("div", {
1040
1053
  className: "PaddingTopXS PaddingRightM PaddingLeftM PaddingBottomM"
1041
1054
  }, /*#__PURE__*/React__default$1["default"].createElement("button", {
1042
1055
  className: "ButtonPrimary",
@@ -1665,7 +1678,7 @@
1665
1678
  });
1666
1679
 
1667
1680
  var DialogStyle = (function (style) {
1668
- return "\n\n .ReactDialogBackground {\n backdrop-filter: blur(5px);\n background: rgba(0,0,0,0.7);\n }\n\n .Dialog {\n margin: 0 auto;\n position: relative;\n width: 420px;\n box-shadow: 0 0 20px rgba(0,0,0,0.1);\n border-radius: 0.8rem;\n }\n\n @media screen and (max-width: 450px) {\n \n .Dialog, .ReactDialogAnimation {\n width: 100%;\n }\n\n }\n\n @media (orientation: portrait) and (max-width: 900px) {\n\n .Dialog {\n align-content: stretch;\n display: flex;\n flex-direction: column;\n height: 100%;\n }\n\n .DialogBody {\n flex: 1;\n align-items: flex-end;\n max-height: 40vh !important;\n }\n\n .DialogFooter {\n padding-bottom: 50px;\n }\n\n .ReactDialogStackCell {\n vertical-align: bottom;\n }\n\n .ReactDialogAnimation {\n bottom: -100px !important;\n max-height: 66vh !important;\n top: inherit !important;\n transition: opacity 0.4s ease, bottom 0.4s ease;\n }\n\n .ReactDialog.ReactDialogOpen .ReactDialogAnimation {\n bottom: 0px !important;\n }\n\n .DialogFooter {\n border-bottom-left-radius: 0 !important;\n border-bottom-right-radius: 0 !important;\n }\n }\n\n .DialogBody {\n background: rgb(248,248,248);\n overflow-x: hidden;\n overflow-y: auto;\n }\n\n .DialogBody.HeightAuto {\n height: auto;\n }\n\n .DialogHeader {\n background: rgb(248,248,248);\n border-top-left-radius: 0.8rem;\n border-top-right-radius: 0.8rem;\n display: flex;\n flex-direction: row;\n position: relative;\n }\n\n .DialogHeaderTitle {\n flex-basis: auto;\n flex-grow: 1;\n }\n \n .DialogHeaderAction {\n height: 3rem;\n }\n\n .DialogFooter {\n background: rgb(248,248,248);\n border-bottom-left-radius: 0.8rem;\n border-bottom-right-radius: 0.8rem;\n line-height: 1.5rem;\n min-height: 2rem;\n position: relative;\n text-align: center;\n }\n\n .ReactShadowDOMInsideContainer > .ReactDialog {\n display: table;\n }\n\n ";
1681
+ return "\n\n .ReactDialogBackground {\n backdrop-filter: blur(5px);\n background: rgba(0,0,0,0.7);\n }\n\n .Dialog {\n margin: 0 auto;\n position: relative;\n width: 420px;\n box-shadow: 0 0 20px rgba(0,0,0,0.1);\n border-radius: 0.8rem;\n }\n\n @media screen and (max-width: 450px) {\n \n .Dialog, .ReactDialogAnimation {\n width: 100%;\n }\n\n }\n\n @media (orientation: portrait) and (max-width: 900px) {\n\n .Dialog {\n align-content: stretch;\n display: flex;\n flex-direction: column;\n height: 100%;\n }\n\n .DialogBody {\n flex: 1;\n align-items: flex-end;\n max-height: 60vh !important;\n }\n\n .DialogFooter {\n padding-bottom: 20px;\n }\n\n .ReactDialogStackCell {\n vertical-align: bottom;\n }\n\n .ReactDialogAnimation {\n bottom: -100px !important;\n max-height: 66vh !important;\n top: inherit !important;\n transition: opacity 0.4s ease, bottom 0.4s ease;\n }\n\n .ReactDialog.ReactDialogOpen .ReactDialogAnimation {\n bottom: 0px !important;\n }\n\n .DialogFooter {\n border-bottom-left-radius: 0 !important;\n border-bottom-right-radius: 0 !important;\n }\n }\n\n .DialogBody {\n background: rgb(248,248,248);\n overflow-x: hidden;\n overflow-y: auto;\n }\n\n .DialogBody.HeightAuto {\n height: auto;\n }\n\n .DialogHeader {\n background: rgb(248,248,248);\n border-top-left-radius: 0.8rem;\n border-top-right-radius: 0.8rem;\n display: flex;\n flex-direction: row;\n position: relative;\n }\n\n .DialogHeaderTitle {\n flex-basis: auto;\n flex-grow: 1;\n }\n \n .DialogHeaderAction {\n height: 3rem;\n }\n\n .DialogFooter {\n background: rgb(248,248,248);\n border-bottom-left-radius: 0.8rem;\n border-bottom-right-radius: 0.8rem;\n line-height: 1.5rem;\n min-height: 2rem;\n position: relative;\n text-align: center;\n }\n\n .ReactShadowDOMInsideContainer > .ReactDialog {\n display: table;\n }\n\n ";
1669
1682
  });
1670
1683
 
1671
1684
  var FontStyle = (function (style) {
@@ -1818,11 +1831,36 @@
1818
1831
 
1819
1832
  return new Promise( /*#__PURE__*/function () {
1820
1833
  var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(resolve, reject) {
1834
+ var wallet, accounts;
1821
1835
  return regenerator.wrap(function _callee$(_context) {
1822
1836
  while (1) {
1823
1837
  switch (_context.prev = _context.next) {
1824
1838
  case 0:
1825
- web3Wallets.getWallet();
1839
+ wallet = web3Wallets.getWallet();
1840
+
1841
+ if (!wallet) {
1842
+ _context.next = 7;
1843
+ break;
1844
+ }
1845
+
1846
+ _context.next = 4;
1847
+ return wallet.accounts();
1848
+
1849
+ case 4:
1850
+ accounts = _context.sent;
1851
+
1852
+ if (!(accounts instanceof Array && accounts.length > 0)) {
1853
+ _context.next = 7;
1854
+ break;
1855
+ }
1856
+
1857
+ return _context.abrupt("return", resolve({
1858
+ wallet: wallet,
1859
+ accounts: accounts,
1860
+ account: accounts[0]
1861
+ }));
1862
+
1863
+ case 7:
1826
1864
  mount({
1827
1865
  style: style,
1828
1866
  document: ensureDocument(document)
@@ -1849,7 +1887,7 @@
1849
1887
  };
1850
1888
  });
1851
1889
 
1852
- case 2:
1890
+ case 8:
1853
1891
  case "end":
1854
1892
  return _context.stop();
1855
1893
  }
@@ -3743,6 +3781,185 @@
3743
3781
  };
3744
3782
  }();
3745
3783
 
3784
+ var SignLoginDialog = (function (props) {
3785
+ var _useContext = React.useContext(ErrorContext),
3786
+ setError = _useContext.setError;
3787
+
3788
+ var _useState = React.useState(false),
3789
+ _useState2 = _slicedToArray(_useState, 2),
3790
+ showSignButton = _useState2[0],
3791
+ setShowSignButton = _useState2[1];
3792
+
3793
+ var _useContext2 = React.useContext(ConfigurationContext),
3794
+ message = _useContext2.message,
3795
+ endpoint = _useContext2.endpoint;
3796
+
3797
+ var _useContext3 = React.useContext(ConfigurationContext),
3798
+ recover = _useContext3.recover;
3799
+
3800
+ var wallet = web3Wallets.getWallet();
3801
+ wallet !== null && wallet !== void 0 && wallet.name ? wallet.name : 'wallet';
3802
+ var walletLogo = wallet !== null && wallet !== void 0 && wallet.logo ? wallet.logo : undefined;
3803
+
3804
+ if (typeof recover != 'function') {
3805
+ recover = function recover(_ref) {
3806
+ var message = _ref.message,
3807
+ signature = _ref.signature;
3808
+ return new Promise(function (resolve, reject) {
3809
+ fetch(endpoint, {
3810
+ method: 'POST',
3811
+ body: JSON.stringify({
3812
+ message: message,
3813
+ signature: signature
3814
+ })
3815
+ }).then(function (response) {
3816
+ if (response.status == 200) {
3817
+ response.text().then(function (account) {
3818
+ resolve(account);
3819
+ })["catch"](setError);
3820
+ } else {
3821
+ response.text().then(function (text) {
3822
+ setError(text || 'Recovering login signature failed!');
3823
+ });
3824
+ }
3825
+ });
3826
+ });
3827
+ };
3828
+ }
3829
+
3830
+ var login = function login() {
3831
+ wallet.sign(message).then(function (signature) {
3832
+ recover({
3833
+ message: message,
3834
+ signature: signature
3835
+ }).then(props.resolve)["catch"](setError);
3836
+ })["catch"](setError);
3837
+ };
3838
+
3839
+ React.useEffect(login, []);
3840
+ React.useEffect(function () {
3841
+ var timeout = setTimeout(function () {
3842
+ return setShowSignButton(true);
3843
+ }, 10000);
3844
+ return function () {
3845
+ return clearTimeout(timeout);
3846
+ };
3847
+ }, []);
3848
+ return /*#__PURE__*/React__default$1["default"].createElement(Dialog$1, {
3849
+ stacked: true,
3850
+ body: /*#__PURE__*/React__default$1["default"].createElement("div", null, walletLogo && /*#__PURE__*/React__default$1["default"].createElement("div", {
3851
+ className: "GraphicWrapper PaddingTopS PaddingBottomS"
3852
+ }, /*#__PURE__*/React__default$1["default"].createElement("img", {
3853
+ className: "Graphic",
3854
+ src: walletLogo
3855
+ })), /*#__PURE__*/React__default$1["default"].createElement("h1", {
3856
+ className: "LineHeightL Text FontSizeL FontWeightBold PaddingTopS"
3857
+ }, "Wallet Login"), /*#__PURE__*/React__default$1["default"].createElement("div", {
3858
+ className: "Text PaddingTopS PaddingBottomS PaddingLeftS PaddingRightS"
3859
+ }, /*#__PURE__*/React__default$1["default"].createElement("p", {
3860
+ className: "FontSizeM PaddingLeftM PaddingRightM"
3861
+ }, "Please sign the login message with your connected wallet."))),
3862
+ footer: showSignButton && /*#__PURE__*/React__default$1["default"].createElement("div", {
3863
+ className: "PaddingTopXS PaddingRightM PaddingLeftM PaddingBottomM"
3864
+ }, /*#__PURE__*/React__default$1["default"].createElement("button", {
3865
+ className: "ButtonPrimary",
3866
+ onClick: login
3867
+ }, "Log in"))
3868
+ });
3869
+ });
3870
+
3871
+ var LoginStack = (function (props) {
3872
+ var _useContext = React.useContext(ClosableContext),
3873
+ open = _useContext.open,
3874
+ close = _useContext.close;
3875
+
3876
+ var _useState = React.useState(true),
3877
+ _useState2 = _slicedToArray(_useState, 2);
3878
+ _useState2[0];
3879
+ _useState2[1];
3880
+
3881
+ return /*#__PURE__*/React__default$1["default"].createElement(reactDialogStack.ReactDialogStack, {
3882
+ open: open,
3883
+ close: close,
3884
+ start: "SignLogin",
3885
+ container: props.container,
3886
+ document: props.document,
3887
+ dialogs: {
3888
+ SignLogin: /*#__PURE__*/React__default$1["default"].createElement(SignLoginDialog, {
3889
+ resolve: props.resolve
3890
+ })
3891
+ }
3892
+ });
3893
+ });
3894
+
3895
+ var Login = function Login(options) {
3896
+ var style, error, document, message, endpoint, recover;
3897
+
3898
+ if (_typeof(options) == 'object') {
3899
+ style = options.style;
3900
+ error = options.error;
3901
+ document = options.document;
3902
+ message = options.message;
3903
+ endpoint = options.endpoint;
3904
+ recover = options.recover;
3905
+ }
3906
+
3907
+ return new Promise( /*#__PURE__*/function () {
3908
+ var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(_resolve, reject) {
3909
+ return regenerator.wrap(function _callee$(_context) {
3910
+ while (1) {
3911
+ switch (_context.prev = _context.next) {
3912
+ case 0:
3913
+ Connect().then(function () {
3914
+ mount({
3915
+ style: style,
3916
+ document: ensureDocument(document)
3917
+ }, function (unmount) {
3918
+ var rejectBeforeUnmount = function rejectBeforeUnmount() {
3919
+ reject('USER_CLOSED_DIALOG');
3920
+ unmount();
3921
+ };
3922
+
3923
+ return function (container) {
3924
+ return /*#__PURE__*/React__default$1["default"].createElement(ErrorProvider, {
3925
+ error: error,
3926
+ container: container,
3927
+ unmount: unmount
3928
+ }, /*#__PURE__*/React__default$1["default"].createElement(ConfigurationProvider, {
3929
+ configuration: {
3930
+ message: message,
3931
+ endpoint: endpoint || '/login',
3932
+ recover: recover
3933
+ }
3934
+ }, /*#__PURE__*/React__default$1["default"].createElement(UpdatableProvider, null, /*#__PURE__*/React__default$1["default"].createElement(ClosableProvider, {
3935
+ unmount: rejectBeforeUnmount
3936
+ }, /*#__PURE__*/React__default$1["default"].createElement(LoginStack, {
3937
+ document: document,
3938
+ container: container,
3939
+ resolve: function resolve(account) {
3940
+ unmount();
3941
+
3942
+ _resolve(account);
3943
+ }
3944
+ }), /*#__PURE__*/React__default$1["default"].createElement(PoweredBy, null)))));
3945
+ };
3946
+ });
3947
+ })["catch"](reject);
3948
+
3949
+ case 1:
3950
+ case "end":
3951
+ return _context.stop();
3952
+ }
3953
+ }
3954
+ }, _callee);
3955
+ }));
3956
+
3957
+ return function (_x, _x2) {
3958
+ return _ref.apply(this, arguments);
3959
+ };
3960
+ }());
3961
+ };
3962
+
3746
3963
  var PaymentAmountRoutingContext = /*#__PURE__*/React__default$1["default"].createContext();
3747
3964
 
3748
3965
  var PaymentAmountRoutingProvider = (function (props) {
@@ -4451,9 +4668,10 @@
4451
4668
 
4452
4669
  var DePayWidgets = {
4453
4670
  Connect: Connect,
4671
+ Donation: Donation,
4672
+ Login: Login,
4454
4673
  Payment: Payment,
4455
4674
  Sale: Sale,
4456
- Donation: Donation,
4457
4675
  provider: web3Client.provider
4458
4676
  };
4459
4677
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@depay/widgets",
3
3
  "moduleName": "DePayWidgets",
4
- "version": "6.0.1",
4
+ "version": "6.2.1",
5
5
  "description": "Web3 Payments with any token. DePay simplifies and improves Web3 Payments with the power of DeFi. Accept any token with on-the-fly conversion.",
6
6
  "main": "./dist/umd/index.js",
7
7
  "module": "./dist/esm/index.js",
@@ -45,7 +45,7 @@
45
45
  "@depay/web3-exchanges": "^8.0.0",
46
46
  "@depay/web3-payments": "^9.0.2",
47
47
  "@depay/web3-tokens": "^7.2.0",
48
- "@depay/web3-wallets": "^7.0.0",
48
+ "@depay/web3-wallets": "^7.2.1",
49
49
  "decimal.js": "^10.3.1",
50
50
  "react-rangeslider": "^2.2.0"
51
51
  },
@@ -60,7 +60,7 @@
60
60
  "@babel/preset-env": "^7.12.7",
61
61
  "@babel/preset-react": "^7.12.7",
62
62
  "@cypress/react": "^5.9.1",
63
- "@depay/web3-mock": "^9.2.0",
63
+ "@depay/web3-mock": "^9.6.0",
64
64
  "@rollup/plugin-babel": "^5.3.0",
65
65
  "@rollup/plugin-commonjs": "^17.1.0",
66
66
  "@rollup/plugin-node-resolve": "^11.1.1",