Skip to content

Commit 2d8b4f6

Browse files
committed
feat: inbox integration
1 parent 388d0b8 commit 2d8b4f6

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

app/src/main/java/com/flowfoundation/wallet/reactnative/bridge/NativeFRWBridge.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class NativeFRWBridge(reactContext: ReactApplicationContext) : NativeFRWBridgeSp
8181

8282
override fun closeRN(id: String?) = uiHandler.closeRN(id)
8383

84+
override fun closeRNWithNFT(id: String?) = uiHandler.closeRNWithNFT(id)
85+
8486
override fun getSignKeyIndex(): Double = accountHandler.getSignKeyIndex()
8587

8688
override fun isFreeGasEnabled(promise: Promise) = utilsHandler.isFreeGasEnabled(promise)

app/src/main/java/com/flowfoundation/wallet/reactnative/bridge/handlers/UIBridgeHandler.kt

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.facebook.react.bridge.Promise
66
import com.facebook.react.bridge.ReactApplicationContext
77
import com.flowfoundation.wallet.manager.app.chainNetWorkString
88
import com.flowfoundation.wallet.manager.flowjvm.cadenceEnableToken
9+
import com.flowfoundation.wallet.manager.flowjvm.cadenceNftEnabled
910
import com.flowfoundation.wallet.manager.transaction.TransactionState
1011
import com.flowfoundation.wallet.manager.transaction.TransactionStateManager
1112
import com.flowfoundation.wallet.network.ApiService
@@ -135,6 +136,82 @@ class UIBridgeHandler(private val reactContext: ReactApplicationContext) {
135136
}
136137
}
137138

139+
fun closeRNWithNFT(id: String?) {
140+
logd(TAG, "closeRNWithNFT() called - id: $id")
141+
try {
142+
val currentActivity = reactContext.currentActivity
143+
144+
if (currentActivity == null || currentActivity.isFinishing || currentActivity.isDestroyed) {
145+
logw(TAG, "closeRNWithNFT() - Activity is null, finishing, or destroyed - skipping")
146+
return
147+
}
148+
149+
if (!id.isNullOrBlank()) {
150+
logd(TAG, "closeRNWithNFT() - flowIdentifier provided, closing screen and triggering enable NFT collection tx: $id")
151+
// Close the activity first so the user isn't waiting on the API call
152+
currentActivity.runOnUiThread {
153+
if (!currentActivity.isFinishing && !currentActivity.isDestroyed) {
154+
currentActivity.setResult(android.app.Activity.RESULT_OK)
155+
currentActivity.finish()
156+
logd(TAG, "closeRNWithNFT() - activity finished, tx will execute in background")
157+
}
158+
}
159+
// Fetch NFT collection info and submit the Cadence tx in the background
160+
ioScope {
161+
try {
162+
val service = retrofitApi().create(ApiService::class.java)
163+
val response = service.getNFTCollections()
164+
val collection = response.data.firstOrNull { it.flowIdentifier == id }
165+
if (collection == null) {
166+
logw(TAG, "closeRNWithNFT() - NFT collection not found for flowIdentifier: $id")
167+
} else {
168+
logd(TAG, "closeRNWithNFT() - found collection: ${collection.name}, executing cadenceNftEnabled")
169+
val transactionId = cadenceNftEnabled(collection)
170+
if (transactionId.isNullOrBlank()) {
171+
loge(TAG, "closeRNWithNFT() - cadenceNftEnabled returned null/blank transactionId")
172+
} else {
173+
logd(TAG, "closeRNWithNFT() - tx submitted: $transactionId")
174+
val transactionState = TransactionState(
175+
transactionId = transactionId,
176+
time = System.currentTimeMillis(),
177+
state = TransactionStatus.PENDING.ordinal,
178+
type = TransactionState.TYPE_ENABLE_NFT,
179+
data = Gson().toJson(collection)
180+
)
181+
TransactionStateManager.newTransaction(transactionState)
182+
pushBubbleStack(transactionState)
183+
}
184+
}
185+
} catch (e: Exception) {
186+
loge(TAG, "closeRNWithNFT() - Failed to enable NFT collection: ${e.message}")
187+
e.printStackTrace()
188+
}
189+
}
190+
return
191+
}
192+
193+
// No flowIdentifier → just close the activity
194+
currentActivity.runOnUiThread {
195+
try {
196+
if (!currentActivity.isFinishing && !currentActivity.isDestroyed) {
197+
logd(TAG, "closeRNWithNFT() - Calling finish() to close React Native activity")
198+
currentActivity.setResult(android.app.Activity.RESULT_OK)
199+
currentActivity.finish()
200+
logd(TAG, "closeRNWithNFT() - finish() called successfully")
201+
} else {
202+
logw(TAG, "closeRNWithNFT() - Activity already finishing or destroyed, skipping")
203+
}
204+
} catch (e: Exception) {
205+
loge(TAG, "closeRNWithNFT() - Failed to finish activity on UI thread: ${e.message}")
206+
e.printStackTrace()
207+
}
208+
}
209+
} catch (e: Exception) {
210+
loge(TAG, "closeRNWithNFT() - Failed to close React Native activity: ${e.message}")
211+
e.printStackTrace()
212+
}
213+
}
214+
138215
fun showToast(title: String, message: String?, type: String?, duration: Double?) {
139216
try {
140217
// Concatenate title and message

0 commit comments

Comments
 (0)