Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ton contest #12

Open
wants to merge 209 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
209 commits
Select commit Hold shift + click to select a range
c4b31a3
tab item text appearance
May 7, 2024
18d86f3
buy sell strings
May 7, 2024
688dfb8
fragment_trade header
May 7, 2024
03d547c
buy sell tabs enum
May 7, 2024
f90773b
empty sell fragment
May 7, 2024
2b1a277
empty buy fragment
May 7, 2024
0200d37
added viewmodel to koin module
May 7, 2024
5b4034b
buy sell pager adapter
May 7, 2024
bd3581c
added child fragment instantiation logic
May 7, 2024
ea76246
dummy content for buy fragment
May 7, 2024
8d9f227
implemented get rate flow case
May 10, 2024
d6aabbf
tinkering di
May 10, 2024
139d6cd
moved load operations to IO dispatcher
May 10, 2024
0bcb727
implemented flow observing extension function
May 10, 2024
38ac9c4
implemented basic amount input logic
May 10, 2024
257f919
currency fetching from preferences
May 10, 2024
12c6604
implemented trade method list item
May 10, 2024
2174b6a
trade divider list item
May 10, 2024
a291098
implemented trade adapter
May 10, 2024
157bd1d
implemented payment operators list support
May 10, 2024
18087ce
trade bottomsheet ux improvement
May 10, 2024
306176e
trade method list item ux improvement
May 10, 2024
cb0d85d
fixed ui issue for recycler view
May 10, 2024
2ff7dff
reduced structure complexity for buy fragment
May 10, 2024
7731352
implemented setThrottleClickListener extension
May 10, 2024
acc2a21
added continue button
May 10, 2024
e2c16fa
updated mock data
May 10, 2024
437c8e3
implemented mock getBuyMethodsCase & mapper
May 10, 2024
12d8785
vm observeFlow extension
May 10, 2024
8220c44
implemented buy list holder
May 10, 2024
e6d9c04
ui fix for trade screen
May 10, 2024
3342bf6
implemented navigation event for picking but operator
May 10, 2024
f215e1d
wrapped screen with nestedScrollView
May 10, 2024
4b4d801
pick operator fragment arguments
May 12, 2024
313a5d0
pick operator events
May 12, 2024
1b50d42
basic pick operator fragment
May 12, 2024
aa628cf
mock get avaiable currencies case
May 12, 2024
bbc07d5
mock get default currency case
May 12, 2024
8a940d7
added picked currency field to the argument
May 12, 2024
093a42b
dropdown button component
May 12, 2024
24026c5
imported icon from figma
May 12, 2024
6d848a2
added pick currency button
May 12, 2024
41b3c2b
basic pick currency fragment
May 12, 2024
e015265
a bit of renaming for CurrencyScreen components
May 12, 2024
5c39504
a bit of everything
May 12, 2024
c1bb3d9
fixed misunderstood flow details
May 12, 2024
333a845
fixed base list fragment view for bottomsheets
May 12, 2024
1b7e668
moved getNameResIdForCurrency to extension
May 12, 2024
b4805a1
made currencies list appear
May 12, 2024
f6dcd29
a bit of polish
May 12, 2024
0a94153
implemented currency picker logic
May 12, 2024
1ddb822
replaced self-made solution with ready one
May 12, 2024
efc242f
mock get payment operators case
May 12, 2024
e762504
renamed the field
May 12, 2024
de3b2a7
made operators list appear
May 12, 2024
e15f9dd
replaced self-written solution with already existing one
May 12, 2024
1dc39e3
made payment operator pickable
May 13, 2024
92f7051
implemented close flow thing & final button
May 13, 2024
fc6f8ed
a bit of renaming
May 13, 2024
88e7779
added argument to exchange fragment to reuse it
May 13, 2024
09cf35a
added exchange direction argument to getExchangeMethodsCase
May 13, 2024
7f73fdf
passed direction to pick operator fragment
May 13, 2024
9e85068
finished sell fragment
May 13, 2024
5ed52c8
a bit of ripple refactoring
May 14, 2024
e3b61a3
navigation to stake fragment
May 14, 2024
d1d3291
stake fragment header events
May 14, 2024
4dc16e8
implemented doOnAmountChange extension function
May 14, 2024
e1e04df
formattedRate extension
May 14, 2024
fb5387d
stake fragment input
May 14, 2024
0cb25a8
updated upd.sh script
May 14, 2024
e3f7562
invoke upd.sh script
May 14, 2024
184ad1a
display available balance on stake fragment
May 14, 2024
a79caa9
stake fragment input validation
May 14, 2024
cd82a7b
generalized bg_chip background
May 14, 2024
85c5123
chip view component
May 14, 2024
d8f99ca
replaced composite view with chip view
May 14, 2024
d71b81d
stake fragment dropdown layout
May 14, 2024
afd9159
staking domain models
May 14, 2024
b19f3a1
staking repository
May 14, 2024
75f3bb7
picked staking pool display
May 14, 2024
dff22e8
moved fragment stuff to the separate package
May 14, 2024
83f0335
staking option picking fragment navigation
May 14, 2024
e1b4031
staking options display
May 14, 2024
cf2a3b2
navigation to pick pool fragment
May 14, 2024
5b1a547
pick pool fragment items display
May 14, 2024
7844c3a
added pool description to pick pool fragment
May 14, 2024
0bfe57d
reworked pick pool fragment args
May 14, 2024
1aeb798
navigation to pool details fragment
May 14, 2024
f948a91
pool details part of state
May 14, 2024
1196594
pool details fragment links
May 15, 2024
84b0992
pool picking
May 15, 2024
71e2315
close flow functionality for pick pool fragment
May 15, 2024
9bbf2db
generalized the approach
May 15, 2024
4c0ff4f
introduced the approach to the fragment where it is needed
May 15, 2024
f6eb17d
extracted some signing logic
May 15, 2024
a35ba10
moved transferMessageCell creation
May 15, 2024
ac415b2
fixed build issue
May 15, 2024
6911830
cell producers for staking
May 15, 2024
bcf8f96
a bit of tinkering with transaction data
May 15, 2024
514d28a
navigation to stake confirm fragment
May 16, 2024
ffa3b88
fragment stake confirm non-rv presentation
May 16, 2024
ed8f26a
confirm stake fragment rv
May 16, 2024
2b5099a
stake case
May 16, 2024
f536793
list helper
May 16, 2024
73abc18
extracted some code from cases
May 16, 2024
2c5e2f7
staking fee calculation
May 16, 2024
b7a2fcd
unhappy path for stake confirm screen
May 16, 2024
596e539
fixed the bug
May 16, 2024
1737a05
implemented proper fee display functionality
May 16, 2024
ee6324c
initial swap fragment
May 16, 2024
63c471a
generated api classes for stonfi
May 17, 2024
755696e
added stonfi api wrapper
May 17, 2024
e64547b
stonfi dex assets repository
May 17, 2024
4e603fd
some temporal stuff
May 17, 2024
3932ca7
swap fragment layout
May 17, 2024
1e3e69b
pick token fragment init
May 17, 2024
fb07c33
pick asset fragment rv
May 17, 2024
a8fd362
input start icon option
May 17, 2024
3e8434b
pick token fragment result return
May 17, 2024
69ab510
implemented swap settings object
May 17, 2024
8a963f9
swap settings init
May 17, 2024
3763bbf
swap settings screen
May 17, 2024
763979a
swap settings arguments pass
May 17, 2024
ccd7138
switched from float to bigdecimal
May 19, 2024
d35b934
rates api for swap fragment
May 19, 2024
7f354ed
proper rates calculation
May 20, 2024
295a263
swap button
May 20, 2024
9596840
swap simulation on swap fragment
May 20, 2024
de5e340
extracted token button to separate view
May 20, 2024
e328d26
extracted swap details view
May 20, 2024
76e1ae3
confirm swap initial fragment
May 20, 2024
71f05da
swap ton->jetton
May 20, 2024
fb82fb9
jetton->ton swap
May 20, 2024
39b49e7
jetton->jetton swap
May 20, 2024
f98bd64
search in pick token fragment
May 20, 2024
de5cb23
minor bugs
May 20, 2024
2af00e2
liquid staking message
May 21, 2024
ad7f5f4
currency for pool details fragment
May 21, 2024
a217a2a
flexible currency in swap fragment
May 21, 2024
4f01479
country picker on buy/sell fragment
May 21, 2024
e4fdcf0
got rid of balance entity for swap
May 22, 2024
a3ac863
staked items on wallet screen
May 22, 2024
94a4b61
proper comparator for swap tokens list
May 22, 2024
98835d6
min amount validation for buy/sell fragment
May 22, 2024
dc29fda
staked asset fragment init
May 22, 2024
539591f
proper staking balance rates
May 22, 2024
ab48783
extracted liquid staking details view
May 22, 2024
0e2f32a
extracted pool details view
May 22, 2024
a5a1d5f
extracted pool links view
May 22, 2024
1150d23
swap footer button text change
May 22, 2024
a8401d9
buy/sell items
May 22, 2024
ba4c92f
sell fragment input < balance validation
May 22, 2024
2c5efcb
performance issue fix on pick asset screen
May 22, 2024
94dc947
extracted staking input form
May 23, 2024
40aa292
unstake messages
May 23, 2024
b05f6a9
unstake fragment init
May 23, 2024
6b2655e
unstake fragment state
May 23, 2024
7661097
bugfix for unstake flow
May 23, 2024
2882474
min stake validation
May 23, 2024
90ff09e
price impact on swap details view
May 23, 2024
e22d4d6
route for swap details view
May 23, 2024
4ffdee1
staking pool balances cache step 1
May 23, 2024
c8474c0
staking pool balances cache step 2
May 23, 2024
1922f4f
staking pool balances cache step 3
May 23, 2024
11680f4
staking pool balances cache step 4
May 23, 2024
4b7780a
staking pool balances cache step 5
May 23, 2024
cd3b0a3
proper processing for nominator pools
May 23, 2024
430d5cb
pending stake/unstake labels
May 24, 2024
f9ed508
stake button handling for staking balance fragment
May 24, 2024
cd60f52
swap receive balance text
May 24, 2024
9bff998
svg loadable image support
May 24, 2024
f40fa1d
finish flow when swap is done
May 24, 2024
0d6dc7c
stake input view max button glow feature
May 24, 2024
2a74edd
navigation from staking balance screen to jetton screen
May 24, 2024
4ac9272
navigation to history when swap/staking is done
May 24, 2024
5dba402
swap confirm button animation
May 24, 2024
05b6afe
set max slippage to 99
May 24, 2024
9cfd345
extracted staking services repository
May 24, 2024
5400fcb
separated flow for testnet staking services
May 24, 2024
ebcdbb1
crypto balances on swap token picker
May 24, 2024
e149442
a bit of refactoring
May 24, 2024
071833e
extracted nominator pool repository
May 24, 2024
eb526d3
reworked the way staked balances were calculated
May 24, 2024
3e132f5
error handling on wallet screen
May 24, 2024
e1d99c3
refactored token item model
May 26, 2024
b930788
refactored dex asset model
May 26, 2024
5cac2b6
got rid of multiple unnecessary fields
May 26, 2024
c7192fa
change jetton asset balance data source
May 26, 2024
eae2495
throttling transformation for ui items flow
May 26, 2024
dad4ce2
swap assets refactoring
May 26, 2024
52125aa
fiat balances on swap picker
May 26, 2024
3aacb94
fixed fiat text for unstake fragment
May 26, 2024
042ca90
staking documentation
May 27, 2024
7451140
swap feature documentation
May 27, 2024
5e08dc6
buy/sell documentation
May 27, 2024
e9b0837
pre-map domain items for swap screen
May 28, 2024
42e7b78
added nominator pools caching
May 28, 2024
d285138
introduced local storage for dex rates
May 28, 2024
6df01b3
unstake ready feature
May 28, 2024
8001ae8
pick asset screen: picked currencies filtration
May 29, 2024
1b0deac
footers bottom padding
May 29, 2024
8459fb2
to send/to receive highlight
May 29, 2024
93f1da8
skeleton loader for swap fragment
May 29, 2024
b70cc97
swap details info buttons
May 29, 2024
a155029
swap input balance validation
May 29, 2024
6554f89
swap balance formatting
May 29, 2024
0d72691
list item mapper cache
May 29, 2024
431e948
swap details text color accent
May 29, 2024
a5d85a8
collapsing search bar
May 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
313 changes: 313 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,314 @@
# tonkeeper

# About this submission

- There are **all three** features implemented
- It really **is** native. It means that this solution does not use third-party SDK in order to form
a blockchain message for swap/staking features. This feature makes the solution less error-prone and
better performance-wise (hence, faster).
- It is almost pixel-perfect and aligns to the designs provided by the contest organizers.

## Staking

Supports all 3 implementations of staking pools:
- Tonstakers
- TON Whales
- TON Nominators

Supports both staking and unstaking.

One can inspect the way blockchain messages are built, checking `CellProducer` interface
implementations. Those are completely natively produced cells.

### Stake screen

To navigate to this screen, just click on `Stake` on the main screen.

You can pick the preferred one from `Stake` screen. When picking, you've got the pool with `Max APY`
highlighted which helps making the right choice. By default, the pool with max APY is picked.

When pool is picked, you've got to enter the amount of `TON` you wish to stake. Form here validates
the input, and does not allow user to enter neither the amount they do not currently have nor amount
less than minimal staking field stated in pool info.

For users who are in hurry, there is a `MAX` button, that sets the amount user wishes to stake equal
to the `TON` balance user currently have.

Users who are new to staking can get an additional info provided by the `info` button on the top
left corner.

There is a `Continue` button. It is only active when user input is valid. When clicked, navigates
user to `Confirm stake screen`.

### Stake options screen

On this screen, there are all three pool implementations present (at least this is correct for the
mainnet). The pool implementation that user has picked is highlighted with active radiobutton. When
user clicks one of those implementations, there are two possible outcomes:
1. There is only one pool for given implementation (true for Tonstakers). In this case, user is
being navigated to this one `Staking pool details screen`.
2. There are more than one pool for the given implementation. In this case, user is being navigated
to the `Staking pools list screen`

The pool implementation that has the highest `APY` is highlighted with `Max APY` sign.

There are two navigation bar buttons:
1. Chevron in top left corner. Navigates back to the `Stake screen`
2. Cross in top right corner. Closes the flow and navigates user to the main screen.

### Staking pools list screen

It looks pretty much the same as `Stake options screen`. If user has the pool from given
implementation picked, this pool is highlighted with active radiobutton. Pool with the highest `APY`
is highlighted with `Max APY` sign.

When clicked on any pool, user is being navigated to the `Staking pool details screen`.

There are two navigation bar buttons:
1. Chevron in top left corner. Navigates back to `Stake options screen`.
2. Cross in top right corner. Closes the flow and navigates user to the main screen.

### Staking pool details screen

Has all the information in regards to the given pool.

Header displays the pool name.

Pool `APY` and `Minimal deposit` are displayed too. If `APY` is maximal, shows `Max APY` sign.

Also shows the links for the given pool. There are always present:
1. Link to the pool provider website (e.g. `tonwhales.com`)
2. Link to the `tonviewer` website where user can check the latest transactions for the pool.

Other links are optional and only appear when provided. When link is clicked, user is being
redirected to the browser.

If pool supports liquid staking, shows details for the corresponding token.

Has `Continue` button. When this button is clicked, navigates user to the `Stake screen`. Updates state
of the `Stake screen`, switching picked pool.

There are two navigation bar buttons:
1. Chevron in top left corner. Navigates back to either `Staking pools list screen` or `Stake
options screen`, depending on where user came from.
2. Cross in top right corner. Closes the flow and navigates user to the main screen.

### Confirm stake screen

Displays the pool icon.

Displays the amount of `TON` user wishes to stake. The amount is being provided from `Stake screen`.
This means it is validated.

Displays the equivalent in currency picked by user.

Displays the wallet name.

Displays the recipient pool name.

Displays the fee in both `TON` and user-preferred fiat currency.

Has a slider. When slider is slided, hides the slider and shows the loader animation on it's place.
When request is handled, there are two possible outcomes.
1. Request is successfully published to the blockchain. In this case, shows green checkmark with
`Done` text and finishes the flow after a second.
2. Request is not published to the blockchain. In this case, shows red cross with `Error` text.

When flow is finished, user is being navigated to the history screen, where their transaction is
being pending.

Navigation bar has 2 buttons:
1. Chevron on the top left corner. Navigates user back to `Stake screen`.
2. Cross on the top right corner. Closes the flow and navigates user to the main screen.

### Main screen

When user has some `TON` staked, there will be changes on the main screen.
1. If user has some liquid staking jetton (e.g. `tsTON`), instead of displaying it as a jetton, app
will display it as a staked balance.
2. If user has simple staking, it will also be displayed right under the jetton balances.

There are some catches with balances of those items:
1. If staking has pending deposit/withdrawal, it won't be displayed in the staking balance since this
balance is not mobile yet. However, it will be summed up for overall balance. So after staking 50 TON,
your overall balance won't change much. However, your staked asset will be at 0 until the next staking
cycle starts.
2. When pending deposit/withdrawal are present, it'll be stated with a corresponding message on a
given item.

When any of those items are clicked, user is being navigated to the `Staking balance screen`.

### Staking balance screen

It has pretty much all the information from `Staking pool details screen`. But is not limited to it.
This screen also shows the balance of staked asset in both `TON` and fiat.

When user have pending withdrawal, it shows corresponding message.

Same is true for pending deposit.

If pool has liquid staking jetton, it's balance will be shown on this screen. User can click this button.
This will navigate user to the jetton balance screen.

There also are `Stake` and `Unstake` buttons.
`Stake` leads to the `Stake screen`. On stake screen, picked poll will be the same that you navigated
from

`Unstake` button leads to `Unstake screen`.

### Unstake screen

This screen is pretty much the same as `Stake screen`. However, it does not allow user to pick the
pool to unstake, since it remembers it from `Staking balance screen`.

Also displays the time user have to wait till the validation cycle is over.

Has `Continue` button. When button is clicked, leads to `Confirm unstake screen`.

### Confirm unstake screen

Works the same way as `Stake screen` but the operation that is done when confirmed is quite the
opposite.

## Swap

Supports swap via `ston.fi` dex.
Only supports jettons that:
1. Have usd price field non-null
2. Not blacklisted
3. Not deprecated
4. Not community
5. Have imageurl field set
6. Have display-name field set.

Any of those prerequisites can be altered in `DexAssetRepository#isValid()` method.

Supports the slippage settings. Both custom and default values.

Supports any direction of swap:
1. TON->Jetton
2. Jetton->Ton
3. Jetton->Jetton

Despite managing list of 10,500 items, works smoothly enough.

Blockchain messages are built natively, without any third-party SDK-s. One can check the code for it
in class `CreateStonfiSwapMessageCase`.

### Swap screen

There are two buttons in navigation bar:
1. Swap settings on the top left. Leads user to the `Swap settings screen`
2. Cross on the top right. Closes the flow and leads user back to main screen

On this screen, user can pick jetton to send. By default, it is `TON`. When clicking on the jetton
button, user navigates to `Swap settings screen`

The same way, user can pick jetton to receive. By default, this does not have any value. When clicked
the corresponding button, user navigates to `Swap settings screen`, same as with send token.

There also is an input, where user can enter the amount they wish to send. When entered, the amount
to receive is automatically calculated.

There is a `MAX` button above the input. When clicked, it sets the current user balance to the input
field. This allows user exchanging all the tokens they have.

There also is a `Swap` button. When clicked, it swaps token to send and token to receive. Also it
keeps corresponding values the same. (e.g. if you had TON<->USDT pair and 1 TON was entered, when
you click the `Swap` button, there will be 6.38 USDT to send and 1 TON to receive when tokens are
swapped).

When both tokens are picked and some amount is entered, transaction is being emulated. This moment,
fees and approximate amount of token to receive is being printed out. Also, at the same moment, the
`Continue` button becomes active.

When `Continue` button is clicked, user navigates to `Confirm swap screen`.

### Choose token screen

Displays the list of supported tokens that user can exchange one for another. Also displays the
balance of those tokens, both in crypto and fiat.

Tokens that have balance are sorted in order of fiat balance. Highest first, lowest last.

Tokens without balance are sorted in alphabetical order.

Also this screen supports search. Filtered tokens are sorted in the same way.

When token is clicked, screen closes and result is being sent to `Swap screen`.

### Swap settings screen

Has two modes:
1. Expert mode. In this mode user has to enter the percentage from keyboard. This mode allows any
slippage percentage from 0 to 99.
2. Novice mode. In this mode user can pick from 1%, 3%, 5%.

When user set their preferred slippage, they are free to click `Save` button. This leads to screen
closure and navigating back to `Swap screen`.

### Confirm swap screen

Shows the same info as `Swap screen` after emulating the transaction.

Has two buttons: `Cancel` and `Confirm`.

When `Confirm` is clicked, buttons are hidden and loader animation is being shown on their place.
When transaction is performed successfully, shows green checkmark with `Done` text. Within a second
navigates to the main screen and opens the history page.

When transaction fails, shows red cross with `Error` text. Within a second shows buttons back.

## Buy/sell

The sequence of screens collects all the data necessary for launching the buy (or sell) flow in
webview. This includes:
1. Country
2. Payment method (e.g. Credit card, cryptocurrency, google pay etc.)
3. Amount
4. Currency
5. Payment operator
6. Exchange type (buy or sell)

When all of those are picked, user can be navigated to the webview where user will be able to exchange
their crypto for fiat money.

Also supports min amount validation.

### Buy screen

User can enter the amount of `TON` they want to buy. Should be more than min amount (which is
hardcoded as 5 TON). Also user should pick the payment method they wish to pay with. Those methods
are also hard-coded, since there were no API for that.

Also user can navigate to `Pick country screen`

When everything is picked, user can click `Continue` button in order to navigate to `Pick operator
screen`

### Sell screen

Pretty much the same as `Buy screen` but it has an additional validation. It validates whether or not
user has the stated amount of `TON` on their balance to be able to sell it. So user cannot try selling
50 `TON` when they only have 10.

### Pick operator screen

Displays dropdown button with picked currency. When this button is clicked, navigates to `Pick
currency screen`.

Also displays a list of payment operators, that are available for given country, payment method,
amount, currency, exchange type.

When payment operator is clicked, it becomes checked and un-check the previous one.

This screen also contains `Continue` button. When clicked, navigates user to `Billing web-view`.

### Pick currency screen

Screen where a list of supported currencies for given exchange type, country, payment method, amount
is displayed. When item is clicked, screen closes and sends result to `Pick operator screen`

### Billing web-view

Pretty much the same as it was on `FiatDialog`.
2 changes: 2 additions & 0 deletions apps/wallet/api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("kotlin-parcelize")
id("kotlinx-serialization")
}

android {
Expand All @@ -25,6 +26,7 @@ android {
dependencies {
implementation(Dependence.Koin.core)
implementation(project(Dependence.Module.tonApi))
implementation(project(Dependence.Module.stonfiApi))
implementation(project(Dependence.Lib.network))
implementation(project(Dependence.Lib.blockchain))
implementation(project(Dependence.Lib.extensions))
Expand Down
24 changes: 20 additions & 4 deletions apps/wallet/api/src/main/java/com/tonapps/wallet/api/API.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import io.tonapi.models.Account
import io.tonapi.models.AccountEvent
import io.tonapi.models.AccountEvents
import io.tonapi.models.EmulateMessageToWalletRequest
import io.tonapi.models.GetStakingPools200Response
import io.tonapi.models.MessageConsequences
import io.tonapi.models.NftItem
import io.tonapi.models.SendBlockchainMessageRequest
Expand All @@ -43,6 +44,7 @@ import org.json.JSONArray
import org.json.JSONObject
import org.ton.api.pub.PublicKeyEd25519
import org.ton.cell.Cell
import java.math.BigDecimal
import java.util.Locale
import java.util.concurrent.TimeUnit

Expand Down Expand Up @@ -77,8 +79,19 @@ class API(

fun emulation(testnet: Boolean) = provider.emulation.get(testnet)

fun jettons(testnet: Boolean) = provider.jettons.get(testnet)

fun rates() = provider.rates.get(false)

fun staking(testnet: Boolean) = provider.staking.get(testnet)

fun getStakingPools(accountId: String, testnet: Boolean): GetStakingPools200Response {
return staking(testnet).getStakingPools(
availableFor = accountId,
includeUnverified = false
)
}

fun getEvents(
accountId: String,
testnet: Boolean,
Expand Down Expand Up @@ -118,9 +131,9 @@ class API(
): List<BalanceEntity> {
val jettonsBalances = accounts(testnet).getAccountJettonsBalances(
accountId = accountId,
currencies = currency
currencies = listOf(currency)
).balances
return jettonsBalances.map { BalanceEntity(it) }.filter { it.value > 0 }
return jettonsBalances.map { BalanceEntity(it) }.filter { it.value > BigDecimal.ZERO }
}

fun resolveAddressOrName(
Expand Down Expand Up @@ -149,7 +162,10 @@ class API(
}

fun getRates(currency: String, tokens: List<String>): Map<String, TokenRates> {
return rates().getRates(tokens.joinToString(","), currency).rates
return rates().getRates(
tokens,
listOf(currency)
).rates
}

fun getNft(address: String, testnet: Boolean): NftItem? {
Expand Down Expand Up @@ -385,7 +401,7 @@ class API(

val JSON = Json { prettyPrint = true }

private fun baseOkHttpClientBuilder(): OkHttpClient.Builder {
fun baseOkHttpClientBuilder(): OkHttpClient.Builder {
return OkHttpClient().newBuilder()
.retryOnConnectionFailure(false)
.connectTimeout(10, TimeUnit.SECONDS)
Expand Down
Loading