forked from family/connectkit
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,24 @@ | ||
import { | ||
DaimoPayIntentStatus, | ||
DaimoPayOrderMode, | ||
DaimoPayOrderStatusSource, | ||
writeDaimoPayOrderID, | ||
} from "@daimo/common"; | ||
import { DaimoPayIntentStatus, writeDaimoPayOrderID } from "@daimo/common"; | ||
import { usePayContext } from "../components/DaimoPay"; | ||
import { PaymentStatus } from "../types"; | ||
|
||
/** Returns the current payment, or undefined if there is none. | ||
* | ||
* Status values: | ||
* - `payment_pending` - the user has not paid yet | ||
* - `payment_unpaid` - the user has not paid yet | ||
* - `payment_started` - the user has paid & payment is in progress. This status | ||
* typically lasts a few seconds. | ||
* - `payment_completed` - the final call or transfer succeeded | ||
* - `payment_bounced` - the final call or transfer reverted. Funds were sent | ||
* to the payment's configured refund address on the destination chain. | ||
*/ | ||
export function useDaimoPayStatus(): | ||
| { paymentId: string; status: PaymentStatus } | ||
| { paymentId: string; status: DaimoPayIntentStatus } | ||
| undefined { | ||
const { paymentState } = usePayContext(); | ||
if (!paymentState || !paymentState.daimoPayOrder) return undefined; | ||
|
||
const order = paymentState.daimoPayOrder; | ||
const paymentId = writeDaimoPayOrderID(order.id); | ||
if (order.mode === DaimoPayOrderMode.HYDRATED) { | ||
if (order.intentStatus !== DaimoPayIntentStatus.PENDING) { | ||
if (order.intentStatus === DaimoPayIntentStatus.SUCCESSFUL) { | ||
return { paymentId, status: "payment_completed" }; | ||
} else { | ||
return { paymentId, status: "payment_bounced" }; | ||
} | ||
} else if ( | ||
order.sourceStatus !== DaimoPayOrderStatusSource.WAITING_PAYMENT | ||
) { | ||
return { paymentId, status: "payment_started" }; | ||
} | ||
} | ||
|
||
return { paymentId, status: "payment_pending" }; | ||
return { paymentId, status: order.intentStatus }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { | |
assertNotNull, | ||
DaimoPayOrder, | ||
DaimoPayTokenAmount, | ||
DaimoPayUserMetadata, | ||
DepositAddressPaymentOptionData, | ||
DepositAddressPaymentOptionMetadata, | ||
DepositAddressPaymentOptions, | ||
|
@@ -20,7 +21,6 @@ import { Address, formatUnits, Hex, parseUnits } from "viem"; | |
import { useAccount, useEnsName } from "wagmi"; | ||
|
||
import { DaimoPayModalOptions, PaymentOption } from "../types"; | ||
import { generatePayId } from "../utils/exports"; | ||
import { detectPlatform } from "../utils/platform"; | ||
import { TrpcClient } from "../utils/trpc"; | ||
import { useDepositAddressOptions } from "./useDepositAddressOptions"; | ||
|
@@ -61,6 +61,10 @@ export interface PayParams { | |
preferredChains?: number[]; | ||
/** Preferred tokens. These appear first in the token list. */ | ||
preferredTokens?: { chain: number; address: Address }[]; | ||
/** External ID. E.g. a correlation ID. */ | ||
externalId?: string; | ||
/** Developer metadata. E.g. correlation ID. */ | ||
metadata?: DaimoPayUserMetadata; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. confirming that we don't expose our previous |
||
} | ||
|
||
/** Creates (or loads) a payment and manages the corresponding modal. */ | ||
|
@@ -215,6 +219,7 @@ export function usePaymentState({ | |
id: order.id.toString(), | ||
toUnits, | ||
metadata: order.metadata, | ||
userMetadata: payParams.metadata, | ||
isAmountEditable: isDepositFlow, | ||
}, | ||
platform, | ||
|
@@ -376,14 +381,12 @@ export function usePaymentState({ | |
}; | ||
|
||
const generatePreviewOrder = async (payParams: PayParams) => { | ||
const newPayId = generatePayId(); | ||
const newId = readDaimoPayOrderID(newPayId).toString(); | ||
// toUnits is undefined if and only if we're in deposit flow. | ||
// Set dummy value for deposit flow, since user can edit the amount. | ||
const toUnits = payParams.toUnits == null ? "0" : payParams.toUnits; | ||
|
||
const orderPreview = await trpc.previewOrder.query({ | ||
id: newId, | ||
appId: payParams.appId, | ||
toChain: payParams.toChain, | ||
toToken: payParams.toToken, | ||
toUnits, | ||
|
@@ -399,6 +402,8 @@ export function usePaymentState({ | |
preferredTokens: payParams.preferredTokens, | ||
}, | ||
}, | ||
externalId: payParams.externalId, | ||
userMetadata: payParams.metadata, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
}); | ||
|
||
setDaimoPayOrder(orderPreview); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.