Skip to content

Commit

Permalink
refactor: more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fbwoolf committed Dec 12, 2024
1 parent dbf7a7a commit 6b70e55
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 155 deletions.
2 changes: 1 addition & 1 deletion config/wallet-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"enabled": true,
"contracts": {
"mainnet": {
"address": "currently-unknown"
"address": "SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token::sbtc-token"
},
"testnet": {
"address": "SNGWPN3XDAQE673MXYXF81016M50NHF5X5PWWM70.sbtc-token::sbtc-token"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
"redux-persist": "6.0.0",
"remark-gfm": "4.0.0",
"rxjs": "7.8.1",
"sbtc": "0.2.4",
"sbtc": "0.2.5",
"style-loader": "3.3.4",
"ts-debounce": "4.0.0",
"url": "0.11.3",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export function SbtcDepositTransactionItem({ deposit }: SbtcDepositTransactionIt
openTxLink={openTxLink}
txCaption={truncateMiddle(deposit.bitcoinTxid, 4)}
txIcon={
// Replace with sBTC avatar icon
<Avatar.Root>
<Avatar.Image alt="ST" src={SbtcAvatarIconSrc} />
</Avatar.Root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function Sip10TokenAssetItem({
const { isTokenEnabled } = useManageTokens();

const { contractId, imageCanonicalUri, name, symbol } = info;
// This can be removed once an img is available directly from the sip10 token
const isSbtc = symbol === 'sBTC';

const icon = (
Expand Down
5 changes: 4 additions & 1 deletion src/app/pages/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useTotalBalance } from '@app/common/hooks/balance/use-total-balance';
import { useOnMount } from '@app/common/hooks/use-on-mount';
import { useSwitchAccountSheet } from '@app/common/switch-account/use-switch-account-sheet-context';
import { whenPageMode } from '@app/common/utils';
import { openInNewTab } from '@app/common/utils/open-in-new-tab';
import { ActivityList } from '@app/features/activity-list/activity-list';
import { FeedbackButton } from '@app/features/feedback-button/feedback-button';
import { SbtcPromoCard } from '@app/features/sbtc-promo-card/sbtc-promo-card';
Expand All @@ -27,6 +28,8 @@ import { AccountCard } from '@app/ui/components/account/account.card';
import { AccountActions } from './components/account-actions';
import { HomeTabs } from './components/home-tabs';

const leatherEarnUrl = 'https://earn.leather.io';

export function Home() {
const { decodedAuthRequest } = useOnboardingState();
const { toggleSwitchAccount } = useSwitchAccountSheet();
Expand Down Expand Up @@ -76,7 +79,7 @@ export function Home() {
>
<AccountActions />
</AccountCard>
<SbtcPromoCard mt="space.05" onClick={() => navigate('test-deposit-sbtc')} />
<SbtcPromoCard mt="space.05" onClick={() => openInNewTab(leatherEarnUrl)} />
</Box>
{whenPageMode({ full: <FeedbackButton />, popup: null })}
<HomeTabs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
import type { SwapFormValues } from '@shared/models/form.model';
import { RouteUrls } from '@shared/route-urls';

// import { bitflow } from '@shared/utils/bitflow-sdk';
import { useSwapContext } from '@app/pages/swap/swap.context';

import type { SwapAssetListProps } from './swap-asset-list';
Expand All @@ -29,13 +28,6 @@ export function useSwapAssetList({ assets, type }: SwapAssetListProps) {
const isBaseList = type === 'base';
const isQuoteList = type === 'quote';

// async function getBtcToken() {
// // const tokens = await bitflow.getAvailableTokens();
// // console.log(tokens.filter(token => token.tokenId === 'token-xbtc'));
// const result = await bitflow.getQuoteForRoute('token-stx', 'token-xbtc', 1);
// console.log(result);
// }

// Filter out selected asset from selectable assets
const selectableAssets = assets
.filter(
Expand Down Expand Up @@ -77,9 +69,8 @@ export function useSwapAssetList({ assets, type }: SwapAssetListProps) {

const onFetchQuoteAmount = useCallback(
async (baseAsset: SwapAsset, quoteAsset: SwapAsset) => {
// await getBtcToken();
const quoteAmount = await fetchQuoteAmount(baseAsset, quoteAsset, values.swapAmountBase);
// Handle race condition; make sure quote amount is 1:1 for BTC swap
// Handle race condition; make sure quote amount is 1:1
if (baseAsset.name === 'BTC') {
void setFieldValue('swapAmountQuote', values.swapAmountBase);
return;
Expand Down
14 changes: 2 additions & 12 deletions src/app/pages/swap/hooks/use-bitflow-swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,10 @@ export function useBitflowSwap() {
baseAmount: string
): Promise<RouteQuote | undefined> => {
if (!baseAmount || !base || !quote || isCrossChainSwap) return;
let baseTokenId = base.tokenId;
let quoteTokenId = quote.tokenId;
// Temporarily handle sBTC exchange rate; force as BTC
// TODO: Remove once Bitflow supports sBTC exchange rate
if (base.tokenId === 'token-sbtc') {
baseTokenId = 'token-xbtc';
}
if (quote.tokenId === 'token-sbtc') {
quoteTokenId = 'token-xbtc';
}
try {
const result = await bitflow.getQuoteForRoute(
baseTokenId,
quoteTokenId,
base.tokenId,
quote.tokenId,
Number(baseAmount)
);
if (!result.bestRoute) {
Expand Down
109 changes: 0 additions & 109 deletions src/app/pages/test-deposit-sbtc/test-deposit-sbtc.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions src/app/query/common/remote-config/remote-config.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export function useConfigBitcoinSendEnabled() {

export function useConfigSbtc() {
const config = useRemoteConfig();
// TODO: Update with new mono version
const sbtc = config?.sbtc;
const network = useCurrentNetwork();
const sbtc = config?.sbtc;

return useMemo(() => {
const displayPromoCardOnNetworks = (sbtc as any)?.showPromoLinkOnNetworks ?? [];
return {
Expand Down
3 changes: 0 additions & 3 deletions src/app/routes/app-routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import { BroadcastError } from '@app/pages/send/broadcast-error/broadcast-error'
import { sendOrdinalRoutes } from '@app/pages/send/ordinal-inscription/ordinal-routes';
import { sendCryptoAssetFormRoutes } from '@app/pages/send/send-crypto-asset-form/send-crypto-asset-form.routes';
import { bitflowSwapRoutes } from '@app/pages/swap/bitflow-swap-container';
import { TestDepositSbtc } from '@app/pages/test-deposit-sbtc/test-deposit-sbtc';
import { UnauthorizedRequest } from '@app/pages/unauthorized-request/unauthorized-request';
import { Unlock } from '@app/pages/unlock';
import { ViewSecretKey } from '@app/pages/view-secret-key/view-secret-key';
Expand Down Expand Up @@ -203,8 +202,6 @@ function useAppRoutes() {

{bitflowSwapRoutes}

<Route path="test-deposit-sbtc" element={<TestDepositSbtc />} />

{/* OnBoarding Routes */}
<Route
path={RouteUrls.Onboarding}
Expand Down
8 changes: 4 additions & 4 deletions tests/page-object-models/swap.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ export class SwapPage {
await this.page.locator('text="BTC"').click();
}

async selectSbtcAsQuoteAsset() {
async selectQuoteAsset() {
const swapAssetSelectors = await this.page.locator(this.selectAssetBtn).all();
await swapAssetSelectors[1].click();
await this.page.locator(this.chooseAssetList).waitFor();
const quoteAssets = await this.page.locator(this.chooseAssetListItem).all();
await quoteAssets[0].click();
// await this.page.locator(this.chooseAssetList).waitFor();
// const quoteAssets = await this.page.locator(this.chooseAssetListItem).all();
// await quoteAssets[0].click();
}
}
13 changes: 7 additions & 6 deletions tests/specs/swap/swap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ test.describe('Swaps', () => {
await expect(toast).toBeVisible();
});

test('that it preselects cross chain swap assets', async ({ swapPage }) => {
test('that it preselects cross chain swap assets and restricts quote list', async ({
swapPage,
}) => {
await swapPage.selectBtcAsBaseAsset();

const quoteAsset = await swapPage.page.locator('text="sBTC"').innerText();
test.expect(quoteAsset).toEqual('sBTC');

await swapPage.selectAssetToReceive();
await swapPage.selectSbtcAsQuoteAsset();

const baseAsset = await swapPage.page.locator('text="BTC"').innerText();
test.expect(baseAsset).toEqual('BTC');
await swapPage.selectQuoteAsset();
await swapPage.page.locator(swapPage.chooseAssetList).waitFor();
const quoteAssets = await swapPage.page.locator(swapPage.chooseAssetListItem).all();
test.expect(quoteAssets.length).toEqual(1);
});
});

0 comments on commit 6b70e55

Please sign in to comment.