649
}
650
}
651
652
+ // Jupiter (Solana) swap path
653
+ if (walletType == WalletType.solana && trade != null && provider is JupiterExchangeProvider) {
654
+ final swapTransactionBase64 = trade.routerData;
655
+ final requestId = trade.routerValue;
656
+ if (swapTransactionBase64?.isNotEmpty == true &&
657
+ requestId?.isNotEmpty == true &&
658
+ solana != null) {
659
+ try {
660
+ final actualFee = trade.fee ?? 0.0005;
661
+ // Fallback to estimate if not available
662
+ final fee = actualFee > 0 ? actualFee : 0.0005;
663
+
664
+ final amount = double.tryParse(trade.amount) ?? 0.0;
665
+
666
+ pendingTransaction = await solana!.signAndPrepareJupiterSwapTransaction(
667
+ wallet,
668
+ swapTransactionBase64!,
669
+ requestId!,
670
+ trade.payoutAddress ?? '',
671
+ amount,
672
+ fee,
673
+ );
674
+
675
+ state = ExecutedSuccessfullyState();
676
+ return pendingTransaction;
677
+ } catch (e, s) {
678
+ printV('Jupiter swap error: $e\n$s');
679
+ throw Exception('Failed to process Jupiter swap: $e');
680
+ }
681
+ }
682
+ }
683
+
684
// Regular flow
685
686
pendingTransaction = await wallet.createTransaction(_credentials(provider));
816
if (walletType == WalletType.solana) {
817
Future.delayed(Duration(seconds: 1), () async {
818
try {
787
- // Updates tx history with the exact mints involved in transaction
788
- // Also updates balances for the tokens involved in the transaction
819
await solana!.pollForTransaction(
820
wallet,
821
pendingTransaction!.id,
823
maxRetries: 5,
824
);
825
} catch (e) {
796
- printV('Failed to update transactions after send: $e');
826
+ printV('Failed to poll for transaction: $e');
827
}
828
});
829
+
830
+ // Update balances for currencies involved in swap
831
+ if (_currentTrade != null) {
832
+ Future.delayed(Duration(seconds: 2), () async {
833
+ try {
834
+ final tokenMints = <String>[];
835
+
836
+ // Extract from currency mint (skip native SOL)
837
+ if (_currentTrade!.from != null && _currentTrade!.from != CryptoCurrency.sol) {
838
+ try {
839
+ final fromMint = solana!.getTokenAddress(_currentTrade!.from!);
840
+ tokenMints.add(fromMint);
841
+ } catch (e) {
842
+ printV('Error getting from currency mint: $e');
843
+ }
844
+ }
845
+
846
+ // Extract to currency mint (skip native SOL)
847
+ if (_currentTrade!.to != null && _currentTrade!.to != CryptoCurrency.sol) {
848
+ try {
849
+ final toMint = solana!.getTokenAddress(_currentTrade!.to!);
850
+ tokenMints.add(toMint);
851
+ } catch (e) {
852
+ printV('Error getting to currency mint: $e');
853
+ }
854
+ }
855
+
856
+ if (tokenMints.isNotEmpty) {
857
+ solana!.updateTokenBalances(
858
+ wallet,
859
+ tokenMints: tokenMints,
860
+ );
861
+
862
+ // Retry after a bit more time to ensure balance is updated
863
+ Future.delayed(Duration(seconds: 2), () async {
864
+ try {
865
+ await solana!.updateTokenBalances(
866
+ wallet,
867
+ tokenMints: tokenMints,
868
+ );
869
+ } catch (e) {
870
+ printV('Error retrying balance update: $e');
871
+ }
872
+ });
873
+ }
874
+ } catch (e) {
875
+ printV('Failed to update balances after send: $e');
876
+ } finally {
877
+ _currentTrade = null;
878
+ _currentProvider = null;
879
+ }
880
+ });
881
+ }
882
}
883
884
// Immediate transaction update for EVM chains, Tron, and Nano
918
919
_currentTrade!.txId = signature;
920
838
- if (!isSuccess) {
839
- _currentTrade!.stateRaw = TradeState.failed.raw;
840
- if (_currentTrade!.isInBox) {
841
- await _currentTrade!.save();
842
- }
843
- }
844
-
845
- if (isSuccess) {
846
- _currentTrade!.stateRaw = TradeState.completed.raw;
847
-
848
- if (_currentTrade!.isInBox) {
849
- await _currentTrade!.save();
850
- }
921
+ _currentTrade!.stateRaw = isSuccess ? TradeState.completed.raw : TradeState.failed.raw;
922
852
- _currentTrade = null;
853
- _currentProvider = null;
923
+ if (_currentTrade!.isInBox) {
924
+ await _currentTrade!.save();
925
}
926
}
927