forked from family/connectkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create metadata field * update DaimoPayIntentStatus values * create externalId field for unique order ids * better assert logging
- Loading branch information
1 parent
f0b7bb9
commit 6ca9f5a
Showing
11 changed files
with
122 additions
and
130 deletions.
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
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
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
Oops, something went wrong.