@daimo/pay 1.1.0 → 1.1.2

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/build/index.d.ts CHANGED
@@ -345,6 +345,9 @@ type ContextValue = {
345
345
  paymentState: PaymentState;
346
346
  /** TRPC API client. Internal use only. */
347
347
  trpc: any;
348
+ /** Custom message to display on confirmation page. */
349
+ confirmationMessage?: string;
350
+ setConfirmationMessage: React$1.Dispatch<React$1.SetStateAction<string | undefined>>;
348
351
  } & useConnectCallbackProps;
349
352
  /** Meant for internal use. This will be non-exported in a future SDK version. */
350
353
  declare const Context: React$1.Context<ContextValue | null>;
@@ -448,6 +451,10 @@ type PayButtonCommonProps = PayButtonPaymentProps & {
448
451
  onPaymentBounced?: (event: PaymentBouncedEvent) => void;
449
452
  /** Automatically close the modal after a successful payment. */
450
453
  closeOnSuccess?: boolean;
454
+ /** Open the modal by default. */
455
+ defaultOpen?: boolean;
456
+ /** Custom message to display on confirmation page. */
457
+ confirmationMessage?: string;
451
458
  };
452
459
  type DaimoPayButtonProps = PayButtonCommonProps & {
453
460
  /** Light mode, dark mode, or auto. */
@@ -1,5 +1,5 @@
1
1
  var name = "@daimo/pay";
2
- var version = "1.1.0";
2
+ var version = "1.1.2";
3
3
  var author = "Daimo";
4
4
  var homepage = "https://pay.daimo.com";
5
5
  var license = "BSD-2-Clause license";
@@ -38,8 +38,8 @@ var keywords = [
38
38
  "crypto"
39
39
  ];
40
40
  var dependencies = {
41
- "@daimo/common": "0.3.16",
42
- "@daimo/contract": "0.3.16",
41
+ "@daimo/common": "0.3.17",
42
+ "@daimo/contract": "0.3.17",
43
43
  "@solana/wallet-adapter-base": "^0.9.23",
44
44
  "@solana/wallet-adapter-react": "^0.15.35",
45
45
  "@solana/web3.js": "^1.95.4",
@@ -106,6 +106,7 @@ const DaimoPayProviderWithoutSolana = ({ children, theme = "auto", mode = "auto"
106
106
  const [solanaConnector, setSolanaConnector] = useState();
107
107
  const [route, setRoute] = useState(ROUTES.SELECT_METHOD);
108
108
  const [errorMessage, setErrorMessage] = useState("");
109
+ const [confirmationMessage, setConfirmationMessage] = useState(undefined);
109
110
  const [resize, onResize] = useState(0);
110
111
  // Include Google Font that is needed for a themes
111
112
  if (opts.embedGoogleFonts)
@@ -165,7 +166,10 @@ const DaimoPayProviderWithoutSolana = ({ children, theme = "auto", mode = "auto"
165
166
  paymentState.setModalOptions(modalOptions);
166
167
  if (daimoPayOrder &&
167
168
  daimoPayOrder.mode === DaimoPayOrderMode.HYDRATED &&
168
- (daimoPayOrder.destFastFinishTxHash || daimoPayOrder.destClaimTxHash)) {
169
+ (daimoPayOrder.sourceStatus !==
170
+ DaimoPayOrderStatusSource.WAITING_PAYMENT ||
171
+ daimoPayOrder.destFastFinishTxHash ||
172
+ daimoPayOrder.destClaimTxHash)) {
169
173
  setRoute(ROUTES.CONFIRMATION);
170
174
  }
171
175
  else {
@@ -194,6 +198,8 @@ const DaimoPayProviderWithoutSolana = ({ children, theme = "auto", mode = "auto"
194
198
  // Other configuration
195
199
  options: opts,
196
200
  errorMessage,
201
+ confirmationMessage,
202
+ setConfirmationMessage,
197
203
  debugMode,
198
204
  log,
199
205
  displayError: (message, code) => {
@@ -1 +1 @@
1
- {"version":3,"file":"DaimoPay.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"DaimoPay.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -47,11 +47,26 @@ function DaimoPayButtonCustom(props) {
47
47
  paymentState.setPayParams(payParams);
48
48
  }
49
49
  }, [payId, ...Object.values(payParams || {})]);
50
+ const { setConfirmationMessage } = context;
51
+ useEffect(() => {
52
+ if (props.confirmationMessage) {
53
+ setConfirmationMessage(props.confirmationMessage);
54
+ }
55
+ }, [props.confirmationMessage, setConfirmationMessage]);
50
56
  // Payment events: call these three event handlers.
51
57
  const { onPaymentStarted, onPaymentCompleted, onPaymentBounced } = props;
52
58
  const order = paymentState.daimoPayOrder;
53
59
  const hydOrder = order?.mode === DaimoPayOrderMode.HYDRATED ? order : null;
54
60
  const isStarted = hydOrder?.sourceStatus !== DaimoPayOrderStatusSource.WAITING_PAYMENT;
61
+ // Functions to show and hide the modal
62
+ const { children, closeOnSuccess } = props;
63
+ const modalOptions = { closeOnSuccess };
64
+ const show = () => {
65
+ if (paymentState.daimoPayOrder == null)
66
+ return;
67
+ context.showPayment(modalOptions);
68
+ };
69
+ const hide = () => context.setOpen(false);
55
70
  useEffect(() => {
56
71
  if (hydOrder == null || !isStarted)
57
72
  return;
@@ -79,14 +94,15 @@ function DaimoPayButtonCustom(props) {
79
94
  onPaymentBounced?.({ type: "payment_bounced", ...commonFields });
80
95
  }
81
96
  }, [hydOrder?.intentStatus]);
97
+ useEffect(() => {
98
+ if (props.defaultOpen) {
99
+ show();
100
+ }
101
+ }, [order != null]);
82
102
  // Validation
83
103
  if ((payId == null) == (payParams == null)) {
84
104
  throw new Error("Must specify either payId or appId, not both");
85
105
  }
86
- const { children, closeOnSuccess } = props;
87
- const modalOptions = { closeOnSuccess };
88
- const show = () => context.showPayment(modalOptions);
89
- const hide = () => context.setOpen(false);
90
106
  return children({ show, hide });
91
107
  }
92
108
  DaimoPayButtonCustom.displayName = "DaimoPayButton.Custom";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,6 +1,6 @@
1
- import { jsx, jsxs } from 'react/jsx-runtime';
1
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import { usePayContext } from '../../DaimoPay.js';
3
- import { PageContent, ModalContent, ModalH1 } from '../../Common/Modal/styles.js';
3
+ import { PageContent, ModalContent, ModalH1, ModalBody } from '../../Common/Modal/styles.js';
4
4
  import { DaimoPayOrderMode, DaimoPayOrderStatusDest, assert } from '@daimo/common';
5
5
  import { getChainExplorerTxUrl } from '@daimo/contract';
6
6
  import { motion } from 'framer-motion';
@@ -9,7 +9,7 @@ import styled from '../../../styles/styled/index.js';
9
9
  import PoweredByFooter from '../../Common/PoweredByFooter/index.js';
10
10
 
11
11
  const Confirmation = () => {
12
- const { paymentState } = usePayContext();
12
+ const { paymentState, confirmationMessage } = usePayContext();
13
13
  const { daimoPayOrder } = paymentState;
14
14
  const { done, txURL } = (() => {
15
15
  if (daimoPayOrder && daimoPayOrder.mode === DaimoPayOrderMode.HYDRATED) {
@@ -43,7 +43,7 @@ const Confirmation = () => {
43
43
  justifyContent: "center",
44
44
  alignItems: "center",
45
45
  paddingBottom: 0,
46
- }, children: [jsx(AnimationContainer, { children: jsxs(InsetContainer, { children: [jsx(Spinner, { "$status": done }), jsx(SuccessIcon, { "$status": done })] }) }), !done ? (jsx(ModalH1, { children: "Confirming..." })) : (jsx(ModalH1, { children: jsx(Link, { href: txURL, target: "_blank", rel: "noopener noreferrer", children: "Payment completed" }) })), jsx(PoweredByFooter, {})] }) }));
46
+ }, children: [jsx(AnimationContainer, { children: jsxs(InsetContainer, { children: [jsx(Spinner, { "$status": done }), jsx(SuccessIcon, { "$status": done })] }) }), !done ? (jsx(ModalH1, { children: "Confirming..." })) : (jsxs(Fragment, { children: [jsx(ModalH1, { children: jsx(Link, { href: txURL, target: "_blank", rel: "noopener noreferrer", children: "Payment completed" }) }), confirmationMessage && (jsx(ModalBody, { children: confirmationMessage }))] })), jsx(PoweredByFooter, {})] }) }));
47
47
  };
48
48
  const AnimationContainer = styled(motion.div) `
49
49
  position: relative;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@daimo/pay",
3
3
  "private": false,
4
- "version": "1.1.0",
4
+ "version": "1.1.2",
5
5
  "author": "Daimo",
6
6
  "homepage": "https://pay.daimo.com",
7
7
  "license": "BSD-2-Clause license",
@@ -40,8 +40,8 @@
40
40
  "crypto"
41
41
  ],
42
42
  "dependencies": {
43
- "@daimo/common": "0.3.16",
44
- "@daimo/contract": "0.3.16",
43
+ "@daimo/common": "0.3.17",
44
+ "@daimo/contract": "0.3.17",
45
45
  "@solana/wallet-adapter-base": "^0.9.23",
46
46
  "@solana/wallet-adapter-react": "^0.15.35",
47
47
  "@solana/web3.js": "^1.95.4",