Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pairing expiry reduction #1477

Merged
merged 18 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.walletconnect.android

import com.walletconnect.android.internal.common.model.AppMetaDataType
import com.walletconnect.android.internal.common.model.Expiry

object Core {
sealed interface Listeners {
Expand Down Expand Up @@ -30,7 +29,9 @@ object Core {
val verifyUrl: String? = null
) : Model()

@Deprecated(message = "DeletedPairing has been deprecated")
data class DeletedPairing(val topic: String, val reason: String) : Model()
@Deprecated(message = "ExpiredPairing has been deprecated")
data class ExpiredPairing(val pairing: Pairing) : Model()

data class PairingState(val isPairingState: Boolean) : Model()
Expand All @@ -42,6 +43,7 @@ object Core {
val relayProtocol: String,
val relayData: String?,
val uri: String,
@Deprecated("isActive has been deprecated")
val isActive: Boolean,
val registeredMethods: String
) : Model()
Expand Down Expand Up @@ -163,12 +165,10 @@ object Core {

data class Disconnect(val topic: String) : Params()

data class Activate(val topic: String) : Params()
data class Delete(val topic: String) : Params()

data class RequestReceived(val topic: String) : Params()

data class UpdateExpiry(val topic: String, val expiry: Expiry) : Params()

data class UpdateMetadata(val topic: String, val metadata: Model.AppMetaData, val metaDataType: AppMetaDataType) : Params()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class GenericException(override val message: String?) : WalletConnectException(m
class MalformedWalletConnectUri(override val message: String?) : WalletConnectException(message)
class PairWithExistingPairingIsNotAllowed(override val message: String?) : WalletConnectException(message)
class ExpiredPairingException(override val message: String?) : WalletConnectException(message)
class ExpiredPairingURIException(override val message: String?) : WalletConnectException(message)
class CannotFindSequenceForTopic(override val message: String?) : WalletConnectException(message)

class InvalidProjectIdException(override val message: String?) : WalletConnectException(message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.walletconnect.android.internal.common.model

import com.walletconnect.android.internal.common.model.type.Sequence
import com.walletconnect.android.internal.utils.currentTimeInSeconds
import com.walletconnect.android.internal.utils.fiveMinutesInSeconds
import com.walletconnect.android.pairing.model.inactivePairing
import com.walletconnect.android.pairing.model.pairingExpiry
import com.walletconnect.foundation.common.model.Topic

data class
Pairing(
data class Pairing(
override val topic: Topic,
override val expiry: Expiry,
val peerAppMetaData: AppMetaData? = null,
Expand All @@ -17,8 +14,6 @@ Pairing(
val isProposalReceived: Boolean = false,
val methods: String? = null,
) : Sequence {
val isActive: Boolean
get() = (expiry.seconds - currentTimeInSeconds) > fiveMinutesInSeconds

constructor(topic: Topic, relay: RelayProtocolOptions, symmetricKey: SymmetricKey, expiry: Expiry, methods: String?) : this(
topic = topic,
Expand All @@ -31,7 +26,7 @@ Pairing(

constructor(uri: WalletConnectUri) : this(
topic = uri.topic,
expiry = uri.expiry ?: Expiry(inactivePairing),
expiry = uri.expiry ?: Expiry(pairingExpiry),
relayProtocol = uri.relay.protocol,
relayData = uri.relay.data,
uri = uri.toAbsoluteString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.walletconnect.android.internal.common.model.AppMetaData
import com.walletconnect.android.internal.common.model.Expiry
import com.walletconnect.android.internal.common.model.Pairing
import com.walletconnect.android.internal.common.model.Redirect
import com.walletconnect.android.pairing.model.activePairing
import com.walletconnect.android.sdk.storage.data.dao.PairingQueries
import com.walletconnect.foundation.common.model.Topic
import com.walletconnect.utils.Empty
Expand All @@ -23,7 +22,7 @@ class PairingStorageRepository(private val pairingQueries: PairingQueries) : Pai
relay_data = relayData,
uri = uri,
methods = methods ?: String.Empty,
is_active = isActive,
is_active = true,
is_proposal_received = isProposalReceived
)
}
Expand All @@ -40,16 +39,7 @@ class PairingStorageRepository(private val pairingQueries: PairingQueries) : Pai
override suspend fun getListOfPairings(): List<Pairing> = pairingQueries.getListOfPairing(mapper = this::toPairing).awaitAsList()

@Throws(SQLiteException::class)
override suspend fun getListOfInactivePairings(): List<Pairing> = pairingQueries.getListOfInactivePairings(mapper = this::toPairing).awaitAsList()

@Throws(SQLiteException::class)
override suspend fun getListOfActivePairings(): List<Pairing> = pairingQueries.getListOfActivePairings(mapper = this::toPairing).awaitAsList()

@Throws(SQLiteException::class)
override suspend fun getListOfInactivePairingsWithoutRequestReceived(): List<Pairing> = pairingQueries.getListOfInactivePairingsWithoutRequestReceived(mapper = this::toPairing).awaitAsList()

@Throws(SQLiteException::class)
override fun activatePairing(topic: Topic) = pairingQueries.activatePairing(expiry = activePairing, is_active = true, topic = topic.value)
override suspend fun getListOfPairingsWithoutRequestReceived(): List<Pairing> = pairingQueries.getListOfPairingsWithoutRequestReceived(mapper = this::toPairing).awaitAsList()

@Throws(SQLiteException::class)
override fun setRequestReceived(topic: Topic) {
Expand All @@ -69,7 +59,6 @@ class PairingStorageRepository(private val pairingQueries: PairingQueries) : Pai
relay_data: String?,
uri: String,
methods: String,
is_active: Boolean,
is_proposal_received: Boolean?,
peerName: String?,
peerDesc: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ interface PairingStorageRepositoryInterface {

suspend fun getListOfPairings(): List<Pairing>

suspend fun getListOfInactivePairings(): List<Pairing>

suspend fun getListOfActivePairings(): List<Pairing>

suspend fun getListOfInactivePairingsWithoutRequestReceived(): List<Pairing>

fun activatePairing(topic: Topic)
suspend fun getListOfPairingsWithoutRequestReceived(): List<Pairing>

fun setRequestReceived(topic: Topic)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ interface PairingInterface {
onError: (Core.Model.Error) -> Unit = {},
)

@Deprecated(
message = "Disconnect method has been replaced",
replaceWith = ReplaceWith(expression = "disconnect(disconnect: Core.Params.Disconnect, onError: (Core.Model.Error) -> Unit = {})")
)
@Deprecated(message = "Disconnect method has been deprecated. It will be removed soon. Pairing will disconnect automatically internally.")
fun disconnect(topic: String, onError: (Core.Model.Error) -> Unit = {})

@Deprecated(message = "Disconnect method has been deprecated. It will be removed soon. Pairing will disconnect automatically internally.")
fun disconnect(disconnect: Core.Params.Disconnect, onError: (Core.Model.Error) -> Unit = {})

@Deprecated(message = "Ping method has been deprecated. It will be removed soon. Please use Ping from Web3Wallet or Sing clients.")
fun ping(ping: Core.Params.Ping, pairingPing: Core.Listeners.PairingPing? = null)

/**
Expand All @@ -43,8 +42,10 @@ interface PairingInterface {
fun validatePairingUri(uri: String): Boolean

interface Delegate {
fun onPairingDelete(deletedPairing: Core.Model.DeletedPairing)
@Deprecated(message = "onPairingDelete callback has been deprecated. It will be removed soon. Pairing will disconnect automatically internally.")
fun onPairingDelete(deletedPairing: Core.Model.DeletedPairing) {}

@Deprecated(message = "onPairingExpired callback has been deprecated. It will be removed soon. Pairing will disconnect automatically internally.")
fun onPairingExpired(expiredPairing: Core.Model.ExpiredPairing) {}

fun onPairingState(pairingState: Core.Model.PairingState) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ internal class PairingProtocol(private val koinApp: KoinApplication = wcKoinApp)
}
}

@Deprecated(message = "Disconnect method has been deprecated. It will be removed soon. Pairing will disconnect automatically internally.")
@Throws(IllegalStateException::class)
override fun disconnect(disconnect: Core.Params.Disconnect, onError: (Core.Model.Error) -> Unit) {
checkEngineInitialization()
Expand All @@ -107,6 +108,7 @@ internal class PairingProtocol(private val koinApp: KoinApplication = wcKoinApp)
}
}

@Deprecated(message = "Disconnect method has been deprecated. It will be removed soon. Pairing will disconnect automatically internally.")
@Throws(IllegalStateException::class)
override fun disconnect(topic: String, onError: (Core.Model.Error) -> Unit) {
checkEngineInitialization()
Expand All @@ -118,6 +120,7 @@ internal class PairingProtocol(private val koinApp: KoinApplication = wcKoinApp)
}
}

@Deprecated(message = "Ping method has been deprecated. It will be removed soon. Please use Ping from Web3Wallet or Sing clients.")
@Throws(IllegalStateException::class)
override fun ping(ping: Core.Params.Ping, pairingPing: Core.Listeners.PairingPing?) {
checkEngineInitialization()
Expand Down
Loading
Loading