-
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.
- Loading branch information
Showing
7 changed files
with
107 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ name: Deploy to GitHub Pages | |
on: | ||
push: | ||
branches: | ||
- PE-5161_gift_app_init | ||
- prod | ||
|
||
jobs: | ||
deploy: | ||
|
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { TurboFactory, USD } from "@ardrive/turbo-sdk"; | ||
import { useState, useRef, useEffect } from "react"; | ||
import { turboConfig, wincPerCredit } from "../constants"; | ||
|
||
export function useCreditsForFiat( | ||
debouncedUsdAmount: number, | ||
errorCallback: (message: string) => void, | ||
): [number | undefined, number | undefined] { | ||
const [winc, setWinc] = useState<string | undefined>(undefined); | ||
const usdWhenCreditsWereLastUpdatedRef = useRef<number | undefined>( | ||
undefined, | ||
); | ||
|
||
// Get credits for USD amount when USD amount has stopped debouncing | ||
useEffect(() => { | ||
TurboFactory.unauthenticated(turboConfig) | ||
.getWincForFiat({ amount: USD(debouncedUsdAmount), promoCodes: [] }) | ||
.then(({ winc }) => { | ||
usdWhenCreditsWereLastUpdatedRef.current = debouncedUsdAmount; | ||
setWinc(winc); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
errorCallback(`Error getting credits for USD amount: ${err.message}`); | ||
}); | ||
}, [debouncedUsdAmount, errorCallback]); | ||
|
||
return [ | ||
winc ? +winc / wincPerCredit : undefined, | ||
usdWhenCreditsWereLastUpdatedRef.current, | ||
]; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { TurboFactory } from "@ardrive/turbo-sdk"; | ||
import { useState, useEffect } from "react"; | ||
import { turboConfig } from "../constants"; | ||
|
||
export function useWincForOneGiB() { | ||
const [wincForOneGiB, setWincForOneGiB] = useState<string | undefined>( | ||
undefined, | ||
); | ||
|
||
// On first render, get winc for 1 GiB for conversions | ||
useEffect(() => { | ||
TurboFactory.unauthenticated(turboConfig) | ||
.getFiatRates() | ||
.then(({ winc }) => { | ||
setWincForOneGiB(winc); | ||
}); | ||
}, []); | ||
|
||
return wincForOneGiB; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { TopUpRawResponse } from "@ardrive/turbo-sdk"; | ||
import { paymentServiceUrl } from "../constants"; | ||
|
||
export async function getTopUpQuote( | ||
usdAmount: number, | ||
recipientEmail: string, | ||
): Promise<TopUpRawResponse> { | ||
// TODO: support emails on turbo sdk | ||
// return turboFactory.unauthenticated(turboConfig).createCheckoutSession({ amount: USD(usdAmount / 100), email: recipientEmail }) | ||
const response = await fetch( | ||
`${paymentServiceUrl}/v1/top-up/checkout-session/${recipientEmail}/usd/${ | ||
usdAmount * 100 | ||
}?destinationAddressType=email`, | ||
); | ||
const data = await response.json(); | ||
|
||
return data; | ||
} |