Skip to content

Commit

Permalink
Ledger/linter (#425)
Browse files Browse the repository at this point in the history
* Update linter

* Run linter

* Code style

* Ignore connection tests for now
  • Loading branch information
valentunn authored Sep 7, 2022
1 parent e2632e9 commit cb74c5f
Show file tree
Hide file tree
Showing 64 changed files with 165 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ root = true
max_line_length = 160
insert_final_newline = true
indent_size = 4
disabled_rules = import-ordering
ktlint_disabled_rules = import-ordering, package-name, trailing-comma-on-call-site, trailing-comma-on-declaration-site, filename
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class RootActivity : BaseActivity<RootViewModel>(), SplashBackgroundHolder {

@Inject
lateinit var navigationHolder: NavigationHolder

@Inject
lateinit var systemCallExecutor: SystemCallExecutor

Expand Down
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ buildscript {

kotlinVersion = '1.7.10'

ktlintPinterestVersion = '0.40.0'
ktlintPinterestVersion = '0.47.0'

recyclerVersion = "1.2.1"
supportVersion = '1.1.0'
Expand Down Expand Up @@ -205,7 +205,11 @@ task clean(type: Delete) {
}

dependencies {
ktlint "com.pinterest:ktlint:$ktlintPinterestVersion"
ktlint ("com.pinterest:ktlint:$ktlintPinterestVersion") {
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
}
}
}

task ktlint(type: JavaExec, group: "verification") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import kotlinx.coroutines.withContext
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException

@Suppress("EXPERIMENTAL_API_USAGE") class SocketSingleRequestExecutor(
@Suppress("EXPERIMENTAL_API_USAGE")
class SocketSingleRequestExecutor(
private val jsonMapper: Gson,
private val logger: Logger,
private val wsFactory: WebSocketFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ typealias BinderWithType<T> = (scale: String?, RuntimeSnapshot, Type<*>) -> T

@OptIn(ExperimentalContracts::class)
inline fun <reified T> requireType(dynamicInstance: Any?): T {

contract {
returns() implies (dynamicInstance is T)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@ class EncryptionUtil @Inject constructor(
private fun decrypt(key: ByteArray, encrypted: ByteArray): ByteArray {
val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
cipher.init(
Cipher.DECRYPT_MODE, SecretKeySpec(key, "AES"),
IvParameterSpec(Arrays.copyOfRange(encrypted, 0, BLOCK_SIZE)), secureRandom
Cipher.DECRYPT_MODE,
SecretKeySpec(key, "AES"),
IvParameterSpec(Arrays.copyOfRange(encrypted, 0, BLOCK_SIZE)),
secureRandom
)
return cipher.doFinal(Arrays.copyOfRange(encrypted, BLOCK_SIZE, encrypted.size))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import dagger.MapKey
import kotlin.reflect.KClass

@Target(
AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.FUNCTION,
AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER
)
@MapKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class NetworkStateProvider : NetworkStateMixin {
attempts != null && attempts > ATTEMPT_THRESHOLD
}
.distinctUntilChanged()
.asLiveData()*/ MutableLiveData(false)
.asLiveData()*/ MutableLiveData(
false
)

private fun stateAsAttempting(state: State): Int? {
return when (state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ fun <T> firstNonEmptyLoading(
.map { loadingStates ->
val isAllLoaded = loadingStates.all { it is LoadingState.Loaded }
val states: List<List<T>> = loadingStates.mapNotNull {
if (it is LoadingState.Loaded && it.data.isNotEmpty())
if (it is LoadingState.Loaded && it.data.isNotEmpty()) {
it.data
else null
} else {
null
}
}

if (isAllLoaded || states.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ object CollectionDiffer {
oldItems: List<T>,
forceUseNewItems: Boolean
): Diff<T> {

val newKeys: Set<String> = newItems.mapTo(mutableSetOf()) { it.identifier }
val oldMapping = oldItems.associateBy { it.identifier }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ fun Lifecycle.onDestroy(action: () -> Unit) {
})
}


fun Lifecycle.whenStarted(action: () -> Unit) {
if (currentState.isAtLeast(Lifecycle.State.STARTED)) {
action()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ fun <FIRST, SECOND, RESULT> LiveData<FIRST>.combine(
initial: RESULT? = null,
zipper: (FIRST, SECOND) -> RESULT
): LiveData<RESULT> {

return MediatorLiveData<RESULT>().apply {
addSource(this@combine) { first ->
val second = another.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class SpannableBuilder(val content: String) {
@ColorInt color: Int? = null,
onClick: () -> Unit
) {

val startIndex = content.indexOf(text)

if (startIndex == -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ class LockBottomSheetBehavior<V : View> @JvmOverloads constructor(
axes: Int,
type: Int
): Boolean {
return if (isDraggable) super.onStartNestedScroll(
coordinatorLayout,
child,
directTargetChild,
target,
axes,
type
) else false
return if (isDraggable) {
super.onStartNestedScroll(
coordinatorLayout,
child,
directTargetChild,
target,
axes,
type
)
} else {
false
}
}

override fun onNestedPreFling(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ fun Context.addRipple(
mask: Drawable? = null,
@ColorInt rippleColor: Int = getColor(R.color.colorSelected)
): Drawable {

return RippleDrawable(rippleColor.toColorStateList(), drawable, mask)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,16 @@ import io.novafoundation.nova.core_db.model.chain.MetaAccountLocal
AccountStakingLocal::class,
TotalRewardLocal::class,
OperationLocal::class,

ChainLocal::class,
ChainNodeLocal::class,
ChainAssetLocal::class,
ChainRuntimeInfoLocal::class,
ChainExplorerLocal::class,
MetaAccountLocal::class,
ChainAccountLocal::class,

DappAuthorizationLocal::class,
NftLocal::class,

PhishingSiteLocal::class,

FavouriteDAppLocal::class,
CurrencyLocal::class
],
Expand All @@ -112,7 +108,6 @@ import io.novafoundation.nova.core_db.model.chain.MetaAccountLocal
MetaAccountTypeConverters::class,
CurrencyConverters::class
)

abstract class AppDatabase : RoomDatabase() {

companion object {
Expand All @@ -126,7 +121,8 @@ abstract class AppDatabase : RoomDatabase() {
if (instance == null) {
instance = Room.databaseBuilder(
context.applicationContext,
AppDatabase::class.java, "app.db"
AppDatabase::class.java,
"app.db"
)
.addMigrations(AddDAppAuthorizations_1_2, AssetTypes_2_3, ChangeAsset_3_4)
.addMigrations(AddChainColor_4_5, AddNfts_5_6, AddSitePhishing_6_7, AddBuyProviders_7_8, BetterChainDiffing_8_9)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,40 @@ abstract class ChainDao {
// ------ Delete --------
@Delete
protected abstract suspend fun deleteChains(chains: List<ChainLocal>)

@Delete
protected abstract suspend fun deleteChainNodes(nodes: List<ChainNodeLocal>)

@Delete
protected abstract suspend fun deleteChainAssets(assets: List<ChainAssetLocal>)

@Delete
protected abstract suspend fun deleteChainExplorers(explorers: List<ChainExplorerLocal>)

// ------ Add --------
@Insert(onConflict = OnConflictStrategy.ABORT)
protected abstract suspend fun addChains(chains: List<ChainLocal>)

@Insert(onConflict = OnConflictStrategy.ABORT)
protected abstract suspend fun addChainNodes(nodes: List<ChainNodeLocal>)

@Insert(onConflict = OnConflictStrategy.ABORT)
protected abstract suspend fun addChainAssets(assets: List<ChainAssetLocal>)

@Insert(onConflict = OnConflictStrategy.ABORT)
protected abstract suspend fun addChainExplorers(explorers: List<ChainExplorerLocal>)

// ------ Update -----

@Update
protected abstract suspend fun updateChains(chains: List<ChainLocal>)

@Update
protected abstract suspend fun updateChainNodes(nodes: List<ChainNodeLocal>)

@Update
protected abstract suspend fun updateChainAssets(assets: List<ChainAssetLocal>)

@Update
protected abstract suspend fun updateChainExplorers(explorers: List<ChainExplorerLocal>)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ data class NodeLocal(
val isDefault: Boolean,
val isActive: Boolean = false
) {
@PrimaryKey(autoGenerate = true) var id: Int = 0
@PrimaryKey(autoGenerate = true)
var id: Int = 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class AccountsAdapter(
require(holder is AccountHolder)

resolvePayload(
holder, position, payloads,
holder,
position,
payloads,
onUnknownPayload = { holder.bindMode(mode, child, accountItemHandler) },
onDiffCheck = {
when (it) {
Expand Down Expand Up @@ -182,7 +184,9 @@ class AccountHolder(view: View) : GroupedListHolder(view) {
}

private object MetaAccountPayloadGenerator : PayloadGenerator<AccountUi>(
AccountUi::title, AccountUi::subtitle, AccountUi::isSelected
AccountUi::title,
AccountUi::subtitle,
AccountUi::isSelected
)

private class DiffCallback : BaseGroupedDiffCallback<ChipLabelModel, AccountUi>(ChipLabelModel::class.java) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ fun mapCryptoTypeToCryptoTypeModel(
resourceManager: ResourceManager,
encryptionType: CryptoType
): CryptoTypeModel {

val name = when (encryptionType) {
CryptoType.SR25519 -> "${resourceManager.getString(R.string.sr25519_selection_title)} ${
resourceManager.getString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class AddAccountRepository(
advancedEncryption: AdvancedEncryption,
addAccountType: AddAccountType
): Long = withContext(Dispatchers.Default) {

addAccount(
derivationPaths = advancedEncryption.derivationPaths,
addAccountType = addAccountType,
Expand All @@ -59,7 +58,6 @@ class AddAccountRepository(
password: String,
addAccountType: AddAccountType
): Long = withContext(Dispatchers.Default) {

addAccount(
derivationPaths = AdvancedEncryption.DerivationPaths.empty(),
addAccountType = addAccountType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ fun mapAdvancedEncryptionValidationFailureToUi(
resourceManager: ResourceManager,
failure: AdvancedEncryptionValidationFailure,
): TitleAndMessage {

return when (failure) {
SUBSTRATE_DERIVATION_PATH -> resourceManager.getString(R.string.account_derivation_path_substrate_invalid_title) to
resourceManager.getString(R.string.account_invalid_derivation_path_message_v2_2_0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fun mapExportJsonPasswordValidationFailureToUi(
resourceManager: ResourceManager,
failure: ExportJsonPasswordValidationFailure,
): TitleAndMessage {

return when (failure) {
ExportJsonPasswordValidationFailure.PASSWORDS_DO_NOT_MATCH -> resourceManager.getString(R.string.common_error_general_title) to
resourceManager.getString(R.string.export_json_password_match_error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class AdvancedEncryptionFragment : BaseFragment<AdvancedEncryptionViewModel>() {
private const val PAYLOAD = "CreateAccountFragment.payload"

fun getBundle(payload: AdvancedEncryptionPayload): Bundle {

return Bundle().apply {
putParcelable(PAYLOAD, payload)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class AcknowledgeSigningNotSupportedBottomSheet(
private val payload: SigningNotSupportedPresentable.Payload,
private val onConfirm: () -> Unit
) : ActionNotAllowedBottomSheet(
context = context,
onSuccess = onConfirm,
),
context = context,
onSuccess = onConfirm,
),
DialogExtensions {

override val dialogInterface: DialogInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class ImportAccountFragment : BaseFragment<ImportAccountViewModel>() {
private const val PAYLOAD = "ImportAccountFragment.PAYLOAD"

fun getBundle(payload: ImportAccountPayload): Bundle {

return Bundle().apply {
putParcelable(PAYLOAD, payload)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class ConfirmMnemonicFragment : BaseFragment<ConfirmMnemonicViewModel>() {
private const val KEY_PAYLOAD = "confirm_payload"

fun getBundle(payload: ConfirmMnemonicPayload): Bundle {

return Bundle().apply {
putParcelable(KEY_PAYLOAD, payload)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ suspend fun mapOperationToOperationModel(
}

is Operation.Type.Extrinsic -> {

val amountColor = if (operationType.status == Operation.Status.FAILED) R.color.gray2 else R.color.white

OperationModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class AssetsFeatureModule {
rampProvider: RampProvider,
transakProvider: TransakProvider
): BuyTokenRegistry {

return BuyTokenRegistry(
providers = listOf(
rampProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,7 @@ private object DiffCallback : BaseGroupedDiffCallback<AssetGroupUi, AssetModel>(
}

private object AssetPayloadGenerator : PayloadGenerator<AssetModel>(
priceRateExtractor, recentChangeExtractor, AssetModel::total
priceRateExtractor,
recentChangeExtractor,
AssetModel::total
)
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class BalanceListModule {
addressIconGenerator: AddressIconGenerator,
currencyInteractor: CurrencyInteractor
): ViewModel {

return BalanceListViewModel(
interactor,
assetsListInteractor,
Expand Down
Loading

0 comments on commit cb74c5f

Please sign in to comment.