Skip to content

Commit

Permalink
Merge branch 'dev' into feature/new-deploy-flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Malochka committed Dec 19, 2024
2 parents 2b4f5d6 + 58afe71 commit 72c0e8c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class TokenWalletSendBloc
KeyAccount? account;

UnsignedMessage? unsignedMessage;
UnsignedMessage? _unsignedMessage;

List<TxTreeSimulationErrorItem>? txErrors;

Expand Down Expand Up @@ -129,47 +128,17 @@ class TokenWalletSendBloc
tokenCurrency = tokenWallet.currency;
emit(const TokenWalletSendState.loading());

final internalMessage = await nekotonRepository.prepareTokenTransfer(
owner: owner,
rootTokenContract: rootTokenContract,
destination: await repackAddress(destination),
amount: tokenAmount,
payload: comment,
attachedAmount: attachedAmount,
notifyReceiver: true,
);

repackedDestination = internalMessage.destination;
sendAmount = internalMessage.amount;

try {
unsignedMessage = await nekotonRepository.prepareTransfer(
address: owner,
publicKey: publicKey,
destination: repackedDestination,
amount: sendAmount,
body: internalMessage.body,
bounce: defaultMessageBounce,
expiration: defaultSendTimeout,
);
} finally {
_unsignedMessage = unsignedMessage;
}

final msg = unsignedMessage;

if (msg == null) {
return;
}
final (internalMessage, unsignedMessage) = await _prepareTransfer();
this.unsignedMessage = unsignedMessage;

final result = await FutureExt.wait2(
nekotonRepository.estimateFees(
address: owner,
message: msg,
message: unsignedMessage,
),
nekotonRepository.simulateTransactionTree(
address: owner,
message: msg,
message: unsignedMessage,
),
);
fees = result.$1;
Expand Down Expand Up @@ -204,16 +173,13 @@ class TokenWalletSendBloc
String password,
) async {
try {
final msg = unsignedMessage;

if (msg == null) {
return;
}

emit(const TokenWalletSendState.sending(canClose: false));
await msg.refreshTimeout();
// await msg.refreshTimeout();
// TODO(komarov): fix refresh_timeout in nekoton
final (_, unsignedMessage) = await _prepareTransfer();
this.unsignedMessage = unsignedMessage;

final hash = msg.hash;
final hash = unsignedMessage.hash;
final transport = nekotonRepository.currentTransport.transport;

final signature = await nekotonRepository.seedList.sign(
Expand All @@ -223,7 +189,7 @@ class TokenWalletSendBloc
signatureId: await transport.getSignatureId(),
);

final signedMessage = await msg.sign(signature: signature);
final signedMessage = await unsignedMessage.sign(signature: signature);

emit(const TokenWalletSendState.sending(canClose: true));

Expand Down Expand Up @@ -260,11 +226,36 @@ class TokenWalletSendBloc
}
}

Future<(InternalMessage, UnsignedMessage)> _prepareTransfer() async {
final internalMessage = await nekotonRepository.prepareTokenTransfer(
owner: owner,
rootTokenContract: rootTokenContract,
destination: await repackAddress(destination),
amount: tokenAmount,
payload: comment,
attachedAmount: attachedAmount,
notifyReceiver: true,
);

// repackedDestination = internalMessage.destination;
// sendAmount = internalMessage.amount;

final unsignedMessage = await nekotonRepository.prepareTransfer(
address: owner,
publicKey: publicKey,
destination: repackedDestination,
amount: sendAmount,
body: internalMessage.body,
bounce: defaultMessageBounce,
expiration: defaultSendTimeout,
);

return (internalMessage, unsignedMessage);
}

@override
Future<void> close() {
unsignedMessage?.dispose();
_unsignedMessage?.dispose();

return super.close();
}
}
46 changes: 27 additions & 19 deletions lib/feature/wallet/ton_wallet_send/bloc/ton_wallet_send_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ class TonWalletSendBloc extends Bloc<TonWalletSendEvent, TonWalletSendState> {

KeyAccount? account;

late UnsignedMessage unsignedMessage;
UnsignedMessage? _unsignedMessage;
UnsignedMessage? unsignedMessage;

List<TxTreeSimulationErrorItem>? txErrors;

Expand Down Expand Up @@ -101,25 +100,16 @@ class TonWalletSendBloc extends Bloc<TonWalletSendEvent, TonWalletSendState> {
repackedDestination = await repackAddress(destination);
}

unsignedMessage = await nekotonRepository.prepareTransfer(
address: address,
publicKey: publicKey,
destination: repackedDestination,
amount: amount,
body: comment,
bounce: defaultMessageBounce,
expiration: defaultSendTimeout,
);
_unsignedMessage = unsignedMessage;
unsignedMessage = await _prepareTransfer();

final result = await FutureExt.wait2(
nekotonRepository.estimateFees(
address: address,
message: unsignedMessage,
message: unsignedMessage!,
),
nekotonRepository.simulateTransactionTree(
address: address,
message: unsignedMessage,
message: unsignedMessage!,
),
);
fees = result.$1;
Expand Down Expand Up @@ -155,10 +145,10 @@ class TonWalletSendBloc extends Bloc<TonWalletSendEvent, TonWalletSendState> {
emit(TonWalletSendState.readyToSend(fees!, txErrors));
}
} on FfiException catch (e, t) {
_logger.severe('_handleSend', e, t);
_logger.severe('_handlePrepare', e, t);
emit(TonWalletSendState.calculatingError(e.message));
} on Exception catch (e, t) {
_logger.severe('_handleSend', e, t);
_logger.severe('_handlePrepare', e, t);
emit(TonWalletSendState.calculatingError(e.toString()));
}
}
Expand All @@ -169,7 +159,10 @@ class TonWalletSendBloc extends Bloc<TonWalletSendEvent, TonWalletSendState> {
) async {
try {
emit(const TonWalletSendState.sending(canClose: false));
await unsignedMessage.refreshTimeout();

// await unsignedMessage.refreshTimeout();
// TODO(komarov): fix refresh_timeout in nekoton
final unsignedMessage = this.unsignedMessage = await _prepareTransfer();

final hash = unsignedMessage.hash;
final transport = nekotonRepository.currentTransport.transport;
Expand Down Expand Up @@ -215,10 +208,25 @@ class TonWalletSendBloc extends Bloc<TonWalletSendEvent, TonWalletSendState> {
}
}

Future<UnsignedMessage> _prepareTransfer() async {
if (needRepack) {
repackedDestination = await repackAddress(destination);
}

return nekotonRepository.prepareTransfer(
address: address,
publicKey: publicKey,
destination: repackedDestination,
amount: amount,
body: comment,
bounce: defaultMessageBounce,
expiration: defaultSendTimeout,
);
}

@override
Future<void> close() {
_unsignedMessage?.dispose();

unsignedMessage?.dispose();
return super.close();
}
}

0 comments on commit 72c0e8c

Please sign in to comment.