-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8448e0
commit f358f57
Showing
62 changed files
with
1,245 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/client/DeleteMe.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package com.tonapps.tonkeeper.client |
26 changes: 26 additions & 0 deletions
26
...llet/instance/app/src/main/java/com/tonapps/tonkeeper/client/safemode/BadDomainsEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.tonapps.tonkeeper.client.safemode | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
data class BadDomainsEntity( | ||
val array: Array<String> | ||
): Parcelable { | ||
|
||
val isEmpty: Boolean | ||
get() = array.isEmpty() | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (javaClass != other?.javaClass) return false | ||
|
||
other as BadDomainsEntity | ||
|
||
return array.contentEquals(other.array) | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return array.contentHashCode() | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...wallet/instance/app/src/main/java/com/tonapps/tonkeeper/client/safemode/SafeModeClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.tonapps.tonkeeper.client.safemode | ||
|
||
import android.content.Context | ||
import android.net.Uri | ||
import android.util.Log | ||
import com.tonapps.icu.Coins | ||
import com.tonapps.wallet.api.API | ||
import com.tonapps.wallet.data.core.BlobDataSource | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.distinctUntilChanged | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
import kotlinx.coroutines.launch | ||
import java.util.concurrent.ConcurrentHashMap | ||
|
||
class SafeModeClient( | ||
private val context: Context, | ||
private val api: API, | ||
private val scope: CoroutineScope | ||
) { | ||
|
||
private val scamDomains = ConcurrentHashMap<String, Boolean>(3, 1.0f, 2) | ||
private val blobCache = BlobDataSource.simple<BadDomainsEntity>(context, "safemode") | ||
private val badDomainsFlow = flow { | ||
getCachedBadDomains()?.let { | ||
emit(it) | ||
} | ||
|
||
loadBadDomains()?.let { | ||
emit(it) | ||
} | ||
}.distinctUntilChanged() | ||
|
||
init { | ||
badDomainsFlow.onEach { | ||
for (domain in it.array) { | ||
scamDomains[domain] = true | ||
} | ||
}.launchIn(scope) | ||
} | ||
|
||
fun isHasScamUris(vararg uris: Uri): Boolean { | ||
for (uri in uris) { | ||
if (uri == Uri.EMPTY) { | ||
continue | ||
} | ||
var host = uri.host ?: continue | ||
if (host.startsWith("www.")) { | ||
host = host.substring(4) | ||
} | ||
if (scamDomains.containsKey(host)) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
private fun getCachedBadDomains(): BadDomainsEntity? { | ||
val entity = blobCache.getCache("scam_domains") | ||
if (entity == null || entity.isEmpty) { | ||
return null | ||
} | ||
return entity | ||
} | ||
|
||
private suspend fun loadBadDomains(): BadDomainsEntity? { | ||
val domains = api.getScamDomains() | ||
if (domains.isEmpty()) { | ||
return null | ||
} | ||
val entity = BadDomainsEntity(domains) | ||
blobCache.setCache("scam_domains", entity) | ||
return entity | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.