-
+
+
-
-
-
diff --git a/packages/shared/src/components/inputs/FiatAmountInput.svelte b/packages/shared/src/components/inputs/FiatAmountInput.svelte
new file mode 100644
index 0000000000..19d225765f
--- /dev/null
+++ b/packages/shared/src/components/inputs/FiatAmountInput.svelte
@@ -0,0 +1,130 @@
+
+
+
+
+
+
+
inputElement?.focus()}
+ class="flex flex-row justify-center items-end w-full
+ gap-0.5 cursor-text rounded-lg"
+ >
+
+
+ {unit}
+
+
+ {#if error}
+
+ {/if}
+
+
+ {formatCurrency(fiatAmount) || '--'}
+
+
diff --git a/packages/shared/src/lib/core/app/interfaces/transak-window-data.interface.ts b/packages/shared/src/lib/core/app/interfaces/transak-window-data.interface.ts
index 858cf83e7d..99469ab0ae 100644
--- a/packages/shared/src/lib/core/app/interfaces/transak-window-data.interface.ts
+++ b/packages/shared/src/lib/core/app/interfaces/transak-window-data.interface.ts
@@ -1,7 +1,7 @@
-import { MarketCurrency } from '@core/market/types'
+import { FiatCurrency } from '@core/market/enums'
export interface ITransakWindowData {
- currency: MarketCurrency
+ currency: FiatCurrency
address: string
service: 'BUY' | 'SELL'
amount: number
diff --git a/packages/shared/src/lib/core/market/actions/getMarketPriceForToken.ts b/packages/shared/src/lib/core/market/actions/getMarketPriceForToken.ts
index 7266ed7d43..242c4d8816 100644
--- a/packages/shared/src/lib/core/market/actions/getMarketPriceForToken.ts
+++ b/packages/shared/src/lib/core/market/actions/getMarketPriceForToken.ts
@@ -2,8 +2,10 @@ import { activeProfile } from '@core/profile/stores'
import { ITokenWithBalance } from '@core/token/interfaces'
import { get } from 'svelte/store'
-export function getMarketPriceForToken(token: ITokenWithBalance): string | undefined {
- const marketCurrency = get(activeProfile)?.settings?.marketCurrency
+export function getMarketPriceForToken(
+ token: ITokenWithBalance,
+ marketCurrency = get(activeProfile)?.settings?.marketCurrency
+): string | undefined {
const marketPrice = token?.marketPrices?.[marketCurrency]
return marketPrice ? String(marketPrice) : undefined
}
diff --git a/packages/shared/src/lib/core/market/actions/getTokenValueFromFiatAmount.ts b/packages/shared/src/lib/core/market/actions/getTokenValueFromFiatAmount.ts
new file mode 100644
index 0000000000..b4b84aa6d5
--- /dev/null
+++ b/packages/shared/src/lib/core/market/actions/getTokenValueFromFiatAmount.ts
@@ -0,0 +1,29 @@
+import { ITokenWithBalance } from '@core/token/interfaces'
+import { getMarketPriceForToken } from './getMarketPriceForToken'
+import { MarketCurrency } from '../types'
+
+export function getTokenValueFromFiatAmount(
+ fiatValue: string | undefined,
+ token: ITokenWithBalance,
+ marketCurrency?: MarketCurrency
+): bigint | undefined {
+ if (fiatValue === undefined) return undefined
+
+ const marketPrice = getMarketPriceForToken(token, marketCurrency)
+ if (marketPrice === undefined) return undefined
+
+ try {
+ const fiatValueNumber = parseFloat(fiatValue)
+ if (isNaN(fiatValueNumber)) return undefined
+
+ const tokenDecimals = token?.metadata?.decimals || 0
+ const marketPriceNumber = parseFloat(marketPrice)
+ if (isNaN(marketPriceNumber)) return undefined
+
+ // Calculate the token amount: fiatValue / marketPrice * 10^tokenDecimals
+ const tokenAmount = (fiatValueNumber / marketPriceNumber) * Math.pow(10, tokenDecimals)
+ return BigInt(Math.floor(tokenAmount))
+ } catch {
+ return undefined
+ }
+}
diff --git a/packages/shared/src/lib/core/market/actions/index.ts b/packages/shared/src/lib/core/market/actions/index.ts
index d58adb887c..aa269eba07 100644
--- a/packages/shared/src/lib/core/market/actions/index.ts
+++ b/packages/shared/src/lib/core/market/actions/index.ts
@@ -2,4 +2,5 @@ export * from './getAndUpdateMarketPrices'
export * from './getAndUpdateTokensMetadataFromCoinGecko'
export * from './getFiatValueFromTokenAmount'
export * from './getMarketPriceForToken'
+export * from './getTokenValueFromFiatAmount'
export * from './market-prices-polling'
diff --git a/packages/shared/src/lib/features/interfaces/feature-flag.interface.ts b/packages/shared/src/lib/features/interfaces/feature-flag.interface.ts
index b09ce73231..b0d6a50e77 100644
--- a/packages/shared/src/lib/features/interfaces/feature-flag.interface.ts
+++ b/packages/shared/src/lib/features/interfaces/feature-flag.interface.ts
@@ -1,4 +1,5 @@
export interface IFeatureFlag {
enabled: boolean
hidden?: boolean
+ sell?: IFeatureFlag
}
diff --git a/packages/shared/src/locales/en.json b/packages/shared/src/locales/en.json
index 3ff2eed0bd..06718280ad 100644
--- a/packages/shared/src/locales/en.json
+++ b/packages/shared/src/locales/en.json
@@ -822,6 +822,10 @@
"error": {
"title": "Transak could not be loaded",
"description": "Please restart the app, if the issue persists please ask for support in our Discord server"
+ },
+ "tabs": {
+ "buy": "Buy tokens",
+ "sell": "Sell tokens"
}
}
},