Skip to content

Commit 2090ab4

Browse files
committed
Added an overloaded connectWallet method that supports the new ActivityResult API.(#17)
1 parent 9b5d5de commit 2090ab4

File tree

13 files changed

+109
-23
lines changed

13 files changed

+109
-23
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
22
id 'com.android.library' version '8.1.0' apply false
3-
id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
3+
id 'org.jetbrains.kotlin.android' version '2.2.21' apply false
44
id 'com.github.dcendents.android-maven' version '1.5' apply false
55
}

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Add the following code to the `build.gradle.kts` file in the `app` module:
1717
```kotlin
1818
dependencies {
1919
// The extension package must be used with the main framework "dora"
20-
implementation("com.github.dora4:dora:1.3.39")
21-
implementation("com.github.dora4:dora-walletconnect-support:2.1.28")
20+
implementation("com.github.dora4:dora:1.3.43")
21+
implementation("com.github.dora4:dora-walletconnect-support:2.1.29")
2222
}
2323
```
2424

docs/es/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Añade el siguiente código en el archivo `build.gradle.kts` del módulo `app`:
1717
```kotlin
1818
dependencies {
1919
// El paquete de extensión debe usarse con el framework principal "dora"
20-
implementation("com.github.dora4:dora:1.3.39")
21-
implementation("com.github.dora4:dora-walletconnect-support:2.1.28")
20+
implementation("com.github.dora4:dora:1.3.43")
21+
implementation("com.github.dora4:dora-walletconnect-support:2.1.29")
2222
}
2323
```
2424

docs/fr/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Ajoutez le code suivant dans le fichier `build.gradle.kts` du module `app` :
1717
```kotlin
1818
dependencies {
1919
// Le package d'extension doit être utilisé avec le framework principal "dora"
20-
implementation("com.github.dora4:dora:1.3.39")
21-
implementation("com.github.dora4:dora-walletconnect-support:2.1.28")
20+
implementation("com.github.dora4:dora:1.3.43")
21+
implementation("com.github.dora4:dora-walletconnect-support:2.1.29")
2222
}
2323
```
2424

docs/ko/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ dependencyResolutionManagement {
1717
```kotlin
1818
dependencies {
1919
// 확장 패키지는 메인 프레임워크 "dora"와 함께 사용해야 합니다.
20-
implementation("com.github.dora4:dora:1.3.39")
21-
implementation("com.github.dora4:dora-walletconnect-support:2.1.28")
20+
implementation("com.github.dora4:dora:1.3.43")
21+
implementation("com.github.dora4:dora-walletconnect-support:2.1.29")
2222
}
2323
```
2424

docs/zh-cn/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ dependencyResolutionManagement {
1717
```kotlin
1818
dependencies {
1919
// 扩展包必须在有主框架dora的情况下使用
20-
implementation("com.github.dora4:dora:1.3.39")
21-
implementation("com.github.dora4:dora-walletconnect-support:2.1.28")
20+
implementation("com.github.dora4:dora:1.3.43")
21+
implementation("com.github.dora4:dora-walletconnect-support:2.1.29")
2222
}
2323
```
2424

docs/zh-tw/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ dependencyResolutionManagement {
1717
```kotlin
1818
dependencies {
1919
// 擴展包必須與主框架 "dora" 一起使用
20-
implementation("com.github.dora4:dora:1.3.39")
21-
implementation("com.github.dora4:dora-walletconnect-support:2.1.28")
20+
implementation("com.github.dora4:dora:1.3.43")
21+
implementation("com.github.dora4:dora-walletconnect-support:2.1.29")
2222
}
2323
```
2424

lib/build.gradle.kts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66

77
android {
88
namespace = "dora.lifecycle.walletconnect"
9-
compileSdk = 34
9+
compileSdk = 36
1010

1111
defaultConfig {
1212
minSdk = 24
@@ -33,9 +33,6 @@ android {
3333
buildFeatures {
3434
aidl = true
3535
}
36-
kotlinOptions {
37-
jvmTarget = "17"
38-
}
3936
compileOptions {
4037
sourceCompatibility = JavaVersion.VERSION_17
4138
targetCompatibility = JavaVersion.VERSION_17
@@ -78,7 +75,7 @@ afterEvaluate {
7875
from(components["release"])
7976
groupId = "com.github.dora4"
8077
artifactId = "dora-walletconnect-support"
81-
version = "2.1.28"
78+
version = "2.1.29"
8279
}
8380
}
8481
}

lib/src/main/java/dora/pay/DoraFund.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import android.app.Application
55
import android.app.NotificationChannel
66
import android.app.NotificationManager
77
import android.content.Context
8+
import android.content.Intent
89
import android.graphics.Color
910
import android.os.Build
1011
import android.util.Log
12+
import androidx.activity.result.contract.ActivityResultContract
1113
import androidx.annotation.ColorInt
1214
import androidx.core.app.NotificationCompat
1315
import androidx.core.content.ContextCompat
16+
import androidx.fragment.app.Fragment
1417
import com.walletconnect.android.Core
1518
import com.walletconnect.web3.modal.client.Modal
1619
import com.walletconnect.web3.modal.client.Web3Modal
@@ -19,6 +22,8 @@ import de.blinkt.openvpn.core.OpenVPNService
1922
import dora.lifecycle.walletconnect.R
2023
import dora.pay.activity.WalletConnectActivity
2124
import dora.pay.token.Token
25+
import dora.pay.wallet.WalletContract
26+
import dora.pay.wallet.WalletResult
2227
import dora.util.IntentUtils
2328
import dora.util.ToastUtils
2429
import dora.widget.DoraAlertDialog
@@ -274,21 +279,33 @@ object DoraFund {
274279
}
275280

276281
/**
277-
* Connect to cold wallet.
282+
* Connect to a cold wallet.
278283
* @since 2.0
279284
*/
280285
fun connectWallet(context: Context) {
281286
IntentUtils.startActivity(context, WalletConnectActivity::class.java)
282287
}
283288

284289
/**
285-
* Connect to cold wallet and pay immediately after connection.
290+
* Connect to a cold wallet and pay immediately after connection.
286291
* @since 2.0
287292
*/
288293
fun connectWallet(activity: Activity, requestCode: Int) {
289294
IntentUtils.startActivityForResult(activity, WalletConnectActivity::class.java, requestCode)
290295
}
291296

297+
/**
298+
* Connect to a cold wallet from a Fragment.
299+
* @since 2.1
300+
*/
301+
fun connectWallet(fragment: Fragment, onResult: (WalletResult?) -> Unit) {
302+
val connectWalletLauncher =
303+
fragment.registerForActivityResult(WalletContract()) { result ->
304+
onResult(result)
305+
}
306+
connectWalletLauncher.launch(Unit)
307+
}
308+
292309
/**
293310
* Disconnect from cold wallet.
294311
* @since 2.0

lib/src/main/java/dora/pay/activity/WalletConnectActivity.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package dora.pay.activity
22

33
import android.annotation.SuppressLint
4-
import android.app.Activity
54
import android.os.Bundle
65
import androidx.appcompat.app.AppCompatActivity
76
import com.walletconnect.web3.modal.ui.Web3ModalView
87
import dora.lifecycle.walletconnect.R
8+
import dora.pay.DoraFund
9+
import dora.pay.wallet.WalletContract
910
import dora.util.StatusBarUtils
1011

12+
/**
13+
* @since 2.0
14+
*/
1115
class WalletConnectActivity : AppCompatActivity() {
1216

1317
@SuppressLint("UnsafeIntentLaunch")
@@ -16,7 +20,14 @@ class WalletConnectActivity : AppCompatActivity() {
1620
setContentView(R.layout.activity_wallet_connect)
1721
StatusBarUtils.setTransparencyStatusBar(this)
1822
findViewById<Web3ModalView>(R.id.web3Modal).setOnCloseModal {
19-
setResult(Activity.RESULT_OK)
23+
if (DoraFund.isWalletConnected()) {
24+
intent.putExtra(WalletContract.EXTRA_CHAIN_ID, DoraFund.getCurrentChain()?.id)
25+
intent.putExtra(WalletContract.EXTRA_CHAIN_NAME, DoraFund.getCurrentChain()?.chainName)
26+
intent.putExtra(WalletContract.EXTRA_ERC20_ADDRESS, DoraFund.getCurrentAddress())
27+
setResult(RESULT_OK, intent)
28+
} else {
29+
setResult(RESULT_CANCELED)
30+
}
2031
finish()
2132
}
2233
}

0 commit comments

Comments
 (0)