createWallet method
Creates a new smart wallet and returns a stream of SmartWalletEvents.
This function sends a request to create a new smart wallet and listens for the events related to the wallet creation process. It returns a stream of SmartWalletEvents that can be used to track the wallet creation progress.
Returns a Future that completes with a DC object:
- On success,
DC.data
will be called with a Stream of SmartWalletEvents. - On failure,
DC.error
will be called with anException
object.
Implementation
Future<DC<Exception, Stream<SmartWalletEvent>>> createWallet() async {
try {
final Response response = await _dio.post(
'/v1/smart-wallets/create',
options: _options,
);
if (response.statusCode == 201) {
final transactionId = response.data['transactionId'];
return DC.data(_createSubscriptionStream(transactionId));
}
return DC.error(Exception('Failed to create wallet'));
} on DioException catch (exception) {
return _handleDioErrorOccurredWhileCreatingWallet(exception);
} catch (e) {
return DC.error(Exception(e.toString()));
}
}