Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Packages/Store/Sources/Models/PriceRecord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ extension PriceRecord: Identifiable {
}

extension AssetPrice {
var record: PriceRecord {
return PriceRecord(
func record(fiatPrice: Double) -> PriceRecord {
PriceRecord(
assetId: assetId,
price: price,
priceUsd: price,
price: fiatPrice,
priceUsd: self.price,
priceChangePercentage24h: priceChangePercentage24h
)
Comment thread
DRadmir marked this conversation as resolved.
}
Expand Down
5 changes: 3 additions & 2 deletions Packages/Store/Sources/Stores/PriceStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ public struct PriceStore: Sendable {
let rate = try getRate(currency: currency)
try db.write { db in
for assetPrice in prices {
let _ = try assetPrice.record.upsertAndFetch(
let convertedPrice = assetPrice.price * rate.rate
let _ = try assetPrice.record(fiatPrice: convertedPrice).upsertAndFetch(
db,
onConflict: [],
doUpdate: { _ in [
PriceRecord.Columns.price.set(to: assetPrice.price * rate.rate),
PriceRecord.Columns.price.set(to: convertedPrice),
PriceRecord.Columns.priceUsd.set(to: assetPrice.price),
PriceRecord.Columns.priceChangePercentage24h.set(to: assetPrice.priceChangePercentage24h),
PriceRecord.Columns.updatedAt.set(to: Date()),
Expand Down
29 changes: 29 additions & 0 deletions Packages/Store/Tests/StoreTests/PriceStoreTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c). Gem Wallet. All rights reserved.

import Testing
import Store
import Primitives
import PrimitivesTestKit
import StoreTestKit

struct PriceStoreTests {

@Test
func firstInsertAppliesCurrencyRate() throws {
let db = DB.mockWithChains([.ethereum])
let priceStore = PriceStore(db: db)
let fiatRateStore = FiatRateStore(db: db)

let assetId = Chain.ethereum.assetId
let rate = 90.0
let priceUsd = 2500.0
let currency = Currency.rub.rawValue

try fiatRateStore.add([FiatRate(symbol: currency, rate: rate)])
try priceStore.updatePrices(prices: [.mock(assetId: assetId, price: priceUsd)], currency: currency)

let result = try priceStore.getPrices(for: [assetId.identifier])

#expect(result.first?.price == priceUsd * rate)
}
}
Loading