Skip to content

Commit

Permalink
[retire] disable fiat payments for icr projects (#2178)
Browse files Browse the repository at this point in the history
* disable fiat payments for icr projects

* rename prop

* remove logging statement

* use usdc as default for icr

* trigger rebuild

* trigger rebuild

* touch api module

* touch api module

* revert

* log current api url

* bump version

* change version

* revert unnecessary changes

* bump api version

* log timeout message

---------

Co-authored-by: Michael Collins <[email protected]>
  • Loading branch information
sprrwhwk and 0xemc authored Feb 2, 2024
1 parent fdc1214 commit 0ffaba9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
14 changes: 12 additions & 2 deletions carbonmark/components/pages/Project/Retire/Pool/RetireForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { getFiatInfo } from "lib/fiat/fiatInfo";
import { getPoolApprovalValue } from "lib/getPoolData";
import { TransactionStatusMessage, TxnStatus } from "lib/statusMessage";
import {
CarbonmarkPaymentMethod,
CarbonmarkPaymentMethods,
ListingProduct,
PoolProduct,
Product,
Expand Down Expand Up @@ -74,14 +76,16 @@ export const RetireForm: FC<Props> = (props) => {
const [costs, setCosts] = useState("");

const { product } = props;
const defaultPaymentMethod: CarbonmarkPaymentMethod =
props.project.registry.startsWith("ICR") ? "usdc" : "fiat";

const methods = useForm<FormValues>({
mode: "onChange",
defaultValues: {
projectTokenAddress: isPool(product)
? product?.projectTokenAddress
: undefined,
paymentMethod: "fiat",
paymentMethod: defaultPaymentMethod,
...inputValues,
},
});
Expand All @@ -96,7 +100,7 @@ export const RetireForm: FC<Props> = (props) => {
// for the usdc icons to be visible for the required transition
// on first load the default paymentMethod is set as usdc & then
// immediately set to fiat.
methods.setValue("paymentMethod", "fiat");
methods.setValue("paymentMethod", defaultPaymentMethod);
}, []);

useEffect(() => {
Expand Down Expand Up @@ -335,6 +339,11 @@ export const RetireForm: FC<Props> = (props) => {
}
}, [retirementBlockNumber]);

const permittedPaymentMethods: Array<CarbonmarkPaymentMethod> =
props.project.registry.startsWith("ICR")
? CarbonmarkPaymentMethods.filter((method) => method !== "fiat")
: Array.from(CarbonmarkPaymentMethods);

return (
<FormProvider {...methods}>
<TwoColLayout>
Expand All @@ -353,6 +362,7 @@ export const RetireForm: FC<Props> = (props) => {
address={address}
fiatAmountError={fiatAmountError}
approvalValue={getApprovalValue()}
enabledPaymentMethods={permittedPaymentMethods}
/>
<SubmitButton
onSubmit={onContinue}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Props = {
address?: string;
fiatAmountError?: boolean;
approvalValue: string;
enabledPaymentMethods: Array<CarbonmarkPaymentMethod>;
};

const validations = (
Expand Down Expand Up @@ -338,7 +339,7 @@ export const RetireInputs: FC<Props> = (props) => {
<>
<button
type="button"
disabled={value.disabled}
disabled={!props.enabledPaymentMethods.includes(value.id)}
aria-label="Payment Method"
onClick={() => {
if (value.id === "usdc" && !isConnected && !address) {
Expand Down
2 changes: 1 addition & 1 deletion carbonmark/lib/getPaymentMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import USDC from "public/icons/USDC.png";

export type CarbonmarkPaymentMethodMap = {
[key in CarbonmarkPaymentMethod]: {
id: string;
id: CarbonmarkPaymentMethod;
icon: StaticImageData;
label: Uppercase<CarbonmarkPaymentMethod> | "Credit Card" | "Bank Transfer";
disabled: boolean;
Expand Down
7 changes: 6 additions & 1 deletion carbonmark/lib/types/carbonmark.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,9 @@ export type Balance = {
};

// add more methods here later
export type CarbonmarkPaymentMethod = "usdc" | "fiat" | "bank-transfer";
export const CarbonmarkPaymentMethods = [
"usdc",
"fiat",
"bank-transfer",
] as const;
export type CarbonmarkPaymentMethod = (typeof CarbonmarkPaymentMethods)[number];
1 change: 1 addition & 0 deletions carbonmark/lib/waitForApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const waitForApi = async (): Promise<boolean> => {
await getVintages();
return true;
} catch (e) {
console.debug(e.message);
console.debug(
`Waiting for API to come online at ${urls.api.base} (${counter})`
);
Expand Down

0 comments on commit 0ffaba9

Please sign in to comment.