Skip to content

Commit

Permalink
feat: remove named imports
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesblasco committed Apr 18, 2024
1 parent 0a121f2 commit cc16c68
Show file tree
Hide file tree
Showing 44 changed files with 204 additions and 214 deletions.
8 changes: 4 additions & 4 deletions packages/stripe_js/lib/src/api/converters/js_converter.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:stripe_js/stripe_api.dart';

class ElementsConverter extends JSConverter<Elements> {
const ElementsConverter();
}

class JSConverter<T> implements JsonConverter<T, dynamic> {
const JSConverter();

Expand All @@ -15,6 +11,10 @@ class JSConverter<T> implements JsonConverter<T, dynamic> {
dynamic toJson(dynamic object) => object;
}

class ElementsConverter extends JSConverter<Elements> {
const ElementsConverter();
}

class ElementConverter extends JSConverter<Element> {
const ElementConverter();
}
6 changes: 2 additions & 4 deletions packages/stripe_js/lib/src/api/elements/element.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:js_interop' as web;
extension type const Element._(Object o) implements Object {}

extension type Element(web.JSObject o) implements web.JSObject {}

extension type Elements(web.JSObject o) implements web.JSObject {}
extension type const Elements._(Object o) implements Object {}
11 changes: 6 additions & 5 deletions packages/stripe_js/lib/src/js/elements/element_base.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import 'package:stripe_js/stripe_api.dart';
import 'dart:js_interop' as web;
import 'dart:js_interop';
import '../utils/utils.dart';

typedef EventCallback<T> = void Function(T event);

extension type StripeElement(Element o) implements Element {
extension type const StripeElement(JSObject o) implements JSObject, Element {
/// HTMLElement keeps giving this error for some reason:
/// Cannot find name 'HTMLElement'
external void mount(String domElement);
external void mount(JSAny domElement);

external void focus();
external void blur();
external void clear();
external void unmount();
external void destroy();

@web.JS("on")
external void _on(String event, web.JSExportedDartFunction handler);
@JS("on")
external void _on(String event, JSExportedDartFunction handler);

void on(String event, EventCallback<JSMap> handler) {
return _on(event, handler.toJS);
Expand Down
9 changes: 5 additions & 4 deletions packages/stripe_js/lib/src/js/elements/element_card.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'dart:js_interop' as web;
import 'dart:js_interop';

import 'package:stripe_js/stripe_api.dart';
import 'package:stripe_js/stripe_js.dart';

extension type CardPaymentElement(StripeElement o) implements StripeElement {
@web.JS('update')
external void _update(web.JSAny? options);
@JS('update')
external void _update(JSAny? options);

/// Updates the options the Element was initialized with.
/// Updates are merged into the existing configuration.
Expand All @@ -30,6 +30,7 @@ extension type CardPaymentElement(StripeElement o) implements StripeElement {

extension ElementsExtension on StripeElements {
CardPaymentElement createCard([CardElementOptions? options]) {
return create('card', (options?.toJson() ?? {}).jsify()) as CardPaymentElement;
return create('card', (options?.toJson() ?? {}).jsify())

Check warning on line 33 in packages/stripe_js/lib/src/js/elements/element_card.dart

View workflow job for this annotation

GitHub Actions / Typo CI

jsify

"jsify" is a typo. Did you mean "ossify"?
as CardPaymentElement;
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
// Module elements

import 'package:stripe_js/stripe_js.dart';
import 'dart:js_interop' as web;
import 'dart:js_interop';

extension type JsElementsCreateOptions._(web.JSObject o)
implements web.JSObject {
extension type JsElementsCreateOptions._(JSObject o) {
external factory JsElementsCreateOptions({
web.JSArray<Font>? fonts,
JSArray<Font>? fonts,
String? locale,
String? clientSecret,
JsElementAppearance? appearance,
String loader = "auto",
String loader,
});

external web.JSArray<Font> fonts;
external JSArray<Font> fonts;
external String locale;
external String clientSecret;
external JsElementAppearance appearance;
}

extension type JsElementAppearance._(web.JSObject o) implements web.JSObject {
extension type JsElementAppearance._(JSObject o) {
factory JsElementAppearance({
String? theme,
Map<String, String>? variables,
Expand All @@ -36,13 +35,13 @@ extension type JsElementAppearance._(web.JSObject o) implements web.JSObject {

external JsElementAppearance.__({
String? theme,
web.JSAny? variables,
web.JSAny? rules,
JSAny? variables,
JSAny? rules,
String? labels,
});

external String? theme;
external web.JSAny? variables;
external web.JSAny? rules;
external JSAny? variables;
external JSAny? rules;
external String? labels;
}
9 changes: 5 additions & 4 deletions packages/stripe_js/lib/src/js/elements/element_payment.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'dart:js_interop' as web;
import 'dart:js_interop';

import 'package:stripe_js/stripe_api.dart';
import 'package:stripe_js/stripe_js.dart';
Expand All @@ -7,7 +7,8 @@ extension ElementsPaymentExtension on StripeElements {
/// This method creates an instance of the Payment Element.
/// [options] : Options for creating the Payment Element.
PaymentElement createPayment([PaymentElementOptions? options]) {
return create('payment', (options?.toJson() ?? {}).jsify()) as PaymentElement;
return create('payment', (options?.toJson() ?? {}).jsify())

Check warning on line 10 in packages/stripe_js/lib/src/js/elements/element_payment.dart

View workflow job for this annotation

GitHub Actions / Typo CI

jsify

"jsify" is a typo. Did you mean "ossify"?
as PaymentElement;
}

PaymentElement? getPayment([PaymentElementOptions? options]) {
Expand All @@ -18,8 +19,8 @@ extension ElementsPaymentExtension on StripeElements {
extension type PaymentElement(StripeElement o) implements StripeElement {
/// Updates the options the Payment Element was initialized with.
/// Updates are merged into the existing configuration.
@web.JS('update')
external void _update([web.JSAny? options]);
@JS('update')
external void _update([JSAny? options]);

void update([PaymentElementOptions? options]) {
return _update((options?.toJson() ?? {}).jsify());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:js_interop' as web;
import 'dart:js_interop';
import 'package:stripe_js/stripe_js.dart';

extension type JsPaymentRequestButtonElementCreateOptions._(web.JSObject o)
implements web.JSObject {
extension type JsPaymentRequestButtonElementCreateOptions._(JSObject o)
implements JSObject {
external factory JsPaymentRequestButtonElementCreateOptions({
JsPaymentRequest? paymentRequest,
JsPaymentRequestButtonElementStyle? style,
Expand All @@ -11,8 +11,8 @@ extension type JsPaymentRequestButtonElementCreateOptions._(web.JSObject o)
external JsPaymentRequest paymentRequest;
}

extension type JsPaymentRequestButtonElementStyle._(web.JSObject o)
implements web.JSObject {
extension type JsPaymentRequestButtonElementStyle._(JSObject o)
implements JSObject {
external factory JsPaymentRequestButtonElementStyle({
PaymentRequestButtonStyleOptions? paymentRequestButton,
});
Expand Down
22 changes: 11 additions & 11 deletions packages/stripe_js/lib/src/js/elements/elements_base.dart
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import 'package:stripe_js/stripe_api.dart';
import 'package:stripe_js/stripe_js.dart';
import 'dart:js_interop' as web;
import 'dart:js_interop';

extension type StripeElements(Elements o) implements Elements {
external StripeElement create(String type, [web.JSAny? options]);
extension type StripeElements(JSObject o) implements JSObject, Elements {
external StripeElement create(String type, [JSAny? options]);
external StripeElement? getElement(String type);
}

extension type ElementChangeResponse._(web.JSObject o) {
extension type ElementChangeResponse._(JSObject o) {
external ElementChangeResponse({
String elementType,
String brand,
bool complete,
bool empty,
web.JSAny /*{ postalCode: string | number }|String*/ value,
JSAny /*{ postalCode: string | number }|String*/ value,
String country,
String bankName,
web.JSAny error,
JSAny error,
});
external String elementType;
external String brand;
external bool complete;
external bool empty;
external web.JSAny /*{ postalCode: string | number }|String*/ get value;
external JSAny /*{ postalCode: string | number }|String*/ get value;
external String country;
external String bankName;
external web.JSAny error;
external JSAny error;
}

extension type ElementOptions._(web.JSObject o) {
external ElementOptions({web.JSArray<Font> fonts, String locale});
extension type ElementOptions._(JSObject o) {
external ElementOptions({JSArray<Font> fonts, String locale});

external web.JSArray<Font> fonts;
external JSArray<Font> fonts;
external String locale;
}

Expand Down
22 changes: 11 additions & 11 deletions packages/stripe_js/lib/src/js/elements/styles.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:js_interop' as web;

import 'dart:js_interop';

extension type Style._(StyleOptions o) implements StyleOptions {
external factory Style({
Expand All @@ -13,7 +12,7 @@ extension type Style._(StyleOptions o) implements StyleOptions {
String fontSmoothing,
String fontStyle,
String fontVariant,
web.JSAny /*String|num*/ fontWeight,
JSAny /*String|num*/ fontWeight,
String iconColor,
String lineHeight,
String letterSpacing,
Expand All @@ -22,13 +21,13 @@ extension type Style._(StyleOptions o) implements StyleOptions {
String textShadow,
String textTransform,
});
@web.JS(':hover:')
@JS(':hover:')
external StyleOptions hover;

@web.JS(':focus')
@JS(':focus')
external StyleOptions focus;

@web.JS(':disabled:')
@JS(':disabled:')
external StyleOptions disabled;

/*external StyleOptions get ::placeholder;*/
Expand All @@ -41,7 +40,7 @@ extension type Style._(StyleOptions o) implements StyleOptions {
/*external set ::-ms-clear(StyleOptions v);*/
}

extension type Font._(web.JSObject o) implements web.JSObject {
extension type Font._(JSObject o) implements JSObject {
external Font({
String family,
String src,
Expand All @@ -61,15 +60,15 @@ extension type Font._(web.JSObject o) implements web.JSObject {
external String cssSrc;
}

extension type StyleOptions._(web.JSObject o) implements web.JSObject {
extension type StyleOptions._(JSObject o) implements JSObject {
external String get color;
external String get backgroundColor;
external String get fontFamily;
external String get fontSize;
external String get fontSmoothing;
external String get fontStyle;
external String get fontVariant;
external web.JSAny /*String|num*/ get fontWeight;
external JSAny /*String|num*/ get fontWeight;
external String get iconColor;
external String get lineHeight;
external String get letterSpacing;
Expand All @@ -85,7 +84,7 @@ extension type StyleOptions._(web.JSObject o) implements web.JSObject {
String fontSmoothing,
String fontStyle,
String fontVariant,
web.JSAny /*String|num*/ fontWeight,
JSAny /*String|num*/ fontWeight,
String iconColor,
String lineHeight,
String letterSpacing,
Expand All @@ -96,7 +95,7 @@ extension type StyleOptions._(web.JSObject o) implements web.JSObject {
});
}

extension type PaymentRequestButtonStyleOptions._(web.JSObject o) {
extension type PaymentRequestButtonStyleOptions._(JSObject o) {
external PaymentRequestButtonStyleOptions({
PaymentRequestButtonType type,
PaymentRequestButtonTheme theme,
Expand All @@ -105,6 +104,7 @@ extension type PaymentRequestButtonStyleOptions._(web.JSObject o) {

/// One of 'default', 'book', 'buy', or 'donate'
external PaymentRequestButtonType type;

/// One of 'dark', 'light', or 'light-outline'
external PaymentRequestButtonTheme theme;

Expand Down
1 change: 0 additions & 1 deletion packages/stripe_js/lib/src/js/js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ export 'payment_methods/payment_methods.dart';
export 'payment_intents/payment_intents.dart';
export 'payment_requests/payment_requests.dart';
export 'elements/elements.dart';

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:stripe_js/src/js/utils/utils.dart';

Check warning on line 1 in packages/stripe_js/lib/src/js/payment_intents/confirm_acss_debit_payment.dart

View workflow job for this annotation

GitHub Actions / Typo CI

Filename: packages/stripe_js/lib/src/js/payment_intents/confirm_acss_debit_payment.dart

"acss" in the filename is a typo. Did you mean "ass"?
import 'package:stripe_js/stripe_api.dart';
import 'package:stripe_js/stripe_js.dart';
import 'dart:js_interop' as web;
import 'dart:js_interop';

extension ExtensionAcssDebitPayment on Stripe {
/// Use stripe.confirmAcssDebitPayment in the Accept a payment flow for the
Expand Down Expand Up @@ -38,10 +38,10 @@ extension ExtensionAcssDebitPayment on Stripe {
.then((response) => response.toDart);
}

@web.JS('confirmAcssDebitPayment')
external web.JSPromise<JSIntentResponse> _confirmAcssDebitPayment(
@JS('confirmAcssDebitPayment')

Check warning on line 41 in packages/stripe_js/lib/src/js/payment_intents/confirm_acss_debit_payment.dart

View workflow job for this annotation

GitHub Actions / Typo CI

confirmAcssDebitPayment

"confirmAcssDebitPayment" is a typo. Did you mean "confirmAssDebitPayment"?
external JSPromise<JSIntentResponse> _confirmAcssDebitPayment(
String clientSecret, [
web.JSAny? data,
web.JSAny? options,
JSAny? data,
JSAny? options,
]);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:stripe_js/stripe_api.dart';
import 'package:stripe_js/stripe_js.dart';
import '../utils/utils.dart';
import 'dart:js_interop' as web;
import 'dart:js_interop';

extension ExtensionAlipayPayment on Stripe {
/// Use stripe.confirmAlipayPayment in the Alipay payment method
Expand Down Expand Up @@ -34,13 +34,12 @@ extension ExtensionAlipayPayment on Stripe {
return _confirmAlipayPayment(clientSecret, jsData, jsOptions)
.toDart
.then((response) => response.toDart);

}

@web.JS('confirmAlipayPayment')
external web.JSPromise<JSIntentResponse> _confirmAlipayPayment(
@JS('confirmAlipayPayment')
external JSPromise<JSIntentResponse> _confirmAlipayPayment(
String clientSecret, [
web.JSAny? data,
web.JSAny? options,
JSAny? data,
JSAny? options,
]);
}
Loading

0 comments on commit cc16c68

Please sign in to comment.