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

create metadata field #33

Merged
merged 4 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions packages/connectkit/src/components/DaimoPayButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
DaimoPayIntentStatus,
DaimoPayOrderMode,
DaimoPayOrderStatusSource,
DaimoPayUserMetadata,
PaymentBouncedEvent,
PaymentCompletedEvent,
PaymentStartedEvent,
Expand Down Expand Up @@ -64,6 +65,10 @@ type PayButtonPaymentProps =
* Preferred tokens. These appear first in the token list.
*/
preferredTokens?: { chain: number; address: Address }[];
/**
* Developer metadata. E.g. correlation ID.
* */
metadata?: DaimoPayUserMetadata;
}
| {
/** The payment ID, generated via the Daimo Pay API. Replaces params above. */
Expand Down Expand Up @@ -154,6 +159,7 @@ function DaimoPayButtonCustom(props: DaimoPayButtonCustomProps) {
paymentOptions: props.paymentOptions,
preferredChains: props.preferredChains,
preferredTokens: props.preferredTokens,
metadata: props.metadata,
}
: null;
let payId = "payId" in props ? props.payId : null;
Expand Down Expand Up @@ -191,16 +197,19 @@ function DaimoPayButtonCustom(props: DaimoPayButtonCustomProps) {
};
const hide = () => context.setOpen(false);

// Emit onPaymentStarted event when payment is initiated
useEffect(() => {
if (hydOrder == null || !isStarted) return;
onPaymentStarted?.({
paymentId: writeDaimoPayOrderID(hydOrder.id),
type: "payment_started",
chainId: assertNotNull(hydOrder.sourceTokenAmount).token.chainId,
txHash: assertNotNull(hydOrder.sourceInitiateTxHash),
metadata: hydOrder.userMetadata,
});
}, [isStarted]);

// Emit onPaymentCompleted or onPaymentBounced event when payment is completed or bounced
useEffect(() => {
if (hydOrder == null) return;
if (hydOrder.intentStatus === DaimoPayIntentStatus.PENDING) return;
Expand All @@ -211,6 +220,7 @@ function DaimoPayButtonCustom(props: DaimoPayButtonCustomProps) {
txHash: assertNotNull(
hydOrder.destFastFinishTxHash ?? hydOrder.destClaimTxHash,
),
metadata: hydOrder.userMetadata,
};
if (hydOrder.intentStatus === DaimoPayIntentStatus.SUCCESSFUL) {
onPaymentCompleted?.({ type: "payment_completed", ...commonFields });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,34 +106,4 @@ const PayWithSolanaToken: React.FC = () => {
);
};

const LoadingContainer = styled(motion.div)`
display: flex;
align-items: center;
justify-content: center;
margin: 10px auto 16px;
height: 120px;
`;
const AnimationContainer = styled(motion.div)<{
$circle: boolean;
}>`
user-select: none;
position: relative;
--spinner-error-opacity: 0;
&:before {
content: "";
position: absolute;
inset: 1px;
opacity: 0;
background: var(--ck-body-color-danger);
${(props) =>
props.$circle &&
css`
inset: -5px;
border-radius: 50%;
background: none;
box-shadow: inset 0 0 0 3.5px var(--ck-body-color-danger);
`}
}
`;

export default PayWithSolanaToken;
5 changes: 5 additions & 0 deletions packages/connectkit/src/hooks/usePaymentState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
assertNotNull,
DaimoPayOrder,
DaimoPayTokenAmount,
DaimoPayUserMetadata,
DepositAddressPaymentOptionData,
DepositAddressPaymentOptionMetadata,
DepositAddressPaymentOptions,
Expand Down Expand Up @@ -61,6 +62,8 @@ export interface PayParams {
preferredChains?: number[];
/** Preferred tokens. These appear first in the token list. */
preferredTokens?: { chain: number; address: Address }[];
/** Developer metadata. E.g. correlation ID. */
Copy link
Member

@dcposch dcposch Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metadata associated with this payment. Use eg. to track correlated IDs.

metadata?: DaimoPayUserMetadata;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirming that we don't expose our previous metadata anywhere... fortunately, it looks like we don't

}

/** Creates (or loads) a payment and manages the corresponding modal. */
Expand Down Expand Up @@ -215,6 +218,7 @@ export function usePaymentState({
id: order.id.toString(),
toUnits,
metadata: order.metadata,
userMetadata: payParams.metadata,
isAmountEditable: isDepositFlow,
},
platform,
Expand Down Expand Up @@ -399,6 +403,7 @@ export function usePaymentState({
preferredTokens: payParams.preferredTokens,
},
},
userMetadata: payParams.metadata,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

});

setDaimoPayOrder(orderPreview);
Expand Down