Skip to content

Commit

Permalink
feat(zenledger): add entry point and export functionality to tools me…
Browse files Browse the repository at this point in the history
…nu (#1276)
  • Loading branch information
HashEngineering authored Apr 5, 2024
1 parent 158566d commit 03c6f5c
Show file tree
Hide file tree
Showing 19 changed files with 563 additions and 3 deletions.
3 changes: 3 additions & 0 deletions common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,7 @@
<string name="enter_amount_available">available</string>
<string name="transaction_row_rate_not_available">Not available</string>
<string name="log_in">Log In</string>

<string name="chain_syncing">The chain is syncing…</string>

</resources>
9 changes: 9 additions & 0 deletions wallet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ android {
buildConfigField("String", "TOPPER_KEY_ID", topperKeyId)
buildConfigField("String", "TOPPER_WIDGET_ID", topperWidgetId)
buildConfigField("String", "TOPPER_PRIVATE_KEY", topperPrivateKey)

def zenLedgerClientId = props.getProperty("ZENLEDGER_CLIENT_ID", "\"\"")
def zenLedgerClientSecret = props.getProperty("ZENLEDGER_CLIENT_SECRET", "\"\"")
buildConfigField("String", "ZENLEDGER_CLIENT_ID", zenLedgerClientId)
buildConfigField("String", "ZENLEDGER_CLIENT_SECRET", zenLedgerClientSecret)
}
_testNet3 {
applicationId = "hashengineering.darkcoin.wallet_test"
Expand All @@ -299,11 +304,15 @@ android {
buildConfigField("String", "TOPPER_KEY_ID", topperKeyId)
buildConfigField("String", "TOPPER_WIDGET_ID", topperWidgetId)
buildConfigField("String", "TOPPER_PRIVATE_KEY", topperPrivateKey)
buildConfigField("String", "ZENLEDGER_CLIENT_ID", "\"\"")
buildConfigField("String", "ZENLEDGER_CLIENT_SECRET", "\"\"")
}
devnet {
applicationId = "org.dash.wallet.devnet"
buildConfigField("String", "UPHOLD_CLIENT_ID", "\"UPHOLD_CLIENT_ID\"")
buildConfigField("String", "UPHOLD_CLIENT_SECRET", "\"UPHOLD_CLIENT_SECRET\"")
buildConfigField("String", "ZENLEDGER_CLIENT_ID", "\"\"")
buildConfigField("String", "ZENLEDGER_CLIENT_SECRET", "\"\"")
}
}

Expand Down
6 changes: 5 additions & 1 deletion wallet/proguard.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@

-keep class org.bouncycastle** { *; }
-keepnames class org.bouncycastle** { *; }
-dontwarn org.bouncycastle.**
-dontwarn org.bouncycastle.**

-keepclassmembers class * {
@com.google.gson.annotations.SerializedName <fields>;
}
Binary file added wallet/res/drawable-hdpi/ic_zenledger_dash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wallet/res/drawable-mdpi/ic_zenledger_dash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wallet/res/drawable-xhdpi/ic_zenledger_dash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wallet/res/drawable-xxhdpi/ic_zenledger_dash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wallet/res/drawable-xxxhdpi/ic_zenledger_dash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions wallet/res/drawable/ic_zenledger_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
~ Copyright (c) 2024$ Dash Core Group
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="34dp"
android:height="34dp"
android:viewportWidth="34"
android:viewportHeight="34">
<path
android:pathData="M6,12C6,8.686 8.686,6 12,6H22C25.314,6 28,8.686 28,12V22C28,25.314 25.314,28 22,28H12C8.686,28 6,25.314 6,22V12Z"
android:fillColor="#11D7A3"/>
<path
android:pathData="M21.4,12.6H11.5V11.5H22.5L21.4,12.6ZM11.5,13.48H20.52L19.42,14.58H11.5V13.48ZM11.5,15.46H18.54L17.44,16.56H11.5V15.46ZM15.46,18.54L16.56,17.44H22.5V18.54H15.46ZM14.58,19.42L13.48,20.52H22.5V19.42H14.58ZM12.6,21.4L11.5,22.5H22.5V21.4H12.6Z"
android:fillColor="#ffffff"
android:fillType="evenOdd"/>
</vector>
104 changes: 104 additions & 0 deletions wallet/res/layout/dialog_zenledger.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2024 Dash Core Group
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">

<View
android:id="@+id/drag_indicator"
android:layout_width="40dp"
android:layout_height="4dp"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:background="@drawable/rounded_background"
android:theme="@style/DragIndicatorBackground"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:background="@color/light_gray" />

<ImageButton
android:id="@+id/collapse_button"
style="@style/DialogCloseButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/zenledger_icon"
android:layout_width="95dp"
android:layout_height="95dp"
android:layout_marginVertical="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/collapse_button"
app:layout_constraintBottom_toTopOf="@id/text_container"
android:src="@drawable/ic_zenledger_dash"
/>

<LinearLayout
android:id="@+id/text_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@id/zenledger_icon"
app:layout_constraintBottom_toTopOf="@+id/export_all_transactions"
>
<TextView
style="@style/Headline5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/zenledger_export_subtitle"
android:textAlignment="center"
/>
<TextView
style="@style/Body2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/zenledger_export_description"
android:textAlignment="center"
/>
<TextView
android:id="@+id/zenledger_link"
style="@style/Caption.Blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="40dp"
android:text="@string/zenledger_export_link"
android:layout_gravity="center"
android:textAlignment="center"
android:drawablePadding="8dp"
app:drawableEndCompat="@drawable/ic_open_link"/>


</LinearLayout>

<Button
android:id="@+id/export_all_transactions"
android:layout_marginHorizontal="15dp"
android:layout_marginVertical="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Button.Primary.Blue"
android:text="@string/zenledger_export_all_tx"
app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
53 changes: 53 additions & 0 deletions wallet/res/layout/fragment_tools.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,57 @@

</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/zenledger_export"
style="@style/MenuRow.Internal">

<ImageView
android:id="@+id/zenledger_icon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:src="@drawable/ic_zenledger_icon"
/>

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toStartOf="@id/zenledger_export_arrow"
app:layout_constraintStart_toEndOf="@id/zenledger_icon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginStart="10dp"
android:orientation="vertical" >

<TextView
android:id="@+id/zenledger_export_title"
style="@style/MenuRowTitle.Internal"
android:layout_marginStart="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/zenledger_export_title"
app:layout_constraintBottom_toBottomOf="parent" />

<TextView
style="@style/Overline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/zenledger_export_subtitle"
android:textAlignment="textStart" />
</LinearLayout>


<ImageView
android:id="@+id/zenledger_export_arrow"
style="@style/MenuRowArrow"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_menu_row_arrow" />

</androidx.constraintlayout.widget.ConstraintLayout>

</LinearLayout>
12 changes: 12 additions & 0 deletions wallet/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,18 @@
<string name="report_transaction_history_mail_intent_chooser">Send transaction history using…</string>
<string name="report_transaction_history_dialog_mail_intent_failed">Sending transaction history failed.</string>

<!-- ZenLedger -->
<string name="zenledger_export_title">ZenLedger</string>
<string name="zenledger_export_subtitle">Simplify your crypto taxes</string>
<string name="zenledger_export_all_tx">Export all transactions</string>
<string name="zenledger_export_description">Connect your crypto wallets to the ZenLedger platform. Learn more and get started with your Dash Wallet transactions.</string>
<string name="zenledger_export_link" translatable="false">zenledger.io</string>
<string name="zenledger_export_url" translatable="false">https://zenledger.io</string>
<string name="chain_syncing_default_message">Wait until the chain is fully synced, so we can review your transaction history.</string>
<string name="zenledger_export_permission">Allow sending all transactions from Dash Wallet to Zenledger?</string>
<string name="zenledger_export_error">There was an error when exporting your transaction history to ZenLedger.</string>


<string name="about_title">About</string>
<string name="about_version_title">Version</string>
<string name="about_copyright_title">Copyright</string>
Expand Down
8 changes: 8 additions & 0 deletions wallet/src/de/schildbach/wallet/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import de.schildbach.wallet.service.*
import de.schildbach.wallet.service.AndroidActionsService
import de.schildbach.wallet.service.AppRestartService
import de.schildbach.wallet.service.RestartService
import de.schildbach.wallet.ui.more.tools.ZenLedgerApi
import de.schildbach.wallet.ui.more.tools.ZenLedgerClient
import de.schildbach.wallet.ui.notifications.NotificationManagerWrapper
import org.dash.wallet.common.Configuration
import org.dash.wallet.common.services.*
Expand All @@ -44,6 +46,8 @@ import org.dash.wallet.common.services.NotificationService
import org.dash.wallet.common.services.SendPaymentService
import org.dash.wallet.common.services.analytics.AnalyticsService
import org.dash.wallet.common.services.analytics.FirebaseAnalyticsServiceImpl
import org.dash.wallet.integrations.crowdnode.api.CrowdNodeApi
import org.dash.wallet.integrations.crowdnode.api.CrowdNodeApiAggregator
import org.dash.wallet.integrations.uphold.api.UpholdClient
import javax.inject.Singleton

Expand Down Expand Up @@ -122,4 +126,8 @@ abstract class AppModule {

@Binds
abstract fun bindWalletFactory(walletFactory: DashWalletFactory) : WalletFactory

@Binds
@Singleton
abstract fun bindZenLedgerClient(zenLedgerClient: ZenLedgerClient): ZenLedgerApi
}
2 changes: 0 additions & 2 deletions wallet/src/de/schildbach/wallet/ui/main/WalletActivityExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import android.os.PowerManager
import android.os.storage.StorageManager
import android.provider.Settings
import android.view.MenuItem
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
import androidx.core.view.isVisible
Expand Down
5 changes: 5 additions & 0 deletions wallet/src/de/schildbach/wallet/ui/more/ToolsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import de.schildbach.wallet.security.SecurityFunctions
import de.schildbach.wallet.ui.AddressBookActivity
import de.schildbach.wallet.ui.ExportTransactionHistoryDialogBuilder
import de.schildbach.wallet.ui.NetworkMonitorActivity
import de.schildbach.wallet.ui.more.tools.ZenLedgerDialogFragment
import de.schildbach.wallet.ui.payments.SweepWalletActivity
import de.schildbach.wallet.util.Toast
import de.schildbach.wallet_test.R
Expand Down Expand Up @@ -132,6 +133,10 @@ class ToolsFragment : Fragment(R.layout.fragment_tools) {
}
}
}

binding.zenledgerExport.setOnClickListener {
ZenLedgerDialogFragment().show(requireActivity())
}
}

private fun handleExtendedPublicKey() {
Expand Down
77 changes: 77 additions & 0 deletions wallet/src/de/schildbach/wallet/ui/more/tools/ZenLedgerClient.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2024 Dash Core Group.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.schildbach.wallet.ui.more.tools
import com.google.gson.GsonBuilder
import de.schildbach.wallet_test.BuildConfig
import okhttp3.OkHttpClient
import org.dash.wallet.common.util.Constants
import org.slf4j.LoggerFactory
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import javax.inject.Inject

class RemoteDataSource {
fun <Api> buildApi(api: Class<Api>, baseUrl: String, client: OkHttpClient): Api {
return Retrofit.Builder()
.client(client)
.baseUrl(baseUrl)
.addConverterFactory(
GsonConverterFactory.create(
GsonBuilder()
.setLenient()
.create()
)
)
.build()
.create(api)
}
}

interface ZenLedgerApi {
suspend fun getToken()
suspend fun getSignupUrl(portfolioRequest: ZenLedgerCreatePortfolioRequest): String?
}

class ZenLedgerClient @Inject constructor(): ZenLedgerApi {
companion object {
private const val BASE_URL = "https://api.zenledger.io/"
private val log = LoggerFactory.getLogger(ZenLedgerClient::class.java)
}

private val keyId: String = BuildConfig.ZENLEDGER_CLIENT_ID
private val privateKey: String = BuildConfig.ZENLEDGER_CLIENT_SECRET
private val zenLedgerService: ZenLedgerService = RemoteDataSource().buildApi(
ZenLedgerService::class.java,
BASE_URL,
Constants.HTTP_CLIENT
)
private var token: String? = null

val hasValidCredentials: Boolean
get() = keyId.isNotEmpty() && privateKey.isNotEmpty()

override suspend fun getToken() {
token = zenLedgerService.getAccessToken(keyId, privateKey)?.accessToken
}

override suspend fun getSignupUrl(portfolioRequest: ZenLedgerCreatePortfolioRequest): String? {
val response = zenLedgerService.createPortfolio("Bearer ${token!!}", portfolioRequest)
log.info("create portfolio response: {}", response)
return response?.data?.signupUrl
}
}
Loading

0 comments on commit 03c6f5c

Please sign in to comment.