-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zenledger): add entry point and export functionality to tools me…
…nu (#1276)
- Loading branch information
1 parent
158566d
commit 03c6f5c
Showing
19 changed files
with
563 additions
and
3 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,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> |
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,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> |
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
77 changes: 77 additions & 0 deletions
77
wallet/src/de/schildbach/wallet/ui/more/tools/ZenLedgerClient.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,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 | ||
} | ||
} |
Oops, something went wrong.