Skip to content

Commit

Permalink
Merge to main (1.0.1) (#88)
Browse files Browse the repository at this point in the history
* Update .gitignore to ignore all .idea files and all build directories. (#20)

* Turn on Gradle parallel execution and caching.

* Add "app_deployment" key (#21)

* Add "app_deployment" key

* Lint

* Initial setup of StrictMode - only logging in debug. (#22)

* Initial setup of StrictMode - only logging in debug.

* Revert injection changes

* Use limitedParallelism and MainScope() in AbacusThreadingImp. (#25)

* Handle exception with invalid URLs (#26)

* MOB-348 Show Squid routing error on deposit/withdrawal (#28)

* Update AppModule.kt and used dependencies to follow Dagger Best Practices guide (in Notion). (#27)

* Correlate x-request-id to correlate route requests from Squid transactions (#23)

* Fix build (#29)

* MOB-362: Some url links don't work with the deployment build (#31)

* Test

* Check for deeplink path during routing

* Clean up

* Clean up

* Update rest of Dagger modules to follow best practices. (#30)

* Remove network selector from settings for release build (#33)

* MOB-363: Android: "System" theme setting not working (#32)

* Observe system theme

* Recompose when theme changes

* Fix a crash on url tapping (#34)

* Remove hardcoded scheme in the setting links. (#35)

* Add Firebase Performance monitoring. (#37)

* Bump Abacus and update the system link. (#36)

* Fix the release build issue of wallet amount not showing up on deposit (#38)

* Fix Subaccount transfer for France (#39)

* Fix Subaccount transfer for France

* Lint

* Update function name to be consistent with iOS

* Clean up the start-up sequence (#41)

* Clean up the start-up sequence

* Lint

* Update Cartera and WalletConnnect to the latest version (#40)

* Update Cartera

* Lint

* Add comments

* MOB-285: Call startTrade() after setMarket() (#43)

* Update the v4-native-client.js to replace # with ___ (#42)

* Add script

* Update v4-client.js

* Safer replacement

* Safer replacement

* Move startWorkers back to Activity.onCreate() (#44)

* Move startWorkers back to Activity.start()

* Comment

* MOB-410 Add tracking for onboarding, transfer, wallet connection (#46)

* Adding Onboarding/Transfer/Wallet events

* Add userID and userProperties

* Optimiazation

* Add link to send logcat messages via email (#45)

* Add link to send logcat messages via email

* Clean up

* Error handling

* Make file provider depending on applicationId

* MOB-432 previous branch was based on a wrong branch (#48)

* MOB-432 previous branch was based on a wrong branch

* PR

* Bump Abacus (#50)

* Bump Abacus

* Revert

* MOB-421 add settings control to turn in-app notifications on/off completely  (#49)

* MOB-421 add settings control to turn in-app notifications on/off completely

* MOB-421 add settings control to turn in-app notifications on/off completely

* Clean up

* Feature/mob 396 position cell with margin type (#51)

* MOB-432 previous branch was based on a wrong branch

* PR

* MOB-396 skeleton for position cell

* Better layout for place holder views (when there is no position, fill or transfers)

* Convert AbacusState flows into StateFlows. (#52)

* MOB-422 Withdrawal gating (#53)

* Withdrawal Gating

* Clean up

* Doing the paddings better. (#56)

* Update Android Gradle Plugin (#55)

* MOB-446  create new add price triggers panel screen  (#58)

* SL/TP Routing and  price triggers panel screen

* Update deeplink to match iOS

* Renaming

* MOB-443 add limit price to price triggers screen (#60)

* Feature/mob 356 trade input (#57)

* Margin type and leverage screens skeleton

* MOB-356 MOB-358 Margin mode screen

* Change bg color

* move modifier to param

* Feature/mob 257 weekly dates (#61)

* Added end time to rewards date range

* lint

* Update SharingStarted usages from Lazily to WhileSubscribed(). (#62)

* Fix issue of text input losing calculated value when not focused (#64)

* Inject coroutine scopes and dispatchers instead of hardcoding. (#65)

* Revert "Update SharingStarted usages from Lazily to WhileSubscribed(). (#62)" (#66)

This reverts commit de98092.

* Fix margin issues with portfolio position items (#67)

* Fix threading issue (#68)

* Bump Abacus and v4-client (#69)

* MOB-440 TP/SL order submission and data binding (#63)

* Wire up input data

* Submission

* WIP

* Bump Abacus and toggle size section

* Update PlatformInfoScaffold

* submissionStatus = _submissionStatus

* Simplify TriggerOrderStream

* Fix an issue of order/fill status display (#72)

* Fix dollar() formatting crash in FR locale. (#74)

* Add formatting functions for size specified in double (1000.0, 0.001,… (#73)

* Add formatting functions for size specified in double (1000.0, 0.001, etc)

* Clean up

* Clean up

* Clean up BigDecimals

* Remove rounded(bigDecimal:

* Fix rounding issue on leverage slider when locale is French (#75)

* MOB-441 add TP/SL display to market screen (Android) (#71)

* Wire up input data

* Submission

* WIP

* Bump Abacus and toggle size section

* MarketInfo buttons

* Clean up

* Clean up TriggerOrderStream

* MOB-442 Support error states for TP/SL inputs  (#77)

* Wire up input data

* Submission

* WIP

* Bump Abacus and toggle size section

* MarketInfo buttons

* Validation

* Show validation error at sections

* Highlighting error/warning field

* Slide size formatting

* Clean up

* Clean up TriggerOrderStream

* Clean up

* Clean up

* Made localizer a computed property (#78)

* MOB-455 Add retry to trade and close order submission (#76)

* Add retry to trade and close order submission.

* _submissionStatus.asStateFlow()

* Turn on Kotlin incremental classpath snapshots. (#80)

* Fixing threading issues (#79)

* Fixing threading issues.

* Clean up

* Feature/mob 360 target leverage (#59)

* Margin type and leverage screens skeleton

* MOB-356 MOB-358 Margin mode screen

* Change bg color

* MOB-360 rough UX for target leverage screen

* Fixed PR

* move modifier to param

* lint

* There is no longer InputFieldScarfold

* Put back InputFieldScaffold

* Fix market info's stats/about tab animation issue (#83)

* MOB-14 Disable sparkline touching on market list (#84)

* Disable sparkline touching on market list

* Clean up

* Bump version (#81)

* Bump Abacus and add script to use locally built Abacus (#86)

* Bump Abacus and add script to use locally built Abacus

* Usage

* Update

* Feature/mob 400 adjust margin screen (#85)

* Margin type and leverage screens skeleton

* MOB-356 MOB-358 Margin mode screen

* Change bg color

* MOB-360 rough UX for target leverage screen

* Fixed PR

* move modifier to param

* In the middle of coding

* lint

* There is no longer InputFieldScarfold

* Put back InputFieldScaffold

* More placeholder code and it compiles

* rough amount input

* Formatting "Add Margin" and "Remove Margin"

---------

Co-authored-by: prashanDYDX <163016611+prashanDYDX@users.noreply.github.com>
Co-authored-by: Prashan Dharmasena <prashan@dydx.exchange>
Co-authored-by: John Huang <johnqh@yahoo.com>
  • Loading branch information
4 people authored Apr 30, 2024
1 parent f78405a commit 7f33b31
Show file tree
Hide file tree
Showing 98 changed files with 2,930 additions and 390 deletions.
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8

org.gradle.parallel=true
org.gradle.caching=true
# compilation avoidance for non public code changes
kotlin.incremental.useClasspathSnapshot=true

# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
Expand Down
42 changes: 42 additions & 0 deletions scripts/build_abacus_local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh

# This script is used to build the abacus project locally.
#
# Please run this after making local change to the abacus project. The change will be
# picked up by the v4-native-android project (via the local maven repository). Note that
# the script needs to be run everytime a change is made to the abacus project.
#
# The script will update both the v4-abacus and v4-native-android repositories, so please make sure
# you clean-up/revert the changes after you are done with the local testing

ABACUS_DIR=~/v4-abacus
ANDROID_DIR=~/v4-native-android

# Create a random version number
NEW_VERSION="local.$(date +%s)"

# search for the first line that starts with "version" in build.gradle.kts
# get the value in the quotes
VERSION=$(grep "^version = " ${ABACUS_DIR}/build.gradle.kts | sed -n 's/version = "\(.*\)"/\1/p')

sed -i '' "s/version = \"$VERSION\"/version = \"$NEW_VERSION\"/" ${ABACUS_DIR}/build.gradle.kts
echo "Version bumped to $NEW_VERSION"

echo "Building Abacus ..."

cd ${ABACUS_DIR}
./gradlew publishToMavenLocal

cd ${ANDROID_DIR}

# get the version from the file
targetFileName="v4/build.gradle"
OLD_VERSION=$(grep "^ abacusVersion = " $targetFileName | sed -n 's/ abacusVersion = ''\(.*\)''/\1/p')

if [ -n "$NEW_VERSION" ] && [ -n "$OLD_VERSION" ]; then
echo "Bumping Abacus version from $OLD_VERSION to $NEW_VERSION"
sed -i '' "s/^ abacusVersion = $OLD_VERSION/ abacusVersion = '$NEW_VERSION'/" $targetFileName
echo "Version bumped to $NEW_VERSION"
else
echo "No version found"
fi
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencyResolutionManagement {
}
}
}
// mavenLocal()
mavenLocal()
}
}

Expand Down
2 changes: 1 addition & 1 deletion v4/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
minSdkVersion parent.minSdkVersion
targetSdkVersion parent.targetSdkVersion
versionCode 9
versionName "1.0.0"
versionName "1.0.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
2 changes: 1 addition & 1 deletion v4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ ext {
compileSdkVersion = 34

// App dependencies
abacusVersion = '1.6.40'
abacusVersion = '1.6.46'
carteraVersion = '0.1.13'
kollectionsVersion = '2.0.16'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package exchange.dydx.trading.common.formatter

import exchange.dydx.utilities.utils.rounded
import java.math.BigDecimal
import java.math.RoundingMode
import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
import java.text.NumberFormat
import java.text.SimpleDateFormat
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit
import java.util.Date
import java.util.Locale
import java.util.regex.Pattern
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.math.abs
import kotlin.math.absoluteValue
import kotlin.math.round

@Singleton
class DydxFormatter @Inject constructor() {
Expand All @@ -37,12 +41,12 @@ class DydxFormatter @Inject constructor() {
DateTimeFormatter.ofPattern("MMM dd").withZone(ZoneOffset.UTC)
}

private val timeFormatter: SimpleDateFormat by lazy {
SimpleDateFormat("HH:mm:ss", locale)
private val timeFormatter: DateTimeFormatter by lazy {
DateTimeFormatter.ofPattern("HH:mm:ss", locale)
}

private val dateTimeFormatter: SimpleDateFormat by lazy {
SimpleDateFormat("yyyy-MM-dd HH:mm:ss", locale)
private val dateTimeFormatter: DateTimeFormatter by lazy {
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", locale)
}

fun dollarVolume(number: Double?, digits: Int = 2): String? {
Expand Down Expand Up @@ -97,15 +101,14 @@ class DydxFormatter @Inject constructor() {
null
}
}
fun localFormatted(number: Double?, digits: Int): String? {
return localFormatted(number?.toBigDecimal(), digits)
}

fun localFormatted(number: BigDecimal?, digits: Int): String? {
fun localFormatted(number: Double?, digits: Int?): String? {
if (number != null) {
val number = if (digits != null) rounded(number, digits) else number
val decimalFormat = NumberFormat.getInstance(locale) as? DecimalFormat
decimalFormat?.minimumFractionDigits = maxOf(digits, 0)
decimalFormat?.maximumFractionDigits = maxOf(digits, 0)
if (digits != null) {
decimalFormat?.minimumFractionDigits = maxOf(digits, 0)
decimalFormat?.maximumFractionDigits = maxOf(digits, 0)
}

val formatted = decimalFormat?.format(number)
val parsed = decimalFormat?.parse(formatted)
Expand All @@ -118,39 +121,16 @@ class DydxFormatter @Inject constructor() {
return null
}

fun localFormatted(number: BigDecimal?, size: String): String? {
val digits = digits(size)
return localFormatted(number, digits)
fun dollar(number: Double?, size: Double? = null): String? {
return dollar(number = number, digits = digits(size))
}

private fun digits(size: String): Int {
val pattern = Pattern.compile("\\.(\\d+)")

val matcher = pattern.matcher(size)
if (matcher.find()) {
return matcher.group(1).length
}
return 2 // Default digits
}

fun dollar(number: Double?, size: String? = null): String? {
return dollar(number = number?.toBigDecimal(), size = size)
}

fun dollar(number: BigDecimal?, size: String? = null): String? {
return dollar(number, digits = digits(size ?: "0.01"))
}

fun dollar(number: Double?, digits: Int): String? {
return dollar(number = number?.toBigDecimal(), digits = digits)
}

fun dollar(number: BigDecimal?, digits: Int): String? {
fun dollar(number: Double?, digits: Int?): String? {
if (number == null) return null
val formattedNumber = localFormatted(number.abs(), digits)
val formattedNumber = localFormatted(abs(number), digits)
return formattedNumber?.let {
val rawDouble = raw(number.toDouble(), digits)?.toDouble() ?: 0.0
if (rawDouble >= 0.0) {
val rounded = if (digits != null && digits >= 0) number.rounded(toPlaces = digits) else number
if (rounded >= 0) {
"$$it"
} else {
"-$$it"
Expand All @@ -159,10 +139,6 @@ class DydxFormatter @Inject constructor() {
}

fun percent(number: Double?, digits: Int, minDigits: Int? = null): String? {
return percent(number = number?.toBigDecimal(), digits = digits, minDigits = minDigits)
}

fun percent(number: BigDecimal?, digits: Int, minDigits: Int? = null): String? {
if (number != null) {
percentFormatter.minimumFractionDigits = minDigits ?: digits
percentFormatter.maximumFractionDigits = digits
Expand Down Expand Up @@ -233,17 +209,19 @@ class DydxFormatter @Inject constructor() {
}
}

fun dateTime(time: Instant?): String? {
fun dateTime(time: Instant?, timeZone: ZoneId = ZoneId.systemDefault()): String? {
return if (time != null) {
dateTimeFormatter.format(Date.from(time))
val ldt: LocalDateTime = time.atZone(timeZone).toLocalDateTime()
dateTimeFormatter.format(ldt)
} else {
null
}
}

fun clock(time: Instant?): String? {
fun clock(time: Instant?, timeZone: ZoneId = ZoneId.systemDefault()): String? {
return if (time != null) {
timeFormatter.format(Date.from(time))
val ldt: LocalDateTime = time.atZone(timeZone).toLocalDateTime()
timeFormatter.format(ldt)
} else {
null
}
Expand All @@ -264,39 +242,104 @@ class DydxFormatter @Inject constructor() {
}
}

/*
xxxxx.yyyyy
Will take the number and round it to the closest step size
e.g. if number is 1021 and step size is "100" then output is "1000"
*/
fun decimalLocaleAgnostic(number: Double?, size: Double? = null): String? {
return raw(number = number, size = size, locale = Locale.US)
}

/*
xxxxx.yyyyy
*/
fun decimalLocaleAgnostic(number: Double?, digits: Int): String? {
fun decimalLocaleAgnostic(number: Double?, digits: Int?): String? {
return raw(number = number, digits = digits, locale = Locale.US)
}

/*
xxxxxx,yyyyy or xxxxx.yyyyy
Will take the number and round it to the closest step size
e.g. if number is 1021 and step size is "100" then output is "1000"
*/
fun raw(number: Double?, size: Double? = null, locale: Locale? = null): String? {
val digits = digits(size)
return raw(number = number, digits = digits, locale = locale ?: this.locale)
}

/*
xxxxxx,yyyyy or xxxxx.yyyyy
*/
fun raw(number: Double?, digits: Int? = null, locale: Locale = Locale.getDefault()): String? {
fun raw(number: Double?, digits: Int?, locale: Locale = Locale.getDefault()): String? {
return number?.let { value ->
if (value.isFinite()) {
if (digits != null) {
val rounded = rounded(value, digits)
val rawFormatter = DecimalFormat.getInstance(locale).apply {
minimumFractionDigits = maxOf(digits, 0)
maximumFractionDigits = maxOf(digits, 0)
roundingMode = RoundingMode.HALF_UP
isGroupingUsed = false
}
val formatted = rawFormatter.format(number)
val formatted = rawFormatter.format(rounded)
val number = rawFormatter.parse(formatted)
if (number.toDouble() == 0.0) { // handle -0.0
rawFormatter.format(0.0)
} else {
formatted
}
} else {
BigDecimal(number).toPlainString()
number.toString()
}
} else {
""
}
}
}

private fun rounded(number: Double, digits: Int): Double {
if (digits >= 0) {
return number
} else {
val reversed = digits * -1
val divideBy = Math.pow(10.0, reversed.toDouble() - 1)
return round(number / divideBy).toInt() * divideBy
}
}

/*
Returns the number of digits for a given size specified in the format of 10^(-x)
e.g.
0.001 -> 3,
0.1 -> 1,
1 -> 0,
10 -> -1
1000 -> -3
*/
private fun digits(size: Double?): Int? {
if (size == null || size <= 0.0) return null

var size = size
if (size >= 1) {
var count = 0
while (size >= 1) {
count++
size /= 10
}
return count * -1
} else if (size <= 0.1) {
var count = 0
while (size <= 0.1) {
count++
size *= 10
}
return count
} else {
return null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ object TradeRoutes {
const val margin_type = "trade/margin_type"
const val target_leverage = "trade/target_leverage"
const val trigger = "trade/take_profit_stop_loss"
const val adjust_margin = "trade/adjust_margin"
}

object TransferRoutes {
Expand Down
Loading

0 comments on commit 7f33b31

Please sign in to comment.