diff --git a/packages/desktop/features/buy-sell.features.ts b/packages/desktop/features/buy-sell.features.ts
index 07735ed62c..de3c65ecb1 100644
--- a/packages/desktop/features/buy-sell.features.ts
+++ b/packages/desktop/features/buy-sell.features.ts
@@ -2,6 +2,9 @@ import { IFeatureFlag } from '@lib/features/interfaces'
const buySellFeatures: IFeatureFlag = {
enabled: true,
+ sell: {
+ enabled: true
+ }
}
export default buySellFeatures
diff --git a/packages/desktop/lib/auxiliary/popup/enums/popup-id.enum.ts b/packages/desktop/lib/auxiliary/popup/enums/popup-id.enum.ts
index 429921049d..dd8bb4410d 100644
--- a/packages/desktop/lib/auxiliary/popup/enums/popup-id.enum.ts
+++ b/packages/desktop/lib/auxiliary/popup/enums/popup-id.enum.ts
@@ -39,6 +39,7 @@ export enum PopupId {
ReceiveAddress = 'receiveAddress',
RemoveProposal = 'removeProposal',
Revote = 'revote',
+ SelectToken = 'selectToken',
SendFlow = 'sendFlow',
SignTypedData = 'signTypedData',
SignMessage = 'signMessage',
diff --git a/packages/desktop/lib/electron/managers/transak.manager.ts b/packages/desktop/lib/electron/managers/transak.manager.ts
index 8bd5498e19..fc0373bff5 100644
--- a/packages/desktop/lib/electron/managers/transak.manager.ts
+++ b/packages/desktop/lib/electron/managers/transak.manager.ts
@@ -219,14 +219,14 @@ export default class TransakManager implements ITransakManager {
}
private getUrl(data: ITransakWindowData): string {
- const { address, currency, service, amount } = data
+ const { address, currency, service, amount, paymentMethod } = data
const apiKey = process.env.TRANSAK_API_KEY
if (typeof apiKey !== 'string') {
throw new Error('Undefined Transak API key')
}
- if (!Object.values(FiatCurrency).includes(currency as FiatCurrency)) {
+ if (!Object.keys(FiatCurrency).includes(currency)) {
throw new Error('Invalid Transak currency')
}
@@ -243,9 +243,10 @@ export default class TransakManager implements ITransakManager {
const queryParams: QueryParameters = {
apiKey,
- defaultFiatCurrency: currency,
- defaultFiatAmount: amount,
+ fiatCurrency: currency,
+ fiatAmount: amount,
walletAddress: address,
+ paymentMethod: paymentMethod,
productsAvailed: service,
cryptoCurrencyCode: 'IOTA',
network: 'miota',
@@ -256,6 +257,7 @@ export default class TransakManager implements ITransakManager {
disablePaymentMethods: ['apple_pay', 'google_pay'],
excludeFiatCurrencies: 'USD',
colorMode,
+ hideExchangeScreen: true,
}
const urlObject = buildUrl({ base: TRANSAK_WIDGET_URL, query: queryParams })
diff --git a/packages/desktop/views/dashboard/buy-sell/BuySell.svelte b/packages/desktop/views/dashboard/buy-sell/BuySell.svelte
index d3185a10b6..ac7e6c7e5c 100644
--- a/packages/desktop/views/dashboard/buy-sell/BuySell.svelte
+++ b/packages/desktop/views/dashboard/buy-sell/BuySell.svelte
@@ -3,10 +3,16 @@
import features from '@features/features'
import { BuySellMainView } from './views'
import { dashboardRoute, DashboardRoute } from '@core/router'
+ import { onMount } from 'svelte'
+ import { updateTransakFiatCurrencies } from '@auxiliary/transak'
$: if (features.analytics.dashboardRoute.buySell.enabled && $dashboardRoute === DashboardRoute.BuySell) {
Platform.trackEvent('buy-sell-route', { route: $dashboardRoute })
}
+
+ onMount(() => {
+ void updateTransakFiatCurrencies()
+ })
diff --git a/packages/desktop/views/dashboard/buy-sell/components/TokenTile.svelte b/packages/desktop/views/dashboard/buy-sell/components/TokenTile.svelte
new file mode 100644
index 0000000000..ee3336b5a2
--- /dev/null
+++ b/packages/desktop/views/dashboard/buy-sell/components/TokenTile.svelte
@@ -0,0 +1,50 @@
+
+
+{#if token && token.metadata}
+
+
+
+
+
+
+ {token.metadata.name
+ ? truncateString(token.metadata.name, 13, 0)
+ : truncateString(token.id, 6, 7)}
+
+
+ {token.metadata
+ ? `≈ ${formatTokenAmount(tokenAmount ?? BigInt(0), token.metadata, { round: false })}`
+ : '-'}
+
+
+
+
+ {marketPrice ? formatCurrency(marketPrice, currency) : '-'}
+
+
+ {fiatValue !== undefined ? formatCurrency(fiatValue ?? '', currency) : '-'}
+
+
+
+
+
+{/if}
diff --git a/packages/desktop/views/dashboard/buy-sell/components/TransakAccountPanel.svelte b/packages/desktop/views/dashboard/buy-sell/components/TransakAccountPanel.svelte
deleted file mode 100644
index e4a16a29cb..0000000000
--- a/packages/desktop/views/dashboard/buy-sell/components/TransakAccountPanel.svelte
+++ /dev/null
@@ -1,49 +0,0 @@
-
-
-
-
-
-
- {fiatBalance}
-
-
-
-
- {$selectedAccount?.depositAddress}
-
-
-
-
diff --git a/packages/desktop/views/dashboard/buy-sell/components/TransakAmountInput.svelte b/packages/desktop/views/dashboard/buy-sell/components/TransakAmountInput.svelte
new file mode 100644
index 0000000000..61e8ab3c1d
--- /dev/null
+++ b/packages/desktop/views/dashboard/buy-sell/components/TransakAmountInput.svelte
@@ -0,0 +1,26 @@
+
+
+
diff --git a/packages/desktop/views/dashboard/buy-sell/components/TransakExchangePanel.svelte b/packages/desktop/views/dashboard/buy-sell/components/TransakExchangePanel.svelte
new file mode 100644
index 0000000000..c414ddf300
--- /dev/null
+++ b/packages/desktop/views/dashboard/buy-sell/components/TransakExchangePanel.svelte
@@ -0,0 +1,198 @@
+
+
+
+
+
+
+ {#if error}
+
+
+ {localize('views.buySell.error.title')}
+ {localize('views.buySell.error.description')}
+
+
+ {:else}
+
+ {#if isFeatureEnabled('buySell.sell')}
+
+
+
+ {/if}
+
+
+
+ {/if}
+
+
diff --git a/packages/desktop/views/dashboard/buy-sell/components/TransakHistoryPanel.svelte b/packages/desktop/views/dashboard/buy-sell/components/TransakHistoryPanel.svelte
new file mode 100644
index 0000000000..5c8eb59826
--- /dev/null
+++ b/packages/desktop/views/dashboard/buy-sell/components/TransakHistoryPanel.svelte
@@ -0,0 +1,8 @@
+
+
+
+ Order history
+
diff --git a/packages/desktop/views/dashboard/buy-sell/components/TransakWindowPlaceholder.svelte b/packages/desktop/views/dashboard/buy-sell/components/TransakWindowPlaceholder.svelte
deleted file mode 100644
index 1abbf927dd..0000000000
--- a/packages/desktop/views/dashboard/buy-sell/components/TransakWindowPlaceholder.svelte
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
- {#if error}
-
- {localize('views.buySell.error.title')}
- {localize('views.buySell.error.description')}
-
- {:else if loading}
-
- {/if}
-
diff --git a/packages/desktop/views/dashboard/buy-sell/components/index.ts b/packages/desktop/views/dashboard/buy-sell/components/index.ts
index de70d28d33..601af4b8b1 100644
--- a/packages/desktop/views/dashboard/buy-sell/components/index.ts
+++ b/packages/desktop/views/dashboard/buy-sell/components/index.ts
@@ -1,4 +1,6 @@
-export { default as TransakAccountPanel } from './TransakAccountPanel.svelte'
+export { default as TokenTile } from './TokenTile.svelte'
+export { default as TransakAmountInput } from './TransakAmountInput.svelte'
export { default as TransakConnectionPanel } from './TransakConnectionPanel.svelte'
+export { default as TransakHistoryPanel } from './TransakHistoryPanel.svelte'
+export { default as TransakExchangePanel } from './TransakExchangePanel.svelte'
export { default as TransakInfoPanel } from './TransakInfoPanel.svelte'
-export { default as TransakWindowPlaceholder } from './TransakWindowPlaceholder.svelte'
diff --git a/packages/desktop/views/dashboard/buy-sell/views/BuySellMainView.svelte b/packages/desktop/views/dashboard/buy-sell/views/BuySellMainView.svelte
index b86b78b1ba..72b242d025 100644
--- a/packages/desktop/views/dashboard/buy-sell/views/BuySellMainView.svelte
+++ b/packages/desktop/views/dashboard/buy-sell/views/BuySellMainView.svelte
@@ -1,146 +1,18 @@
-
-
-
-
-
+
+
+
-
-
+
+
-
-
-
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/auxiliary/transak/actions/index.ts b/packages/shared/src/lib/auxiliary/transak/actions/index.ts
new file mode 100644
index 0000000000..224393753e
--- /dev/null
+++ b/packages/shared/src/lib/auxiliary/transak/actions/index.ts
@@ -0,0 +1,2 @@
+export * from './updateTransakCryptoCurrencies'
+export * from './updateTransakFiatCurrencies'
diff --git a/packages/shared/src/lib/auxiliary/transak/actions/updateTransakCryptoCurrencies.ts b/packages/shared/src/lib/auxiliary/transak/actions/updateTransakCryptoCurrencies.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/shared/src/lib/auxiliary/transak/actions/updateTransakFiatCurrencies.ts b/packages/shared/src/lib/auxiliary/transak/actions/updateTransakFiatCurrencies.ts
new file mode 100644
index 0000000000..bb339bb5e1
--- /dev/null
+++ b/packages/shared/src/lib/auxiliary/transak/actions/updateTransakFiatCurrencies.ts
@@ -0,0 +1,24 @@
+import { TransakApi } from '../apis'
+import { TransakFiatCurrencies, transakFiatCurrencies } from '../stores'
+
+const FILTERED_PAYMENT_OPTIONS = ['apple_pay', 'google_pay']
+
+export async function updateTransakFiatCurrencies(): Promise
{
+ const api = new TransakApi()
+ const { response } = (await api.getFiatCurrencies()) ?? {}
+
+ transakFiatCurrencies.set(
+ response?.reduce((acc, val) => {
+ return {
+ ...acc,
+ [val.symbol]: {
+ paymentOptions: val.paymentOptions
+ .filter((option) => !FILTERED_PAYMENT_OPTIONS.includes(option.id) && option.isActive)
+ .map(({ id, name, minAmount, maxAmount }) => {
+ return { id, name: name ? name : id, minAmount, maxAmount }
+ }),
+ },
+ }
+ }, {} as TransakFiatCurrencies)
+ )
+}
diff --git a/packages/shared/src/lib/auxiliary/transak/constants/transak-api-production-base-url.constant.ts b/packages/shared/src/lib/auxiliary/transak/constants/transak-api-production-base-url.constant.ts
index e2b293925e..069f9bc05e 100644
--- a/packages/shared/src/lib/auxiliary/transak/constants/transak-api-production-base-url.constant.ts
+++ b/packages/shared/src/lib/auxiliary/transak/constants/transak-api-production-base-url.constant.ts
@@ -1 +1 @@
-export const TRANSAK_API_PRODUCTION_BASE_URL = 'https://api.transak.com/api/v2'
+export const TRANSAK_API_PRODUCTION_BASE_URL = 'https://api.transak.com'
diff --git a/packages/shared/src/lib/auxiliary/transak/constants/transak-api-staging-base-url.constant.ts b/packages/shared/src/lib/auxiliary/transak/constants/transak-api-staging-base-url.constant.ts
index d60fc85351..aa713b28d1 100644
--- a/packages/shared/src/lib/auxiliary/transak/constants/transak-api-staging-base-url.constant.ts
+++ b/packages/shared/src/lib/auxiliary/transak/constants/transak-api-staging-base-url.constant.ts
@@ -1 +1 @@
-export const TRANSAK_API_STAGING_BASE_URL = 'https://api-stg.transak.com/api/v2'
+export const TRANSAK_API_STAGING_BASE_URL = 'https://api-stg.transak.com'
diff --git a/packages/shared/src/lib/auxiliary/transak/enums/transak-api-endpoint.enum.ts b/packages/shared/src/lib/auxiliary/transak/enums/transak-api-endpoint.enum.ts
index 96e150b901..b571225395 100644
--- a/packages/shared/src/lib/auxiliary/transak/enums/transak-api-endpoint.enum.ts
+++ b/packages/shared/src/lib/auxiliary/transak/enums/transak-api-endpoint.enum.ts
@@ -1,4 +1,4 @@
export enum TransakApiEndpoint {
- CryptoCurrencies = 'currencies/crypto-currencies',
- FiatCurrencies = 'currencies/fiat-currencies',
+ CryptoCurrencies = 'api/v2/currencies/crypto-currencies',
+ FiatCurrencies = 'fiat/public/v1/currencies/fiat-currencies',
}
diff --git a/packages/shared/src/lib/auxiliary/transak/enums/transak-payment-option.enum.ts b/packages/shared/src/lib/auxiliary/transak/enums/transak-payment-option.enum.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/shared/src/lib/auxiliary/transak/index.ts b/packages/shared/src/lib/auxiliary/transak/index.ts
index 6921285864..812088a792 100644
--- a/packages/shared/src/lib/auxiliary/transak/index.ts
+++ b/packages/shared/src/lib/auxiliary/transak/index.ts
@@ -1,2 +1,6 @@
+export * from './actions'
+export * from './apis'
export * from './constants'
export * from './enums'
+export * from './interfaces'
+export * from './stores'
diff --git a/packages/shared/src/lib/auxiliary/transak/stores/index.ts b/packages/shared/src/lib/auxiliary/transak/stores/index.ts
new file mode 100644
index 0000000000..2c21a11252
--- /dev/null
+++ b/packages/shared/src/lib/auxiliary/transak/stores/index.ts
@@ -0,0 +1,2 @@
+export * from './transak-crypto-currencies.store'
+export * from './transak-fiat-currencies.store'
diff --git a/packages/shared/src/lib/auxiliary/transak/stores/transak-crypto-currencies.store.ts b/packages/shared/src/lib/auxiliary/transak/stores/transak-crypto-currencies.store.ts
new file mode 100644
index 0000000000..19dfaf7b2f
--- /dev/null
+++ b/packages/shared/src/lib/auxiliary/transak/stores/transak-crypto-currencies.store.ts
@@ -0,0 +1,3 @@
+import { writable } from 'svelte/store'
+
+export const transakCryptoCurrencies = writable({})
diff --git a/packages/shared/src/lib/auxiliary/transak/stores/transak-fiat-currencies.store.ts b/packages/shared/src/lib/auxiliary/transak/stores/transak-fiat-currencies.store.ts
new file mode 100644
index 0000000000..d612ee8b9e
--- /dev/null
+++ b/packages/shared/src/lib/auxiliary/transak/stores/transak-fiat-currencies.store.ts
@@ -0,0 +1,16 @@
+import { FiatCurrency } from '@core/market'
+import { Writable, writable } from 'svelte/store'
+
+export type TransakFiatCurrencies = {
+ [key in keyof typeof FiatCurrency]: {
+ paymentOptions: {
+ id: string
+ name: string
+ minAmount: number
+ maxAmount: number
+ disabled?: boolean
+ }[]
+ }
+}
+
+export const transakFiatCurrencies: Writable = writable(undefined)
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..32793943ae 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,8 +1,9 @@
-import { MarketCurrency } from '@core/market/types'
+import { FiatCurrency } from '@core/market/enums'
export interface ITransakWindowData {
- currency: MarketCurrency
+ currency: keyof typeof FiatCurrency
address: string
service: 'BUY' | 'SELL'
amount: number
+ paymentMethod: string
}
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 c546045489..7566c6f77f 100644
--- a/packages/shared/src/locales/en.json
+++ b/packages/shared/src/locales/en.json
@@ -825,6 +825,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"
}
}
},