Skip to content

Commit

Permalink
feat: add initial error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dtscalac committed May 28, 2024
1 parent eabdffb commit 1d131bf
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export 'src/cardano_wallet.dart';
export 'src/catalyst_cardano_platform.dart';
export 'src/exceptions.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract interface class CardanoWallet {
/// transparent to web pages using this API. If a wallet is already connected
/// this function should not request access a second time, and instead just
/// return the API object.
Future<CardanoWalletApi> enable();
Future<CardanoWalletApi> enable({List<CipExtension>? extensions});
}

/// The full API of enabled wallet extension.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ extension type JSCardanoWallet(JSObject _) implements JSObject {
external JSPromise<JSBoolean> isEnabled();

/// See [CardanoWallet.enable].
external JSPromise<JSCardanoWalletApi> enable();
external JSPromise<JSCardanoWalletApi> enable([
JSCipExtensions? extensions,
]);

/// Converts JS representation to pure dart representation.
CardanoWallet get toDart => JSCardanoWalletProxy(this);
Expand Down Expand Up @@ -85,11 +87,39 @@ extension type JSCardanoWalletApi(JSObject _) implements JSObject {
CardanoWalletApi get toDart => JSCardanoWalletApiProxy(this);
}

/// Represents wallet extensions to be activated in [JSCardanoWallet.enable].
extension type JSCipExtensions._(JSObject _) implements JSObject {
/// An array of extensions.
external JSArray<JSCipExtension> get extensions;

/// The default constructor for [JSCipExtensions].
external factory JSCipExtensions({JSArray<JSCipExtension> extensions});

/// Constructs [JSCipExtensions] from dart representation.
factory JSCipExtensions.fromDart(List<CipExtension> extensions) {
return JSCipExtensions(
extensions: extensions.map(JSCipExtension.fromDart).toList().toJS,
);
}

/// Converts JS representation to pure dart representation.
List<CipExtension> get toDart =>
extensions.toDart.map((e) => e.toDart).toList();
}

/// The JS representation of the [CipExtension].
extension type JSCipExtension(JSObject _) implements JSObject {
extension type JSCipExtension._(JSObject _) implements JSObject {
/// See [JSCipExtension.cip].
external JSNumber get cip;

/// The default constructor for [JSCipExtension].
external factory JSCipExtension({JSNumber cip});

/// Constructs [JSCipExtension] from dart representation.
factory JSCipExtension.fromDart(CipExtension extension) {
return JSCipExtension(cip: extension.cip.toJS);
}

/// Converts JS representation to pure dart representation.
CipExtension get toDart => CipExtension(cip: cip.toDartInt);
}
Expand Down
Loading

0 comments on commit 1d131bf

Please sign in to comment.