-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/transfer-state-save
- Loading branch information
Showing
61 changed files
with
5,097 additions
and
437 deletions.
There are no files selected for viewing
3,536 changes: 3,536 additions & 0 deletions
3,536
app/schemas/one.mixin.android.db.MixinDatabase/64.json
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package one.mixin.android.db | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.paging.PagingSource | ||
import androidx.room.Dao | ||
import androidx.room.Query | ||
import androidx.room.Transaction | ||
import kotlinx.coroutines.flow.Flow | ||
import one.mixin.android.ui.home.web3.components.InscriptionState | ||
import one.mixin.android.vo.UtxoItem | ||
import one.mixin.android.vo.route.SwapOrder | ||
import one.mixin.android.vo.route.SwapOrderItem | ||
import one.mixin.android.vo.safe.Output | ||
import one.mixin.android.vo.safe.SafeCollectible | ||
import one.mixin.android.vo.safe.SafeCollection | ||
import timber.log.Timber | ||
|
||
@Dao | ||
interface OrderDao : BaseDao<SwapOrder> { | ||
|
||
@Query( | ||
""" | ||
SELECT o.*, t.icon_url as asset_icon_url, rt.icon_url as receive_asset_icon_url, rt.symbol as receive_asset_symbol, t.symbol as asset_symbol, pc.name AS pay_chain_name, rc.name AS receive_chain_name FROM swap_orders o | ||
LEFT JOIN tokens t ON o.pay_asset_id = t.asset_id | ||
LEFT JOIN tokens rt ON o.receive_asset_id = rt.asset_id | ||
LEFT JOIN chains pc ON t.chain_id = pc.chain_id | ||
LEFT JOIN chains rc ON rt.chain_id = rc.chain_id | ||
ORDER BY o.created_at DESC | ||
""" | ||
) | ||
fun orders(): Flow<List<SwapOrderItem>> | ||
|
||
@Query( | ||
""" | ||
SELECT o.*, t.icon_url as asset_icon_url, rt.icon_url as receive_asset_icon_url, rt.symbol as receive_asset_symbol, t.symbol as asset_symbol, rt.chain_id as receive_chain_id, t.chain_id as pay_chain_id, pc.name AS pay_chain_name, rc.name AS receive_chain_name | ||
FROM swap_orders o | ||
LEFT JOIN tokens t ON o.pay_asset_id = t.asset_id | ||
LEFT JOIN tokens rt ON o.receive_asset_id = rt.asset_id | ||
LEFT JOIN chains pc ON t.chain_id = pc.chain_id | ||
LEFT JOIN chains rc ON rt.chain_id = rc.chain_id | ||
WHERE o.order_id = :orderId | ||
""" | ||
) | ||
fun getOrderById(orderId: String): Flow<SwapOrderItem?> | ||
|
||
@Query("SELECT * FROM swap_orders WHERE state = 'pending'") | ||
suspend fun getPendingOrders(): List<SwapOrder> | ||
|
||
@Query( | ||
""" | ||
SELECT created_at FROM swap_orders ORDER BY created_at DESC LIMIT 1 | ||
""" | ||
) | ||
suspend fun lastOrderCreatedAt(): String? | ||
} |
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
29 changes: 29 additions & 0 deletions
29
app/src/main/java/one/mixin/android/job/RefreshOrdersJob.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,29 @@ | ||
package one.mixin.android.job | ||
|
||
import com.birbit.android.jobqueue.Params | ||
import kotlinx.coroutines.runBlocking | ||
|
||
class RefreshOrdersJob : BaseJob(Params(PRIORITY_BACKGROUND).singleInstanceBy(GROUP).requireNetwork().persist()) { | ||
companion object { | ||
private const val serialVersionUID = 2L | ||
const val GROUP = "RefreshOrdersJob" | ||
const val LIMIT = 20 | ||
} | ||
|
||
override fun onRun(): Unit = | ||
runBlocking { | ||
val lastCreate = orderDao.lastOrderCreatedAt() | ||
refreshOrders(lastCreate) | ||
} | ||
|
||
private suspend fun refreshOrders(offset: String?) { | ||
val response = routeService.orders(limit = LIMIT, offset = offset) | ||
if (response.isSuccess && response.data != null) { | ||
orderDao.insertListSuspend(response.data!!) | ||
if (response.data!!.size >= LIMIT) { | ||
val lastCreate = response.data?.last()?.createdAt ?: return | ||
refreshOrders(lastCreate) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.