@daimo/pay
Version:
Seamless crypto payments. Onboard users from any chain, any coin into your app with one click.
40 lines (37 loc) • 1.36 kB
JavaScript
import { useState, useEffect } from 'react';
/** Wallet payment options. User picks one. */
function useSolanaPaymentOptions({ trpc, address, usdRequired, isDepositFlow, }) {
const [options, setOptions] = useState(null);
const [isLoading, setIsLoading] = useState(false);
useEffect(() => {
const refreshWalletPaymentOptions = async () => {
if (address == null || usdRequired == null)
return;
setOptions(null);
setIsLoading(true);
try {
const newOptions = await trpc.getSolanaPaymentOptions.query({
pubKey: address,
// API expects undefined for deposit flow.
usdRequired: isDepositFlow ? undefined : usdRequired,
});
setOptions(newOptions);
}
catch (error) {
console.error(error);
}
finally {
setIsLoading(false);
}
};
if (address != null && usdRequired != null) {
refreshWalletPaymentOptions();
}
}, [address, usdRequired, isDepositFlow]); // eslint-disable-line react-hooks/exhaustive-deps
return {
options,
isLoading,
};
}
export { useSolanaPaymentOptions };
//# sourceMappingURL=useSolanaPaymentOptions.js.map