@@ -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