Skip to content

Commit

Permalink
fix: catalyst cardano null utxos (#746)
Browse files Browse the repository at this point in the history
* fix: handle null utxos

* fix: more error logs
  • Loading branch information
dtscalac authored Sep 2, 2024
1 parent 1fb17b2 commit 3f2f592
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ Future<void> _signAndSubmitRbacTx({
),
);

if (utxos.isEmpty) {
throw Exception('Insufficient balance, please top up your wallet');
}

final x509Envelope = await _buildMetadataEnvelope(
utxos: utxos,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Future<void> _signAndSubmitTx({
),
);

if (utxos.isEmpty) {
throw Exception('Insufficient balance, please top up your wallet');
}

final unsignedTx = _buildUnsignedTx(
utxos: utxos,
changeAddress: changeAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ extension type JSCardanoWalletApi(JSObject _) implements JSObject {
]);

/// See [CardanoWalletApi.getUtxos].
external JSPromise<JSArray<JSString>> getUtxos([
external JSPromise<JSArray<JSString>>? getUtxos([
JSAny? amount,
JSAny? paginate,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,24 @@ class JSCardanoWalletApiProxy implements CardanoWalletApi {
Paginate? paginate,
}) async {
try {
return await _delegate
.getUtxos(
amount != null
? hex.encode(cbor.encode(amount.toCbor())).toJS
: makeUndefined(),
paginate != null ? JSPaginate.fromDart(paginate) : makeUndefined(),
)
.toDart
.then(
(array) => array.toDart
.map(
(item) => TransactionUnspentOutput.fromCbor(
cbor.decode(hex.decode(item.toDart)),
),
)
.toList(),
);
final utxos = _delegate.getUtxos(
amount != null
? hex.encode(cbor.encode(amount.toCbor())).toJS
: makeUndefined(),
paginate != null ? JSPaginate.fromDart(paginate) : makeUndefined(),
);

if (utxos == null) return [];

return await utxos.toDart.then(
(array) => array.toDart
.map(
(item) => TransactionUnspentOutput.fromCbor(
cbor.decode(hex.decode(item.toDart)),
),
)
.toList(),
);
} catch (ex) {
throw _mapApiException(ex) ??
_mapPaginateException(ex) ??
Expand Down

0 comments on commit 3f2f592

Please sign in to comment.