Skip to content

Commit

Permalink
Merge pull request #1466 from WalletConnect/feat/settlement_before_pr…
Browse files Browse the repository at this point in the history
…oposal_response

feat: Publish session settle before proposal approve
  • Loading branch information
jakubuid committed Aug 12, 2024
2 parents 9a7d3fb + 25b41b1 commit 4899bf1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ class SignClientInstrumentedAndroidTest {
launch(walletDelegate, dappDelegate)
}

@Test
fun receiveSessionProposal() {
Timber.d("receiveRejectSession: start")

val walletDelegate = object : WalletDelegate() {
override fun onSessionProposal(sessionProposal: Sign.Model.SessionProposal, verifyContext: Sign.Model.VerifyContext) {
scenarioExtension.closeAsSuccess().also { Timber.d("proposal received: finish") }
}
}
val dappDelegate = object : DappDelegate() {}

launch(walletDelegate, dappDelegate)
}

@Test
fun receiveRejectSession() {
Timber.d("receiveRejectSession: start")
Expand Down Expand Up @@ -312,22 +326,13 @@ class SignClientInstrumentedAndroidTest {
}

private fun pairDappAndWallet(onPairSuccess: (pairing: Core.Model.Pairing) -> Unit) {
TestClient.Dapp.Pairing.getPairings().let { pairings ->
if (pairings.isEmpty()) {
Timber.d("pairings.isEmpty() == true")

val pairing: Core.Model.Pairing = (TestClient.Dapp.Pairing.create(onError = ::globalOnError) ?: fail("Unable to create a Pairing")) as Core.Model.Pairing
Timber.d("DappClient.pairing.create: $pairing")

TestClient.Wallet.Pairing.pair(Core.Params.Pair(pairing.uri), onError = ::globalOnError, onSuccess = {
Timber.d("WalletClient.pairing.pair: $pairing")
onPairSuccess(pairing)
})
} else {
Timber.d("pairings.isEmpty() == false")
fail("Pairing already exists. Storage must be cleared in between runs")
}
}
val pairing: Core.Model.Pairing = (TestClient.Dapp.Pairing.create(onError = ::globalOnError) ?: fail("Unable to create a Pairing")) as Core.Model.Pairing
Timber.d("DappClient.pairing.create: $pairing")

TestClient.Wallet.Pairing.pair(Core.Params.Pair(pairing.uri), onError = ::globalOnError, onSuccess = {
Timber.d("WalletClient.pairing.pair: $pairing")
onPairSuccess(pairing)
})
}

private fun pairAndConnect() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ internal class ApproveSessionUseCase(
}.also { logger.error("Subscribe to session topic failure: $error") }
onFailure(error)
})

sessionSettle(request.id, proposal, sessionTopic, request.topic)

trace.add(Trace.Session.PUBLISHING_SESSION_APPROVE).also { logger.log("Publishing session approve on topic: $sessionTopic") }
jsonRpcInteractor.respondWithParams(request, approvalParams, irnParams,
onSuccess = {
Expand All @@ -169,8 +172,6 @@ internal class ApproveSessionUseCase(
}.also { logger.error("Session approve failure, topic: $sessionTopic: $error") }
onFailure(error)
})

sessionSettle(request.id, proposal, sessionTopic, request.topic)
} catch (e: Exception) {
if (e is NoRelayConnectionException) insertEventUseCase(Props(type = EventType.Error.NO_WSS_CONNECTION, properties = Properties(trace = trace, topic = pairingTopic)))
if (e is NoInternetConnectionException) insertEventUseCase(Props(type = EventType.Error.NO_INTERNET_CONNECTION, properties = Properties(trace = trace, topic = pairingTopic)))
Expand Down

0 comments on commit 4899bf1

Please sign in to comment.