Skip to content

Commit

Permalink
chore: merge remote-tracking branch 'origin' into feat/modify-bitcoin…
Browse files Browse the repository at this point in the history
…-loading-box
  • Loading branch information
rozanagy committed Oct 23, 2024
2 parents f0a285e + 3325abb commit d9ee77b
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 9 deletions.
5 changes: 5 additions & 0 deletions config.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
"name": "Smart Bitcoin Labs",
"addresses": ["0x46166fA874AAEDEA8d98b15F9A72C84e22Abe2A1"],
"logo": "/images/logos/sbl-logotype.svg"
},
{
"name": "Waterdrip Capital",
"addresses": ["0x2816f3528AD324E6089714DA8E89455f58739e68"],
"logo": "/images/logos/waterdrip-capital-logo.svg"
}
],
"protocols": [
Expand Down
12 changes: 12 additions & 0 deletions public/images/logos/fordefi-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 99 additions & 0 deletions public/images/logos/waterdrip-capital-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Link, Text, VStack } from '@chakra-ui/react';

export function UpdateBitcoinWalletMessage(): React.JSX.Element {
return (
<VStack
alignItems={'end'}
p={'15px'}
w={'100%'}
border={'1px dashed'}
borderRadius={'md'}
borderColor={'orange.01'}
>
<Text color={'white'} fontSize={'12px'}>
Before proceeding, please make sure your Bitcoin Wallet is up to date.
</Text>
<Text color={'white'} fontSize={'12px'}>
If you are using Ledger, ensure both the device firmware and Bitcoin App are updated to
avoid errors.
</Text>
<Text color={'white'} fontSize={'12px'}>
Use{' '}
<Link
color={'orange.01'}
href="https://support.ledger.com/article/8458939792669-zd"
isExternal
>
Ledger Live
</Link>{' '}
to update both firmware and the app easily.
</Text>
</VStack>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { BitcoinWalletType, bitcoinWallets } from '@models/wallet';
import { modalActions } from '@store/slices/modal/modal.actions';

import { SelectBitcoinWalletMenu } from './components/select-bitcoin-wallet-modal-menu';
import { UpdateBitcoinWalletMessage } from './components/update-bitcoin-wallet-message';

export function SelectBitcoinWalletModal({
isOpen,
Expand Down Expand Up @@ -47,6 +48,19 @@ export function SelectBitcoinWalletModal({
});
}
break;
case BitcoinWalletType.Fordefi:
try {
await connectUnisatWallet(true);
} catch (error: any) {
toast({
title: 'Failed to connect to Unisat Wallet',
description: error.message,
status: 'error',
duration: 9000,
isClosable: true,
});
}
break;
case BitcoinWalletType.Ledger:
dispatch(modalActions.toggleLedgerModalVisibility());
break;
Expand All @@ -66,6 +80,7 @@ export function SelectBitcoinWalletModal({
handleClick={() => handleLogin(wallet.id)}
/>
))}
<UpdateBitcoinWalletMessage />
</VStack>
</ModalLayout>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { BitcoinTransactionConfirmationsContext } from '@providers/bitcoin-query
import { BitcoinWalletContextState } from '@providers/bitcoin-wallet-context-provider';
import { useForm } from '@tanstack/react-form';
import Decimal from 'decimal.js';
import { isEmpty } from 'ramda';

import { TransactionFormNavigateButtonGroup } from './components/transaction-screen.transaction-form.navigate-button-group';
import { TransactionFormProgressStack } from './components/transaction-screen.transaction-form.progress-stack/components/transaction-screen.transaction-form.progress-stack';
Expand Down Expand Up @@ -140,7 +141,8 @@ export function VaultTransactionForm({
},
validators: {
onChange: ({ value }) => {
setCurrentFieldValue(new Decimal(value.assetAmount).toNumber());
const assetAmount = value.assetAmount;
setCurrentFieldValue(isEmpty(assetAmount) ? 0 : new Decimal(value.assetAmount).toNumber());
return {
fields: {
assetAmount: validateFormAmount(
Expand Down
1 change: 1 addition & 0 deletions src/app/hooks/use-psbt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export function usePSBT(): UsePSBTReturnType {
[BitcoinWalletType.Ledger]: isLedgerLoading,
[BitcoinWalletType.Leather]: isLeatherLoading,
[BitcoinWalletType.Unisat]: isUnisatLoading,
[BitcoinWalletType.Fordefi]: isUnisatLoading,
};

return {
Expand Down
16 changes: 11 additions & 5 deletions src/app/hooks/use-unisat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { shiftValue } from 'dlc-btc-lib/utilities';
import { BITCOIN_NETWORK_MAP } from '@shared/constants/bitcoin.constants';

interface UseUnisatReturnType {
connectUnisatWallet: () => Promise<void>;
connectUnisatWallet: (isFordefi?: boolean) => Promise<void>;
handleFundingTransaction: (
dlcHandler: SoftwareWalletDLCHandler,
vault: RawVault,
Expand Down Expand Up @@ -131,10 +131,16 @@ export function useUnisat(): UseUnisatReturnType {
*
* @returns A promise that resolves to the user's taproot address.
*/
async function getBitcoinAddresses(): Promise<BitcoinTaprootAccount> {
async function getBitcoinAddresses(isFordefi: boolean = false): Promise<BitcoinTaprootAccount> {
try {
if (!window.unisat) {
throw new UnisatError('Unisat Wallet is not installed');
throw new UnisatError(
isFordefi ? 'Fordefi Wallet is Not Installed' : 'Unisat Wallet is Not Installed'
);
} else if (isFordefi && !window?.unisat?.is_fordefi) {
throw new UnisatError('Please disable Unisat Wallet and enable Fordefi Wallet');
} else if (!isFordefi && window?.unisat?.is_fordefi) {
throw new UnisatError('Please disable Fordefi Wallet and enable Unisat Wallet');
}

const userAddresses: string[] = await window.unisat.requestAccounts();
Expand All @@ -159,11 +165,11 @@ export function useUnisat(): UseUnisatReturnType {
*
* @returns A promise that resolves to the User's Taproot Address.
*/
async function connectUnisatWallet(): Promise<void> {
async function connectUnisatWallet(isFordefi: boolean = false): Promise<void> {
try {
setIsLoading([true, 'Connecting To Unisat Wallet']);

const taprootAccount = await getBitcoinAddresses();
const taprootAccount = await getBitcoinAddresses(isFordefi);

const unisatDLCHandler = new SoftwareWalletDLCHandler(
taprootAccount.publicKey,
Expand Down
9 changes: 8 additions & 1 deletion src/shared/models/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export enum BitcoinWalletType {
Leather = 'Leather',
Ledger = 'Ledger',
Unisat = 'Unisat',
Fordefi = 'Fordefi',
}

export interface BitcoinWallet {
Expand All @@ -28,4 +29,10 @@ const unisat: BitcoinWallet = {
logo: '/images/logos/unisat-logo.svg',
};

export const bitcoinWallets: BitcoinWallet[] = [leather, ledger, unisat];
const fordefi: BitcoinWallet = {
id: BitcoinWalletType.Fordefi,
name: 'Fordefi',
logo: '/images/logos/fordefi-logo.svg',
};

export const bitcoinWallets: BitcoinWallet[] = [leather, ledger, unisat, fordefi];
5 changes: 4 additions & 1 deletion src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ export function findEthereumNetworkByName(ethereumNetworkName: string): Chain {

export function formatEvent(event: DetailedEvent): FormattedEvent {
const isMint = event.eventType === 'mint';
const date = new Date(event.timestamp * 1000);
return {
dlcBTCAmount: isMint ? event.value : -event.value,
merchant: isMint ? event.to : event.from,
txHash: event.txHash,
date: new Date(event.timestamp * 1000).toDateString(),
date: date
.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })
.replace(',', ''),
isMint,
chain: event.chain,
isCCIP: event.isCCIP,
Expand Down
2 changes: 1 addition & 1 deletion src/styles/modal-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { definePartsStyle, defineMultiStyleConfig } = createMultiStyleConfigHelpe

const baseStyle = definePartsStyle({
dialogContainer: {
top: '19.5%',
top: '10.5%',
},
dialog: {
padding: '15px',
Expand Down

0 comments on commit d9ee77b

Please sign in to comment.