Skip to content

Commit

Permalink
fix: fix errors with creating invites
Browse files Browse the repository at this point in the history
  • Loading branch information
HashEngineering committed Jan 25, 2025
1 parent 67aa4a6 commit 007bfb8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ interface InvitationsDao {
suspend fun count(): Int

@Query("SELECT * FROM invitation_table WHERE fundingAddress = :fundingAddress")
suspend fun loadByFundingAddress(fundingAddress: String): Invitation
suspend fun loadByFundingAddress(fundingAddress: String): Invitation?
}
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ class TopUpRepositoryImpl @Inject constructor(
if (invitation.dynamicLink != null) {
fundingTxes.remove(invitation.txid)
} else {
// TODO: should we fix the link now or let the user do it
val dashPayProfile = platformRepo.getLocalUserProfile()
val assetLockTx = fundingTxes[invitation.txid]
if (assetLockTx != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,22 @@ class SendInviteOperation(val application: Application) {
val allOperationsData = workManager.getWorkInfosByTagLiveData(SendInviteWorker::class.qualifiedName!!)

@SuppressLint("EnqueueWork")
fun create(id: String, value: Coin): WorkContinuation {
fun create(fundingAddress: String, value: Coin): WorkContinuation {

val password = SecurityGuard().retrievePassword()
val sendInviteWorker = OneTimeWorkRequestBuilder<SendInviteWorker>()
.setInputData(
workDataOf(
SendInviteWorker.KEY_PASSWORD to password,
SendInviteWorker.KEY_FUNDING_ADDRESS to fundingAddress,
SendInviteWorker.KEY_VALUE to value.value
)
)
.addTag("invite:$id")
.addTag("invite:$fundingAddress")
.build()

return WorkManager.getInstance(application)
.beginUniqueWork(uniqueWorkName(id),
.beginUniqueWork(uniqueWorkName(fundingAddress),
ExistingWorkPolicy.KEEP,
sendInviteWorker)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,28 @@ class SendInviteWorker @AssistedInject constructor(
org.bitcoinj.core.Context.propagate(wallet.context)
val blockchainIdentity = platformRepo.blockchainIdentity
var invitation = invitationsDao.loadByFundingAddress(fundingAddress)
val assetLockTx = if (!invitation.hasTransaction()) {
val assetLockTx = if (invitation == null || !invitation.hasTransaction()) {
topUpRepository.createInviteFundingTransactionAsync(
blockchainIdentity,
encryptionKey,
Coin.valueOf(value)
)
} else {
authGroupExtension.invitationFundingTransactions.find { it.txId == invitation.txid }
authGroupExtension.invitationFundingTransactions.find { it.txId == invitation!!.txid }
?: return Result.failure(workDataOf(KEY_ERROR_MESSAGE to "invite funding tx ${invitation.txid} not found"))
}

// make sure TX has been sent
val confidence = assetLockTx.getConfidence(walletDataProvider.wallet!!.context)
val wasTxSent = confidence.isChainLocked ||
confidence.isTransactionLocked ||
confidence.numBroadcastPeers() > 0
confidence.isTransactionLocked ||
confidence.numBroadcastPeers() > 0
if (!wasTxSent) {
topUpRepository.sendTransaction(assetLockTx)
}

// create the dynamic link
invitation = invitationsDao.loadByFundingAddress(fundingAddress)
invitation = invitationsDao.loadByFundingAddress(fundingAddress)!!
if (invitation.dynamicLink == null) {
val dashPayProfile = platformRepo.getLocalUserProfile()
val dynamicLink = topUpRepository.createDynamicLink(dashPayProfile!!, assetLockTx, encryptionKey)
Expand Down

0 comments on commit 007bfb8

Please sign in to comment.