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 20106ab
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 165 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
5 changes: 2 additions & 3 deletions src/app/pages/swap/bitflow-swap-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ function BitflowSwapContainer() {
onSetSwapSubmissionData({
...swapData,
fee: satToBtc(sBtcDepositData?.fee ?? 0).toNumber(),
txData: sBtcDepositData?.deposit,
txData: { deposit: sBtcDepositData?.deposit },
});
swapNavigate(RouteUrls.SwapReview);
return;
return swapNavigate(RouteUrls.SwapReview);
}

const routeQuote = await fetchRouteQuote(
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
29 changes: 25 additions & 4 deletions src/app/pages/swap/hooks/use-sbtc-deposit-transaction.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
/* eslint-disable */
// TODO: Enable eslint and remove test logs
import { useMemo } from 'react';
import { useNavigate } from 'react-router-dom';

import * as btc from '@scure/btc-signer';
import type { P2TROut } from '@scure/btc-signer/payment';
import { MAINNET, REGTEST, SbtcApiClientTestnet, TESTNET, buildSbtcDepositTx } from 'sbtc';
import {
MAINNET,
REGTEST,
SbtcApiClient,
SbtcApiClientTestnet,
TESTNET,
buildSbtcDepositTx,
} from 'sbtc';

import type { BitcoinNetworkModes } from '@leather.io/models';
import { useAverageBitcoinFeeRates } from '@leather.io/query';
Expand All @@ -24,6 +33,7 @@ import { useCurrentNetwork } from '@app/store/networks/networks.selectors';

import type { SwapSubmissionData } from '../swap.context';

// Suggested to use as defaults
const maxSignerFee = 80_000;
const reclaimLockTime = 6_000;

Expand All @@ -35,9 +45,6 @@ interface SbtcDeposit {
trOut: P2TROut;
}

// Check network for correct client
const client = new SbtcApiClientTestnet();

function getSbtcNetworkConfig(network: BitcoinNetworkModes) {
const networkMap = {
mainnet: MAINNET,
Expand All @@ -49,6 +56,15 @@ function getSbtcNetworkConfig(network: BitcoinNetworkModes) {
return networkMap[network];
}

// TODO: Set config paths, or likely remove when defaults are published
const clientMainnet = new SbtcApiClient({
sbtcContract: '',
btcApiUrl: '',
stxApiUrl: '',
sbtcApiUrl: '',
});
const clientTestnet = new SbtcApiClientTestnet();

export function useSbtcDepositTransaction() {
const toast = useToast();
const { setIsIdle } = useLoading(LoadingKeys.SUBMIT_SWAP_TRANSACTION);
Expand All @@ -60,6 +76,11 @@ export function useSbtcDepositTransaction() {
const navigate = useNavigate();
const network = useCurrentNetwork();

const client = useMemo(
() => (network.chain.bitcoin.mode === 'mainnet' ? clientMainnet : clientTestnet),
[network]
);

// Check if the signer is compliant
useBreakOnNonCompliantEntity();

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
10 changes: 7 additions & 3 deletions src/app/query/sbtc/sbtc-deposits.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface GetSbtcDepositsResponse {
nextToken?: string;
}

// TODO: Verify this is correct for mainnet launch
const emilyUrl = 'https://beta.sbtc-emily.com/deposit';

async function getSbtcDeposits(status: string): Promise<GetSbtcDepositsResponse> {
Expand All @@ -53,17 +54,20 @@ function useGetSbtcDeposits(stxAddress: string, status: string) {
});
}

// Possibly also include status `accepted` here, but need to test when testnet is working
export function useSbtcPendingDeposits(stxAddress: string) {
const { data: pendingDeposits = [], isLoading: isLoadingStatusPending } = useGetSbtcDeposits(
stxAddress,
'pending'
);
const { data: reprocessingDeposits = [], isLoading: isLoadingStatusReprocessing } =
useGetSbtcDeposits(stxAddress, 'reprocessing');
const { data: acceptedDeposits = [], isLoading: isLoadingStatusAccepted } = useGetSbtcDeposits(
stxAddress,
'accepted'
);

return {
isLoading: isLoadingStatusPending || isLoadingStatusReprocessing,
pendingSbtcDeposits: [...pendingDeposits, ...reprocessingDeposits],
isLoading: isLoadingStatusPending || isLoadingStatusReprocessing || isLoadingStatusAccepted,
pendingSbtcDeposits: [...pendingDeposits, ...reprocessingDeposits, ...acceptedDeposits],
};
}
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
Loading

0 comments on commit 20106ab

Please sign in to comment.