Skip to content

Commit 9c2296b

Browse files
committed
Update block timestamp for estimating block height. Check purchases in PurchaseActivity. v0.1.9
1 parent 60ae9d3 commit 9c2296b

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ android {
1414
applicationId "com.vandyke.sia"
1515
minSdkVersion 21
1616
targetSdkVersion 27
17-
versionCode 108
18-
versionName "0.1.8"
17+
versionCode 109
18+
versionName "0.1.9"
1919
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
2020
/* lets us not shrink debug builds, for faster build times. Not necessary for release builds, since we shrink those */
2121
multiDexEnabled true

app/src/main/java/com/vandyke/sia/data/models/wallet/WalletData.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import android.arch.persistence.room.Entity
88
import android.arch.persistence.room.PrimaryKey
99
import com.fasterxml.jackson.annotation.JsonCreator
1010
import com.fasterxml.jackson.annotation.JsonIgnore
11+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
1112
import com.fasterxml.jackson.annotation.JsonProperty
1213
import java.math.BigDecimal
1314

1415
@Entity(tableName = "wallet")
16+
@JsonIgnoreProperties(ignoreUnknown = true)
1517
data class WalletData @JsonCreator constructor(
1618
@JsonProperty(value = "encrypted")
1719
val encrypted: Boolean = false,

app/src/main/java/com/vandyke/sia/ui/main/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class MainActivity : AppCompatActivity() {
7676
val purchased = client.queryPurchases(BillingClient.SkuType.SUBS)
7777
.purchasesList
7878
.find { it.sku == PurchaseActivity.overall_sub_sku } != null
79+
client.endConnection()
7980
Prefs.cachedPurchased = purchased
8081
if (!purchased) {
8182
finish()

app/src/main/java/com/vandyke/sia/ui/onboarding/PurchaseActivity.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ class PurchaseActivity : AppCompatActivity(), PurchasesUpdatedListener {
2727
client = BillingClient.newBuilder(this).setListener(this).build()
2828
client.startConnection(object : BillingClientStateListener {
2929
override fun onBillingSetupFinished(responseCode: Int) {
30-
if (pending)
30+
val purchased = client.queryPurchases(BillingClient.SkuType.SUBS)
31+
.purchasesList
32+
.find { it.sku == overall_sub_sku } != null
33+
Prefs.cachedPurchased = purchased
34+
if (purchased) {
35+
goToMainActivity()
36+
} else if (pending) {
3137
launchSubscriptionPurchase()
38+
}
3239
}
3340

3441
override fun onBillingServiceDisconnected() {
@@ -50,8 +57,7 @@ class PurchaseActivity : AppCompatActivity(), PurchasesUpdatedListener {
5057
|| purchases?.find { it.sku == overall_sub_sku } != null
5158
|| client.queryPurchases(BillingClient.SkuType.SUBS).purchasesList.find { it.sku == overall_sub_sku } != null) {
5259
Prefs.cachedPurchased = true
53-
finish()
54-
startActivity(Intent(this, MainActivity::class.java))
60+
goToMainActivity()
5561
}
5662
}
5763

@@ -72,6 +78,11 @@ class PurchaseActivity : AppCompatActivity(), PurchasesUpdatedListener {
7278
}
7379
}
7480

81+
private fun goToMainActivity() {
82+
finish()
83+
startActivity(Intent(this, MainActivity::class.java))
84+
}
85+
7586
override fun onDestroy() {
7687
super.onDestroy()
7788
client.endConnection()

app/src/main/java/com/vandyke/sia/util/SCUtil.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import java.text.NumberFormat
1010

1111
val HASTINGS_PER_SC = BigDecimal("1000000000000000000000000")
1212

13-
val BLOCK_100k_TIMESTAMP = 1492126789
13+
const val BLOCK_139949_TIMESTAMP = 1517519551
1414

1515
val UNCONFIRMED_TX_TIMESTAMP = BigDecimal("18446744073709551615")
1616

@@ -33,14 +33,14 @@ fun BigDecimal.format(): String {
3333
object SCUtil {
3434
fun estimatedBlockHeightAt(time: Long): Long {
3535
val blockTime = 9 // overestimate
36-
val diff = time - BLOCK_100k_TIMESTAMP
37-
return (100000 + diff / 60 / blockTime.toLong())
36+
val diff = time - BLOCK_139949_TIMESTAMP
37+
return (139949 + diff / 60 / blockTime.toLong())
3838
}
3939

4040
fun estimatedTimeAtBlock(height: Long): Long {
4141
val blockTime = 10
4242
val heightDiff = height - 100000
4343
val timeDiff = heightDiff * blockTime
44-
return (BLOCK_100k_TIMESTAMP + timeDiff * 60)
44+
return (BLOCK_139949_TIMESTAMP + timeDiff * 60)
4545
}
4646
}

0 commit comments

Comments
 (0)