Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CHATWOOT_API: ${{ secrets.CHATWOOT_API }}
E2E: true
GEO: false
run: ./gradlew assembleDevDebug

- name: Rename APK
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ Simply pass `E2E=true` as environment variable and build any flavor.
E2E=true ./gradlew assembleDevRelease
```

#### Disable Geoblocking Checks

By default, geoblocking checks via API are enabled. To disable at build time, use the `GEO` environment variable:

```sh
GEO=false E2E=true ./gradlew assembleDevRelease
```

### Build for Release

**Prerequisites**
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ android {
useSupportLibrary = true
}
buildConfigField("boolean", "E2E", System.getenv("E2E")?.toBoolean()?.toString() ?: "false")
buildConfigField("boolean", "GEO", System.getenv("GEO")?.toBoolean()?.toString() ?: "true")
}

flavorDimensions += "network"
Expand Down
6 changes: 3 additions & 3 deletions app/src/androidTest/java/to/bitkit/services/BlocktankTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ class BlocktankTest {
}

@Test
fun testCreateCjitOrder() = runBlocking {
fun testCreateCjitEntry() = runBlocking {
// Test creating a CJIT order
val channelSizeSat = 100_000uL // 100k sats
val invoiceSat = 10_000uL // 10k sats for the invoice
val invoiceDescription = "Test CJIT order"
val invoiceDescription = "Test CJIT"
val nodeId = "03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad" // Example node ID
val channelExpiryWeeks = 6u
val options = CreateCjitOptions(source = "bitkit", discountCode = null)
Expand Down Expand Up @@ -122,7 +122,7 @@ class BlocktankTest {
)

// Test getting CJIT entries
val entries = service.blocktank.cjitOrders(
val entries = service.blocktank.cjitEntries(
entryIds = listOf(cjitEntry.id),
filter = null,
refresh = true
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/to/bitkit/env/Env.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import kotlin.io.path.Path
internal object Env {
val isDebug = BuildConfig.DEBUG
const val isE2eTest = BuildConfig.E2E
const val isGeoblockingEnabled = BuildConfig.GEO
val network = Network.valueOf(BuildConfig.NETWORK)
val walletSyncIntervalSecs = 10_uL // TODO review
val platform = "Android ${Build.VERSION.RELEASE} (API ${Build.VERSION.SDK_INT})"
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/to/bitkit/fcm/WakeNodeWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ class WakeNodeWorker @AssistedInject constructor(
val sats = channel.amountOnClose
self.bestAttemptContent?.title = "Received ⚡ $sats sats"

val cjitOrder = channel.let { blocktankRepo.getCjitOrder(it) }
if (cjitOrder != null) {
val cjitEntry = channel.let { blocktankRepo.getCjitEntry(it) }
if (cjitEntry != null) {
val amount = channel.amountOnClose.toLong()

// Save for UI to pick up
Expand All @@ -161,7 +161,7 @@ class WakeNodeWorker @AssistedInject constructor(
sats = amount,
)
)
activityRepo.insertActivityFromChannel(cjitOrder = cjitOrder, channel = channel)
activityRepo.insertActivityFromCjit(cjitEntry = cjitEntry, channel = channel)
}
}
} else if (self.notificationType == orderPaymentConfirmed) {
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/to/bitkit/repositories/ActivityRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -510,17 +510,17 @@ class ActivityRepo @Inject constructor(
}

/**
* Inserts a new activity
* Inserts a new activity for a fulfilled (channel ready) cjit channel order
*/
suspend fun insertActivityFromChannel(
cjitOrder: IcJitEntry?,
suspend fun insertActivityFromCjit(
cjitEntry: IcJitEntry?,
channel: ChannelDetails,
): Result<Unit> = withContext(bgDispatcher) {
runCatching {
requireNotNull(cjitOrder)
requireNotNull(cjitEntry)

val amount = channel.amountOnClose
val now = nowTimestamp().toEpochMilli().toULong()
val now = nowTimestamp().epochSecond.toULong()

return@withContext insertActivity(
Activity.Lightning(
Expand All @@ -530,7 +530,7 @@ class ActivityRepo @Inject constructor(
status = PaymentState.SUCCEEDED,
value = amount,
fee = 0U,
invoice = cjitOrder.invoice.request,
invoice = cjitEntry.invoice.request,
message = "",
timestamp = now,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The time parameter could have a less error-prone name, like timestampSeconds

preimage = null,
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/to/bitkit/repositories/BlocktankRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class BlocktankRepo @Inject constructor(
}
}

suspend fun getCjitOrder(channel: ChannelDetails): IcJitEntry? = withContext(bgDispatcher) {
suspend fun getCjitEntry(channel: ChannelDetails): IcJitEntry? = withContext(bgDispatcher) {
return@withContext _blocktankState.value.cjitEntries.firstOrNull { order ->
order.channelSizeSat == channel.channelValueSats &&
order.lspNode.pubkey == channel.counterpartyNodeId
Expand Down Expand Up @@ -131,7 +131,7 @@ class BlocktankRepo @Inject constructor(

// Sync instantly from cache
val cachedOrders = coreService.blocktank.orders(refresh = false)
val cachedCjitEntries = coreService.blocktank.cjitOrders(refresh = false)
val cachedCjitEntries = coreService.blocktank.cjitEntries(refresh = false)
_blocktankState.update { state ->
state.copy(
orders = cachedOrders,
Expand All @@ -142,7 +142,7 @@ class BlocktankRepo @Inject constructor(

// Then refresh from server
val orders = coreService.blocktank.orders(refresh = true)
val cjitEntries = coreService.blocktank.cjitOrders(refresh = true)
val cjitEntries = coreService.blocktank.cjitEntries(refresh = true)
_blocktankState.update { state ->
state.copy(
orders = orders,
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/to/bitkit/services/CoreService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ class CoreService @Inject constructor(
}
}

@Suppress("KotlinConstantConditions")
private suspend fun isGeoBlocked(): Boolean {
if (!Env.isGeoblockingEnabled) {
Logger.verbose("Geoblocking disabled via build config", context = "GeoCheck")
return false
}

return ServiceQueue.CORE.background {
runCatching {
Logger.verbose("Checking geo status…", context = "GeoCheck")
Expand Down Expand Up @@ -578,7 +584,7 @@ class BlocktankService(
}
}

suspend fun cjitOrders(
suspend fun cjitEntries(
entryIds: List<String>? = null,
filter: CJitStateEnum? = null,
refresh: Boolean = true,
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ class AppViewModel @Inject constructor(

is Event.ChannelReady -> {
val channel = lightningRepo.getChannels()?.find { it.channelId == event.channelId }
val cjitOrder = channel?.let { blocktankRepo.getCjitOrder(it) }
if (cjitOrder != null) {
val cjitEntry = channel?.let { blocktankRepo.getCjitEntry(it) }
if (cjitEntry != null) {
val amount = channel.amountOnClose.toLong()
showNewTransactionSheet(
NewTransactionSheetDetails(
Expand All @@ -232,7 +232,7 @@ class AppViewModel @Inject constructor(
),
event = event
)
activityRepo.insertActivityFromChannel(cjitOrder = cjitOrder, channel = channel)
activityRepo.insertActivityFromCjit(cjitEntry = cjitEntry, channel = channel)
} else {
toast(
type = Toast.ToastType.LIGHTNING,
Expand Down
4 changes: 2 additions & 2 deletions app/src/test/java/to/bitkit/repositories/BlocktankRepoTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class BlocktankRepoTest : BaseUnitTest() {
wheneverBlocking { coreService.blocktank.orders(refresh = false) }.thenReturn(emptyList())
wheneverBlocking { coreService.blocktank.orders(refresh = true) }.thenReturn(emptyList())

wheneverBlocking { coreService.blocktank.cjitOrders(refresh = false) }.thenReturn(emptyList())
wheneverBlocking { coreService.blocktank.cjitOrders(refresh = true) }.thenReturn(emptyList())
wheneverBlocking { coreService.blocktank.cjitEntries(refresh = false) }.thenReturn(emptyList())
wheneverBlocking { coreService.blocktank.cjitEntries(refresh = true) }.thenReturn(emptyList())
}

private fun createSut(): BlocktankRepo {
Expand Down