Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
bugfix: only attempt to create a token account on send if the error i…
Browse files Browse the repository at this point in the history
…s UnknownAccountInRequest. Also don't attempt to merge accounts if we don't have token accounts to merge.

GitOrigin-RevId: c0bc101e7bed7113042c84bcc888079f46c18282
  • Loading branch information
kikengineering committed May 27, 2021
1 parent 11c7b1d commit 33be8e2
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions base/src/main/java/org/kin/sdk/base/KinAccountContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ class KinAccountContextImpl private constructor(
private fun mergeTokenAccountsIfNecessary(): Promise<List<KinTokenAccountInfo>> {
val account = storage.getAccount(accountId)
val privateKey = account?.key as? Key.PrivateKey
return if (privateKey != null && account.status is KinAccount.Status.Registered) {
return if (privateKey != null && account.status is KinAccount.Status.Registered && account.tokenAccounts.size > 1) {
service.mergeTokenAccounts(
accountId,
privateKey,
Expand All @@ -464,7 +464,6 @@ class KinAccountContextImpl private constructor(
.map { tokenAccountInfos }
}
} else Promise.of(emptyList<KinTokenAccountInfo>())

}

override fun getAccount(forceUpdate: Boolean): Promise<KinAccount> {
Expand Down Expand Up @@ -645,7 +644,7 @@ class KinAccountContextImpl private constructor(
*payments.map { paymentItem ->
service.resolveTokenAccounts(paymentItem.destinationAccount)
.flatMap {
if (it.isEmpty()) {
if (it.isEmpty() && error == KinService.FatalError.UnknownAccountInRequest) {
service.createTokenAccountForDestinationOwner(paymentItem.destinationAccount.toProtoSolanaAccountId().toPublicKey())
.map { (destAccountInstructions, signer) ->
createAccountInstructions += destAccountInstructions
Expand Down

0 comments on commit 33be8e2

Please sign in to comment.