Skip to content

Commit

Permalink
Merge pull request #120 from tonkeeper/ledger-bug-fixes
Browse files Browse the repository at this point in the history
ledger bug fixes
  • Loading branch information
polstianka authored Jan 27, 2025
2 parents 7fe55c5 + 564001a commit fa78714
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ data class TransferEntity(
}
val builder = TransactionBuilder()
if (isNft) {
builder.setCoins(coins)
builder.setCoins(jettonTransferAmount.toGrams())
builder.setDestination(AddrStd.parse(nftAddress!!))
builder.setPayload(
TonPayloadFormat.NftTransfer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ class LedgerSignScreen: BaseFragment(R.layout.fragment_ledger_sign), BaseFragmen
collectFlow(connectionViewModel.eventFlow, ::onEvent)
}

/*override fun onDestroy() {
super.onDestroy()
if (!requireActivity().isChangingConfigurations && !isSuccessful) {
navigation?.setFragmentResult(args.requestKey, Bundle())
}
}*/

private fun onEvent(event: LedgerEvent) {
when (event) {
is LedgerEvent.Ready -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.tonapps.icu.Coins

sealed class SendEvent {
data class Failed(val throwable: Throwable): SendEvent()
data object Canceled: SendEvent()
data object Success: SendEvent()
data object Loading: SendEvent()
data class InsufficientBalance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ class SendScreen(wallet: WalletEntity) : WalletContextScreen(R.layout.fragment_s

private fun onEvent(event: SendEvent) {
when (event) {
is SendEvent.Canceled -> setDefault()
is SendEvent.Failed -> setFailed(event.throwable)
is SendEvent.Success -> setSuccess()
is SendEvent.Loading -> setLoading()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,9 @@ class SendViewModel(
_uiEventFlow.tryEmit(SendEvent.Loading)
Triple(boc, transfer.wallet, internalMessage)
}.catch {
if (it !is CancellationException) {
if (it is CancellationException) {
_uiEventFlow.tryEmit(SendEvent.Canceled)
} else {
FirebaseCrashlytics.getInstance().recordException(Throwable("SendViewModel sign failed", it))
_uiEventFlow.tryEmit(SendEvent.Failed(it))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class SendTransactionViewModel(
init {
viewModelScope.launch(Dispatchers.IO) {
val tokens = getTokens()
val internalMessage = (forceRelayer || settingsRepository.batteryIsEnabledTx(wallet.accountId, batteryTransactionType))
val useBattery = settingsRepository.batteryIsEnabledTx(wallet.accountId, batteryTransactionType)
try {
val transfers = transfers(tokens.filter { it.isRequestMinting }, true)
message = accountRepository.messageBody(wallet, request.validUntil, transfers)
Expand Down Expand Up @@ -119,7 +119,7 @@ class SendTransactionViewModel(
wallet = wallet,
balance = tonBalance,
required = transferTotal,
withRechargeBattery = false,
withRechargeBattery = forceRelayer || useBattery,
singleWallet = isSingleWallet()
)
} else {
Expand All @@ -132,7 +132,7 @@ class SendTransactionViewModel(
}
} catch (e: Throwable) {
FirebaseCrashlytics.getInstance().recordException(APIException.Emulation(
boc = message?.createSignedBody(EmptyPrivateKeyEd25519.invoke(), internalMessage)?.base64() ?: "failed",
boc = message?.createSignedBody(EmptyPrivateKeyEd25519.invoke(), forceRelayer || useBattery)?.base64() ?: "failed",
sourceUri = request.appUri,
cause = e
))
Expand All @@ -143,7 +143,7 @@ class SendTransactionViewModel(
wallet = wallet,
balance = tonBalance,
required = Coins.of(0.1),
withRechargeBattery = false,
withRechargeBattery = forceRelayer || useBattery,
singleWallet = isSingleWallet()
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,14 @@ class TonTransport(private val transport: Transport) {
}

is DNSRecord.Unknown -> {
bytes += LedgerWriter.putUint8(if (record.value != null) 1 else 0) + LedgerWriter.putUint8(
1
)

if (record.key.size != 32) {
throw Error("DNS record key length must be 32 bytes long")
}

bytes += LedgerWriter.putUint8(if (record.value != null) 1 else 0)
bytes += LedgerWriter.putUint8(1)
bytes += record.key

cell = cell.storeBytes(record.key)

if (record.value != null) {
Expand Down

0 comments on commit fa78714

Please sign in to comment.