Skip to content

Commit 8aa4b08

Browse files
committed
Added an overloaded connectWallet method that supports the new ActivityResult API.(#17)
1 parent 6d08b16 commit 8aa4b08

9 files changed

Lines changed: 52 additions & 16 deletions

File tree

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Add the following code to the `build.gradle.kts` file in the `app` module:
1818
dependencies {
1919
// The extension package must be used with the main framework "dora"
2020
implementation("com.github.dora4:dora:1.3.43")
21-
implementation("com.github.dora4:dora-walletconnect-support:2.1.30")
21+
implementation("com.github.dora4:dora-walletconnect-support:2.1.31")
2222
}
2323
```
2424

docs/es/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Añade el siguiente código en el archivo `build.gradle.kts` del módulo `app`:
1818
dependencies {
1919
// El paquete de extensión debe usarse con el framework principal "dora"
2020
implementation("com.github.dora4:dora:1.3.43")
21-
implementation("com.github.dora4:dora-walletconnect-support:2.1.30")
21+
implementation("com.github.dora4:dora-walletconnect-support:2.1.31")
2222
}
2323
```
2424

docs/fr/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Ajoutez le code suivant dans le fichier `build.gradle.kts` du module `app` :
1818
dependencies {
1919
// Le package d'extension doit être utilisé avec le framework principal "dora"
2020
implementation("com.github.dora4:dora:1.3.43")
21-
implementation("com.github.dora4:dora-walletconnect-support:2.1.30")
21+
implementation("com.github.dora4:dora-walletconnect-support:2.1.31")
2222
}
2323
```
2424

docs/ko/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencyResolutionManagement {
1818
dependencies {
1919
// 확장 패키지는 메인 프레임워크 "dora"와 함께 사용해야 합니다.
2020
implementation("com.github.dora4:dora:1.3.43")
21-
implementation("com.github.dora4:dora-walletconnect-support:2.1.30")
21+
implementation("com.github.dora4:dora-walletconnect-support:2.1.31")
2222
}
2323
```
2424

docs/zh-cn/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencyResolutionManagement {
1818
dependencies {
1919
// 扩展包必须在有主框架dora的情况下使用
2020
implementation("com.github.dora4:dora:1.3.43")
21-
implementation("com.github.dora4:dora-walletconnect-support:2.1.30")
21+
implementation("com.github.dora4:dora-walletconnect-support:2.1.31")
2222
}
2323
```
2424

docs/zh-tw/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencyResolutionManagement {
1818
dependencies {
1919
// 擴展包必須與主框架 "dora" 一起使用
2020
implementation("com.github.dora4:dora:1.3.43")
21-
implementation("com.github.dora4:dora-walletconnect-support:2.1.30")
21+
implementation("com.github.dora4:dora-walletconnect-support:2.1.31")
2222
}
2323
```
2424

lib/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ android {
5959
}
6060

6161
dependencies {
62-
implementation("com.github.dora4:dora:1.3.39")
63-
api("com.github.dora4:dview-alert-dialog:1.25")
62+
implementation("com.github.dora4:dora:1.3.43")
63+
api("com.github.dora4:dview-alert-dialog:1.28")
6464
// wallet connect
6565
api(platform("com.walletconnect:android-bom:1.31.4"))
6666
api("com.walletconnect:android-core")
@@ -75,7 +75,7 @@ afterEvaluate {
7575
from(components["release"])
7676
groupId = "com.github.dora4"
7777
artifactId = "dora-walletconnect-support"
78-
version = "2.1.30"
78+
version = "2.1.31"
7979
}
8080
}
8181
}

lib/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected void onPause() {
6262
}
6363

6464
private void showDisconnectDialog() {
65-
DoraAlertDialog dialog = new DoraAlertDialog(this);
65+
DoraAlertDialog dialog = DoraAlertDialog.create(this);
6666
dialog.title(getString(R.string.warm_prompt));
6767
dialog.message(getString(R.string.cancel_connection_query));
6868
dialog.themeColor(DoraFund.INSTANCE.getThemeColor());

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

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,22 +280,36 @@ object DoraFund {
280280

281281
/**
282282
* Connect to a cold wallet.
283+
* Launches the wallet connection screen from a given context without expecting a result.
284+
*
285+
* @param context The context used to start the wallet connection activity.
283286
* @since 2.0
284287
*/
285288
fun connectWallet(context: Context) {
286289
IntentUtils.startActivity(context, WalletConnectActivity::class.java)
287290
}
288291

289292
/**
290-
* Connect to a cold wallet and pay immediately after connection.
293+
* Connect to a cold wallet and perform a payment immediately after the connection succeeds.
294+
* This method starts the wallet connection activity for a result,
295+
* allowing the caller to handle the connection or payment outcome in onActivityResult.
296+
*
297+
* @param activity The activity used to start the wallet connection.
298+
* @param requestCode The request code used to identify the result in onActivityResult.
291299
* @since 2.0
292300
*/
293301
fun connectWallet(activity: Activity, requestCode: Int) {
294302
IntentUtils.startActivityForResult(activity, WalletConnectActivity::class.java, requestCode)
295303
}
296304

297305
/**
298-
* Connect to a cold wallet from a Fragment.
306+
* Connect to a cold wallet from a Fragment using the new Activity Result API.
307+
* This method registers a launcher for the WalletContract and launches it immediately.
308+
*
309+
* @param fragment The Fragment from which the wallet connection is initiated.
310+
* @param onResult Optional callback invoked when the wallet connection finishes.
311+
* The WalletResult contains information about the connection status,
312+
* or null if the operation was canceled or failed.
299313
* @since 2.1
300314
*/
301315
@JvmOverloads
@@ -307,6 +321,28 @@ object DoraFund {
307321
connectWalletLauncher.launch(Unit)
308322
}
309323

324+
/**
325+
* Ensures that a wallet is connected before performing an action.
326+
* If a wallet is already connected, it immediately invokes the callback with null.
327+
* Otherwise, it initiates the wallet connection process.
328+
*
329+
* @param fragment The Fragment from which the wallet connection is initiated.
330+
* @param onResult Callback invoked after the connection attempt.
331+
* If the wallet is already connected, the result will be null.
332+
* @since 2.1
333+
*/
334+
fun ensureConnectWallet(fragment: Fragment, onResult: (WalletResult) -> Unit) {
335+
if (isWalletConnected()) {
336+
onResult.invoke(WalletResult(getCurrentChain()?.id ?: "",
337+
getCurrentChain()?.chainName ?: "", getCurrentAddress()))
338+
} else {
339+
connectWallet(fragment = fragment) {
340+
onResult(WalletResult(it?.chainId ?: "", it?.chainName ?: "",
341+
it?.address ?: ""))
342+
}
343+
}
344+
}
345+
310346
/**
311347
* Disconnect from cold wallet.
312348
* @since 2.0
@@ -722,7 +758,7 @@ object DoraFund {
722758
orderListener: OrderListener
723759
) {
724760
if (payListener == null) throw PaymentException("No PayListener is set.")
725-
DoraAlertDialog(context).show(
761+
DoraAlertDialog.create(context).show(
726762
"$goodsDesc\n\n${
727763
ContextCompat.getString(
728764
context,
@@ -778,7 +814,7 @@ object DoraFund {
778814
orderListener: OrderListener
779815
) {
780816
if (payListener == null) throw PaymentException("No PayListener is set.")
781-
DoraAlertDialog(context).show(
817+
DoraAlertDialog.create(context).show(
782818
"$goodsDesc\n\n${
783819
ContextCompat.getString(
784820
context,
@@ -843,7 +879,7 @@ object DoraFund {
843879
orderListener: OrderListener
844880
) {
845881
if (payListener == null) throw PaymentException("No PayListener is set.")
846-
DoraAlertDialog(context).show(
882+
DoraAlertDialog.create(context).show(
847883
"$goodsDesc\n\n${
848884
ContextCompat.getString(
849885
context,
@@ -933,7 +969,7 @@ object DoraFund {
933969
}
934970

935971
if (payListener == null) throw PaymentException("No PayListener is set.")
936-
DoraAlertDialog(context).show(
972+
DoraAlertDialog.create(context).show(
937973
"$goodsDesc\n\n${
938974
ContextCompat.getString(
939975
context,

0 commit comments

Comments
 (0)