From 055483ca86ebf14291158f4df189dffa5178a98a Mon Sep 17 00:00:00 2001 From: Jean Ribeiro Date: Mon, 1 Jul 2024 19:16:13 -0300 Subject: [PATCH 01/14] feat: adds MVP exchange screen in buy/sell view --- .../desktop/features/buy-sell.features.ts | 3 + .../lib/electron/managers/transak.manager.ts | 10 +- .../views/dashboard/buy-sell/BuySell.svelte | 6 + .../buy-sell/components/TokenTile.svelte | 50 +++++ .../components/TransakAccountPanel.svelte | 49 ----- .../components/TransakAmountInput.svelte | 26 +++ .../components/TransakExchangePanel.svelte | 198 ++++++++++++++++++ .../TransakWindowPlaceholder.svelte | 30 --- .../dashboard/buy-sell/components/index.ts | 5 +- .../buy-sell/views/BuySellMainView.svelte | 145 +------------ .../components/inputs/FiatAmountInput.svelte | 130 ++++++++++++ .../lib/auxiliary/transak/actions/index.ts | 2 + .../actions/updateTransakCryptoCurrencies.ts | 0 .../actions/updateTransakFiatCurrencies.ts | 24 +++ ...ransak-api-production-base-url.constant.ts | 2 +- .../transak-api-staging-base-url.constant.ts | 2 +- .../enums/transak-api-endpoint.enum.ts | 4 +- .../enums/transak-payment-option.enum.ts | 0 .../shared/src/lib/auxiliary/transak/index.ts | 4 + .../src/lib/auxiliary/transak/stores/index.ts | 2 + .../stores/transak-crypto-currencies.store.ts | 3 + .../stores/transak-fiat-currencies.store.ts | 16 ++ .../transak-window-data.interface.ts | 5 +- .../market/actions/getMarketPriceForToken.ts | 6 +- .../actions/getTokenValueFromFiatAmount.ts | 29 +++ .../src/lib/core/market/actions/index.ts | 1 + .../interfaces/feature-flag.interface.ts | 1 + packages/shared/src/locales/en.json | 4 + 28 files changed, 526 insertions(+), 231 deletions(-) create mode 100644 packages/desktop/views/dashboard/buy-sell/components/TokenTile.svelte delete mode 100644 packages/desktop/views/dashboard/buy-sell/components/TransakAccountPanel.svelte create mode 100644 packages/desktop/views/dashboard/buy-sell/components/TransakAmountInput.svelte create mode 100644 packages/desktop/views/dashboard/buy-sell/components/TransakExchangePanel.svelte delete mode 100644 packages/desktop/views/dashboard/buy-sell/components/TransakWindowPlaceholder.svelte create mode 100644 packages/shared/src/components/inputs/FiatAmountInput.svelte create mode 100644 packages/shared/src/lib/auxiliary/transak/actions/index.ts create mode 100644 packages/shared/src/lib/auxiliary/transak/actions/updateTransakCryptoCurrencies.ts create mode 100644 packages/shared/src/lib/auxiliary/transak/actions/updateTransakFiatCurrencies.ts create mode 100644 packages/shared/src/lib/auxiliary/transak/enums/transak-payment-option.enum.ts create mode 100644 packages/shared/src/lib/auxiliary/transak/stores/index.ts create mode 100644 packages/shared/src/lib/auxiliary/transak/stores/transak-crypto-currencies.store.ts create mode 100644 packages/shared/src/lib/auxiliary/transak/stores/transak-fiat-currencies.store.ts create mode 100644 packages/shared/src/lib/core/market/actions/getTokenValueFromFiatAmount.ts diff --git a/packages/desktop/features/buy-sell.features.ts b/packages/desktop/features/buy-sell.features.ts index 07735ed62c..8d2e1c259f 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: false, + }, } export default buySellFeatures 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 @@ - - - -
-
- - - - IOTA -
- -
-
- - {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 @@ + + +
+ + {currency} +
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/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')} -
diff --git a/packages/desktop/views/dashboard/buy-sell/components/TransakExchangePanel.svelte b/packages/desktop/views/dashboard/buy-sell/components/TransakExchangePanel.svelte index fd156ca64b..d03d8acf3e 100644 --- a/packages/desktop/views/dashboard/buy-sell/components/TransakExchangePanel.svelte +++ b/packages/desktop/views/dashboard/buy-sell/components/TransakExchangePanel.svelte @@ -188,7 +188,7 @@ {/if}
-
+
-
{/if} diff --git a/packages/shared/src/lib/auxiliary/transak/enums/transak-connection-status.enum.ts b/packages/shared/src/lib/auxiliary/transak/enums/transak-connection-status.enum.ts index 40cfd529c9..30d50e7289 100644 --- a/packages/shared/src/lib/auxiliary/transak/enums/transak-connection-status.enum.ts +++ b/packages/shared/src/lib/auxiliary/transak/enums/transak-connection-status.enum.ts @@ -1,5 +1,6 @@ export enum TransakConnectionStatus { Connected = 'connected', Redirected = 'redirected', + Waiting = 'waiting', Disconnected = 'disconnected', } diff --git a/packages/shared/src/locales/en.json b/packages/shared/src/locales/en.json index c729a0a0a1..0b6a918ad0 100644 --- a/packages/shared/src/locales/en.json +++ b/packages/shared/src/locales/en.json @@ -1778,7 +1778,8 @@ "saving": "Saving", "enabled": "Enabled", "disabled": "Disabled", - "networkSettings": "Network settings" + "networkSettings": "Network settings", + "waitingConnection": "Waiting connection" }, "filters":{ "title": "Filters", From 2fec83bbe0cfeef3fbcc1ce12674cd4272cea322 Mon Sep 17 00:00:00 2001 From: Jean Ribeiro Date: Tue, 16 Jul 2024 08:23:34 -0300 Subject: [PATCH 04/14] fix: select token popup changing store --- .../popup/popups/TransakSelectTokenPopup.svelte | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/desktop/components/popup/popups/TransakSelectTokenPopup.svelte b/packages/desktop/components/popup/popups/TransakSelectTokenPopup.svelte index c9f575bb54..c55342ed65 100644 --- a/packages/desktop/components/popup/popups/TransakSelectTokenPopup.svelte +++ b/packages/desktop/components/popup/popups/TransakSelectTokenPopup.svelte @@ -10,6 +10,7 @@ import { TransakCryptoCurrencyTile } from '@views/dashboard/buy-sell/components' let searchValue: string = '' + let selectedToken = $selectedExchangeCryptoCurrency const options = [ { value: 'all', label: localize('popups.transaction.allNetworks') }, @@ -56,7 +57,7 @@ if (cryptoCurrency === $selectedExchangeCryptoCurrency) { onContinueClick() } else { - $selectedExchangeCryptoCurrency = cryptoCurrency + selectedToken = cryptoCurrency } } catch (err) { handleError(err) @@ -68,6 +69,7 @@ } function onContinueClick(): void { + $selectedExchangeCryptoCurrency = selectedToken closePopup() } @@ -78,7 +80,7 @@ continueButton={{ text: localize('actions.continue'), onClick: onContinueClick, - disabled: !$selectedExchangeCryptoCurrency, + disabled: !selectedToken, }} >