Skip to content

Commit

Permalink
Add expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang committed Mar 28, 2024
1 parent 6cf69ca commit c11d124
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ dependencies {
implementation platform('org.jetbrains.kotlin:kotlin-bom:1.8.0')
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.7.0'
implementation 'androidx.activity:activity-compose:1.8.2'
implementation platform('androidx.compose:compose-bom:2022.10.00')
implementation platform('androidx.compose:compose-bom:2024.03.00')
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
Expand All @@ -60,7 +60,7 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
androidTestImplementation platform('androidx.compose:compose-bom:2024.03.00')
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
debugImplementation 'androidx.compose.ui:ui-tooling'
debugImplementation 'androidx.compose.ui:ui-test-manifest'
Expand Down
1 change: 0 additions & 1 deletion cartera/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ android {
configurations {
all {
exclude group: 'org.bouncycastle', module: 'bcprov-jdk15to18'
exclude group: 'org.bouncycastle', module: 'bcprov-jdk15on'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class WalletConnectV2Provider(

private var currentPairing: Core.Model.Pairing? = null

// expiry must be between current timestamp + MIN_INTERVAL and current timestamp + MAX_INTERVAL (MIN_INTERVAL: 300, MAX_INTERVAL: 604800)
private val requestExpiry: Long
get() = (System.currentTimeMillis() / 1000) + 400

private val dappDelegate = object : SignClient.DappDelegate {
override fun onSessionApproved(approvedSession: Sign.Model.ApprovedSession) {
// Triggered when Dapp receives the session approval from wallet
Expand Down Expand Up @@ -315,14 +319,15 @@ class WalletConnectV2Provider(
val namespace = currentSession?.namespace()
val chainId = currentSession?.chainId()
return if (sessionTopic != null && account != null && namespace != null && chainId != null) {
return Sign.Params.Request(
Sign.Params.Request(
sessionTopic = sessionTopic,
method = "personal_sign",
params = "[\"${message}\", \"${account}\"]",
chainId = "$namespace:$chainId",
expiry = requestExpiry,
)
} else {
return null
null
}
}

Expand All @@ -348,6 +353,7 @@ class WalletConnectV2Provider(
method = "eth_signTypedData",
params = "[\"${account}\", \"${message}\"]",
chainId = "$namespace:$chainId",
expiry = requestExpiry,
)
} else {
null
Expand All @@ -374,6 +380,7 @@ class WalletConnectV2Provider(
method = "eth_sendTransaction",
params = "[$message]",
chainId = "$namespace:$chainId",
expiry = requestExpiry,
)
} else {
null
Expand Down Expand Up @@ -471,13 +478,19 @@ class WalletConnectV2Provider(
val params = requestParams()
if (params != null) {
reallyMakeRequest(request, params) { result, error ->
completion(result, error)
CoroutineScope(Dispatchers.Main).launch {
completion(result, error)
}
}
} else {
completion(null, WalletError(CarteraErrorCode.INVALID_SESSION))
CoroutineScope(Dispatchers.Main).launch {
completion(null, WalletError(CarteraErrorCode.INVALID_SESSION))
}
}
} else {
completion(null, WalletError(CarteraErrorCode.INVALID_SESSION))
CoroutineScope(Dispatchers.Main).launch {
completion(null, WalletError(CarteraErrorCode.INVALID_SESSION))
}
}
}
}
Expand Down

0 comments on commit c11d124

Please sign in to comment.