Skip to content
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

More bulletproof, intuitive options format #73

Open
osdiab opened this issue Feb 5, 2021 · 3 comments
Open

More bulletproof, intuitive options format #73

osdiab opened this issue Feb 5, 2021 · 3 comments
Assignees
Labels
integration ease of integration with the donate-button p1

Comments

@osdiab
Copy link
Contributor

osdiab commented Feb 5, 2021

The options format as is is pretty brittle, with a lot of stuff failing if you don't specify them just right. For example, levels need to be duplicated in multiple places, changing behavior in the i18n blob, and specifying incorrectly can lead to confusing behavior and crashing, when one would assume an i18n blob would be totally optional and only impact display.

With a major version bump let's make a cleaner, less failure-prone options format that better allows for partial inclusion of options and avoid contradictory settings. Using TypeScript will also help us make sure that we don't blow things up unexpectedly. #11

@osdiab osdiab added the p1 label Feb 10, 2021
@osdiab
Copy link
Contributor Author

osdiab commented Feb 10, 2021

we should do this before a lot of people start using the donate button, or else it will be hard to move

@osdiab osdiab self-assigned this Feb 10, 2021
@osdiab osdiab added the integration ease of integration with the donate-button label Feb 10, 2021
@osdiab
Copy link
Contributor Author

osdiab commented Feb 10, 2021

This is the current interface, as I typed out based on the actual usage on site, taken from options-types.ts:

export enum LayoutMode {
	SINGLE = 'SINGLE',
	SPLIT = 'SPLIT'
}
export type DonationFrequency = 'ONCE' | 'MONTHLY';
export interface DonationLevel {
	amount: string;
	bgColor?: string;
	default?: boolean;
	img?: string;
	classes?: readonly string[];
}

/**
 * Donation level as expected in the i18n object
 * TODO: don't duplicate info from DonationLevel
 */
export interface I18NDonationLevel {
	amount: string;
	name?: string;
	description1?: string;
	description2?: string;
}

export type OnSubmitFunction = (parameters: {
	amount: string;
	frequency: DonationFrequency;
}) => void;
export interface OnSubmitObject {
	readonly charity: string;
	readonly params?: {
		readonly share_info?: 0 | 1;
		readonly no_exit?: 0 | 1;
	};
}
export type OnSubmit = OnSubmitFunction | OnSubmitObject;

export interface MonthlyOptions {
	readonly levels: readonly DonationLevel[];
}
export interface OneTimeOptions {
	readonly img?: string;
	readonly levels: number[];
	readonly allowCustom: boolean;
	readonly bgColor?: string;
}
export interface I18NFrequencyOptions {
	readonly logo: {
		readonly header: string;
		readonly text: string;
		readonly link: string;
	};
	readonly name?: string;
	readonly description?: string;
	readonly header: string;
	readonly info: string;
	readonly levels?: readonly I18NDonationLevel[];
	readonly custom: {
		readonly label?: string;
		readonly placeholder: string;
	};
	readonly button: string;
	readonly switch: string;
}
export interface I18NOptions {
	readonly company: {
		readonly logo: string;
		readonly name: string;
		readonly location: string;
	};
	readonly monthly: I18NFrequencyOptions;
	readonly oneTime: I18NFrequencyOptions;
	readonly footer: string;
}
export enum DefaultFrequency {
	MONTHLY = 'monthly',
	ONE_TIME = 'one-time'
}
export interface DonateButtonOptions {
	readonly monthly: MonthlyOptions;
	readonly oneTime: OneTimeOptions;
	readonly onSubmit: OnSubmit;
	readonly defaultMode: DefaultFrequency;
	readonly currency: string;
	readonly mode: LayoutMode;
	readonly show: boolean;
	readonly i18n: Partial<Record<string, I18NOptions>>;
	readonly language: string;
}

@osdiab
Copy link
Contributor Author

osdiab commented Apr 15, 2021

I'm going to work on this now, by making a beta version of the donate button package to allow for sweeping breaking changes under a new version number, in order to expedite getting a simplified button out that directs people to specifically do crypto donations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration ease of integration with the donate-button p1
Projects
None yet
Development

No branches or pull requests

1 participant