Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/soroswap/frontend into dev/…
Browse files Browse the repository at this point in the history
…lit-collective
  • Loading branch information
MattPoblete committed Jul 18, 2024
2 parents 36a8fad + 4e7b0fe commit ab389e1
Show file tree
Hide file tree
Showing 16 changed files with 486 additions and 594 deletions.
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
"@polkadot/types": "^10.12.6",
"@reduxjs/toolkit": "^2.2.1",
"@scio-labs/use-inkathon": "^0.8.1",
"@soroban-react/chains": "9.1.8",
"@soroban-react/connect-button": "9.1.9",
"@soroban-react/contracts": "9.1.9",
"@soroban-react/core": "9.1.9",
"@soroban-react/events": "9.1.9",
"@soroban-react/freighter": "9.1.8",
"@soroban-react/hana": "^9.1.8",
"@soroban-react/lobstr": "9.1.8",
"@soroban-react/types": "9.1.8",
"@soroban-react/utils": "9.1.8",
"@soroban-react/wallet-data": "9.1.9",
"@soroban-react/xbull": "9.1.8",
"@soroban-react/chains": "9.1.12",
"@soroban-react/connect-button": "9.1.12",
"@soroban-react/contracts": "9.1.12",
"@soroban-react/core": "9.1.12",
"@soroban-react/events": "9.1.12",
"@soroban-react/freighter": "9.1.12",
"@soroban-react/hana": "9.1.12",
"@soroban-react/lobstr": "9.1.12",
"@soroban-react/types": "9.1.12",
"@soroban-react/utils": "9.1.12",
"@soroban-react/wallet-data": "9.1.12",
"@soroban-react/xbull": "9.1.12",
"@stellar/freighter-api": "1.7.1",
"@stellar/frontend-helpers": "^2.1.4",
"@stellar/stellar-sdk": "11.3.0",
Expand Down
6 changes: 3 additions & 3 deletions src/components/Bridge/BridgeAssetItem.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Asset } from 'stellar-sdk';
import { Asset } from '@stellar/stellar-sdk';
import CurrencyLogo from 'components/Logo/CurrencyLogo';
import { useGetBridgeAssetInfo } from 'hooks/bridge/pendulum/useGetBridgeAssetInfo';
import { Box, Typography } from 'soroswap-ui';
import { BridgeChains } from './BridgeComponent';
import { useGetBridgeAssetInfo } from 'hooks/bridge/pendulum/useGetBridgeAssetInfo';
import CurrencyLogo from 'components/Logo/CurrencyLogo';

export const BridgeAssetItem = ({
asset,
Expand Down
6 changes: 3 additions & 3 deletions src/components/Bridge/BridgeConfirmModal.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { Box, Modal, Typography, useTheme } from 'soroswap-ui';
import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
import { Asset } from '@stellar/stellar-sdk';
import BigNumber from 'bignumber.js';
import { useEffect, useMemo, useState } from 'react';
import { AlertTriangle, Info } from 'react-feather';
import { Asset } from 'stellar-sdk';
import { Box, Modal, Typography, useTheme } from 'soroswap-ui';

import { nativePendulumToDecimal, nativeStellarToDecimal } from 'helpers/bridge/pendulum/spacewalk';
import { useGetBridgeAssetInfo } from 'hooks/bridge/pendulum/useGetBridgeAssetInfo';
import { useSpacewalkFees } from 'hooks/bridge/pendulum/useSpacewalkFees';
import { UseBooleanReturnProps } from 'hooks/useBoolean';

import { Step, StepContent, StepLabel, Stepper } from 'soroswap-ui';
import { ButtonPrimary } from 'components/Buttons/Button';
import { CloseButton } from 'components/Buttons/CloseButton';
import { AutoColumn } from 'components/Column';
Expand All @@ -24,6 +23,7 @@ import {
import { ButtonText, SubHeaderLarge, SubHeaderSmall } from 'components/Text';
import { MouseoverTooltip } from 'components/Tooltip';
import { ConfirmedIcon } from 'components/TransactionConfirmationModal/ModalStyles';
import { Step, StepContent, StepLabel, Stepper } from 'soroswap-ui';
import BridgeAssetItem from './BridgeAssetItem';
import { BridgeChains } from './BridgeComponent';
import { ModalContentWrapper } from './BridgeSelector';
Expand Down
4 changes: 2 additions & 2 deletions src/components/Bridge/BridgeSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Modal, Typography, styled, useMediaQuery, useTheme } from 'soroswap-ui';
import { Asset } from '@stellar/stellar-sdk';
import Column from 'components/Column';
import {
Aligner,
Expand All @@ -10,7 +10,7 @@ import CurrencyLogo from 'components/Logo/CurrencyLogo';
import { RowFixed } from 'components/Row';
import { useGetBridgeAssetInfo } from 'hooks/bridge/pendulum/useGetBridgeAssetInfo';
import useBoolean from 'hooks/useBoolean';
import { Asset } from 'stellar-sdk';
import { Box, Modal, Typography, styled, useMediaQuery, useTheme } from 'soroswap-ui';
import { opacify } from 'themes/utils';
import BridgeAssetItem from './BridgeAssetItem';
import { BridgeChains } from './BridgeComponent';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Bridge/BridgeSteps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Asset } from '@stellar/stellar-sdk';
import BigNumber from 'bignumber.js';
import { BridgeChains } from './BridgeComponent';
import { Asset } from 'stellar-sdk';

export interface StepType {
label: string;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Bridge/Issue/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Box, Button, MenuItem, Select, TextField } from 'soroswap-ui';
import { useInkathon } from '@scio-labs/use-inkathon';
import { useSorobanReact } from '@soroban-react/core';
import { BASE_FEE, Memo, Operation, TransactionBuilder } from '@stellar/stellar-sdk';
import { deriveShortenedRequestId } from 'helpers/bridge/pendulum/spacewalk';
import {
convertRawHexKeyToPublicKey,
Expand All @@ -10,7 +10,7 @@ import { getEventBySectionAndMethod, getSubstrateErrors } from 'helpers/bridge/p
import { useIssuePallet } from 'hooks/bridge/pendulum/useIssuePallet';
import useSpacewalkBridge from 'hooks/bridge/pendulum/useSpacewalkBridge';
import { useCallback, useMemo, useState } from 'react';
import { BASE_FEE, Memo, Operation, TransactionBuilder } from 'stellar-sdk';
import { Box, Button, MenuItem, Select, TextField } from 'soroswap-ui';
import { BridgeButton } from '../BridgeButton';

export type IssueFormValues = {
Expand Down
109 changes: 23 additions & 86 deletions src/components/Modals/ConnectWalletModal.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import { useContext, useState, useEffect } from 'react';
import { useContext, useEffect, useState } from 'react';

import { Box, CircularProgress, Modal, useMediaQuery } from 'soroswap-ui';
import { styled, useTheme } from 'soroswap-ui';
import { useSorobanReact } from '@soroban-react/core';
import { Connector } from '@soroban-react/types';
import { ButtonPrimary } from 'components/Buttons/Button';
import { AppContext } from 'contexts';
import Image from 'next/image';
import freighterLogoBlack from '../../assets/svg/FreighterWalletBlack.svg';
import freighterLogoWhite from '../../assets/svg/FreighterWalletWhite.svg';
import ModalBox from './ModalBox';
import { ButtonPrimary } from 'components/Buttons/Button';
import { AlertCircle } from 'react-feather';

import * as Bowser from 'bowser';
import { isConnected } from '@stellar/freighter-api';
import { isConnected as isConnectedLobstr } from '@lobstrco/signer-extension-api';

import { Connector } from '@soroban-react/types';
import { hana } from '@soroban-react/hana';
import { walletConnectors } from 'soroban/MySorobanReactProvider';
import { Box, CircularProgress, Modal, styled, useMediaQuery, useTheme } from 'soroswap-ui';
import ModalBox from './ModalBox';

const Title = styled('div')`
font-size: 24px;
Expand Down Expand Up @@ -88,6 +80,15 @@ export const ConnectWalletStyles = {
FooterText,
};

const buildWalletsStatus = () => {
return walletConnectors.map((w) => ({
isInstalled: false,
isLoading: true,
name: w.id,
connector: w,
}));
};

const ConnectWalletContent = ({
isMobile,
wallets,
Expand All @@ -100,71 +101,19 @@ const ConnectWalletContent = ({
const theme = useTheme();
const { ConnectWalletModal } = useContext(AppContext);
const { setConnectWalletModalOpen } = ConnectWalletModal;
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const sorobanContext = useSorobanReact();
const { setActiveConnectorAndConnect } = sorobanContext;
const [walletsStatus, setWalletsStatus] = useState<
{ name: string; isInstalled: boolean; isLoading: boolean }[]
>([
{ name: 'freighter', isInstalled: false, isLoading: true },
{ name: 'xbull', isInstalled: false, isLoading: true },
{ name: 'lobstr', isInstalled: false, isLoading: true },
{ name: 'hana', isInstalled: false, isLoading: true },
]);
const browser = Bowser.getParser(window.navigator.userAgent).getBrowserName();
>(buildWalletsStatus());

const installWallet = (wallet: any) => {
if (wallet.id === 'freighter') {
switch (browser) {
case 'Firefox':
window.open('https://addons.mozilla.org/en-US/firefox/addon/freighter/', '_blank');
break;
default:
window.open(
'https://chromewebstore.google.com/detail/freighter/bcacfldlkkdogcmkkibnjlakofdplcbk',
'_blank',
);
break;
}
} else if (wallet.id === 'xbull') {
switch (browser) {
case 'Firefox':
window.open('https://addons.mozilla.org/es/firefox/addon/xbull-wallet/', '_blank');
break;
default:
window.open(
'https://chromewebstore.google.com/detail/xbull-wallet/omajpeaffjgmlpmhbfdjepdejoemifpe',
'_blank',
);
break;
}
} else if (wallet.id === 'lobstr') {
switch (browser) {
default:
window.open(
'https://chromewebstore.google.com/detail/lobstr-signer-extension/ldiagbjmlmjiieclmdkagofdjcgodjle',
'_blank',
);
break;
}
} else if (wallet.id === 'hana') {
switch (browser) {
default:
window.open(
'https://chromewebstore.google.com/detail/hana-wallet/jfdlamikmbghhapbgfoogdffldioobgl',
'_blank',
);
break;
}
}
setTimeout(() => {
window.location.reload();
}, 30000);
const installWallet = (wallet: Connector) => {
window.open(wallet.downloadUrls?.browserExtension, '_blank');
};

const connectWallet = async (wallet: Connector) => {
try {
await setActiveConnectorAndConnect?.(wallet);
setActiveConnectorAndConnect?.(wallet);
setConnectWalletModalOpen(false);
} catch (err) {
const errorMessage = `${err}`;
Expand Down Expand Up @@ -193,26 +142,14 @@ const ConnectWalletContent = ({

useEffect(() => {
const newWalletsStatus = walletsStatus.map(async (walletStatus) => {
if (walletStatus.name === 'freighter') {
const freighterConnector = sorobanContext.connectors.find((c) => c.id === 'freighter');
const connected = await freighterConnector?.isConnected();
return { name: walletStatus.name, isInstalled: connected, isLoading: false };
}
if (walletStatus.name === 'xbull') {
if ((window as any).xBullSDK) {
return { name: walletStatus.name, isInstalled: true, isLoading: false };
}
}
if (walletStatus.name === 'lobstr') {
const connected = await isConnectedLobstr();
const contextConnector = sorobanContext.connectors.find((c) => c.id === walletStatus.name);

return { name: walletStatus.name, isInstalled: connected, isLoading: false };
}
if (walletStatus.name === 'hana') {
const connected = hana().isConnected();
if (contextConnector) {
let connected = await contextConnector.isConnected();

return { name: walletStatus.name, isInstalled: connected, isLoading: false };
}

return { ...walletStatus, isLoading: false };
});

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/bridge/pendulum/spacewalk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { ApiPromise } from '@polkadot/api';
import { UInt, u128 } from '@polkadot/types';
import type { Enum, Struct, u8 } from '@polkadot/types-codec';
import { U8aFixed } from '@polkadot/types-codec';
import { Asset, Keypair } from '@stellar/stellar-sdk';
import { TenantName } from 'BridgeStateProvider/models';
import BigNumber from 'bignumber.js';
import bs58 from 'bs58';
import { SpacewalkCodeToSymbol, SpacewalkStellarAssetType } from 'hooks/bridge/pendulum/useSpacewalkVaults';
import { DateTime } from 'luxon';
import { Asset, Keypair } from 'stellar-sdk';
import { convertRawHexKeyToPublicKey } from './stellar';

interface SpacewalkPrimitivesCurrencyId extends Enum {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/bridge/pendulum/stellar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Asset, Keypair, StrKey } from '@stellar/stellar-sdk';
import BigNumber from 'bignumber.js';
import { Buffer } from 'buffer';
import { Asset, Keypair, StrKey } from 'stellar-sdk';

// Applying this assignment to the global object here - because Buffer is used only in this file. If Buffer is to be used in several places - it should be added to the global object in the entry file of the application.
// Ref: https://github.com/pendulum-chain/portal/issues/344
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/bridge/pendulum/useGetBridgeAssetInfo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Asset } from 'stellar-sdk';
import { BridgeChains } from 'components/Bridge/BridgeComponent';
import { useSorobanReact } from '@soroban-react/core';
import { SpacewalkCodeToSymbol } from './useSpacewalkVaults';
import { Asset } from '@stellar/stellar-sdk';
import { BridgeChains } from 'components/Bridge/BridgeComponent';
import { useAllTokens } from 'hooks/tokens/useAllTokens';
import { SpacewalkCodeToSymbol } from './useSpacewalkVaults';

interface UseGetAssetInfoProps {
asset: Asset | undefined;
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/bridge/pendulum/useIssueHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import {

import { useInkathon } from '@scio-labs/use-inkathon';
import { useSorobanReact } from '@soroban-react/core';
import { Asset, BASE_FEE, Memo, Operation, TransactionBuilder } from '@stellar/stellar-sdk';
import BigNumber from 'bignumber.js';
import { IssueStepsByKeys, StepKeys } from 'components/Bridge/BridgeSteps';
import { deriveShortenedRequestId } from 'helpers/bridge/pendulum/spacewalk';
import { getEventBySectionAndMethod, getSubstrateErrors } from 'helpers/bridge/pendulum/substrate';
import { useIssuePallet } from 'hooks/bridge/pendulum/useIssuePallet';
import { useCallback, useMemo, useState } from 'react';
import { Asset, BASE_FEE, Memo, Operation, TransactionBuilder } from 'stellar-sdk';
import { VaultId } from './useSpacewalkVaults';
import { UseStepperState } from './useModalStepper';
import { StepKeys, IssueStepsByKeys } from 'components/Bridge/BridgeSteps';
import { VaultId } from './useSpacewalkVaults';
interface Props {
amount: string;
selectedAsset: Asset | undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/bridge/pendulum/useRedeemHandler.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useInkathon } from '@scio-labs/use-inkathon';
import { useSorobanReact } from '@soroban-react/core';
import { Asset } from '@stellar/stellar-sdk';
import BigNumber from 'bignumber.js';
import { decimalToStellarNative, isPublicKey } from 'helpers/bridge/pendulum/stellar';
import { getEventBySectionAndMethod, getSubstrateErrors } from 'helpers/bridge/pendulum/substrate';
import { useRedeemPallet } from 'hooks/bridge/pendulum/useRedeemPallet';
import { useCallback, useMemo, useState } from 'react';
import { Asset } from 'stellar-sdk';
import { VaultId } from './useSpacewalkVaults';

interface Props {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/bridge/pendulum/useSpacewalkBridge.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useSorobanReact } from '@soroban-react/core';
import { Asset } from '@stellar/stellar-sdk';
import { TenantName } from 'BridgeStateProvider/models';
import { convertCurrencyToStellarAsset, shouldFilterOut } from 'helpers/bridge/pendulum/spacewalk';
import { stringifyStellarAsset } from 'helpers/bridge/pendulum/stellar';
import _ from 'lodash-es';
import { Dispatch, SetStateAction, useEffect, useMemo, useState } from 'react';
import { Asset } from 'stellar-sdk';
import {
ExtendedSpacewalkVault,
SpacewalkCodeToSymbol,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useGetMyBalances.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { SorobanContextType, useSorobanReact } from '@soroban-react/core';
import { BASE_FEE } from '@stellar/stellar-sdk';
import { AccountResponse } from '@stellar/stellar-sdk/lib/horizon';
import BigNumber from 'bignumber.js';
import { TokenType } from 'interfaces';
import { useCallback } from 'react';
import { BASE_FEE } from 'stellar-sdk';
import useSWRImmutable from 'swr/immutable';
import { useAllTokens } from './tokens/useAllTokens';
import { tokenBalances } from './useBalances';
Expand Down
4 changes: 2 additions & 2 deletions src/soroban/MySorobanReactProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const activeChainName = process.env.NEXT_PUBLIC_DEFAULT_NETWORK || 'testnet';
const activeChain: WalletChain = findWalletChainByName(activeChainName) || testnet;

// Set allowed connectors
const connectors: Connector[] = [freighter(), xbull(), lobstr(), hana()];
export const walletConnectors: Connector[] = [freighter(), xbull(), lobstr(), hana()];

export default function MySorobanReactProvider({
children,
Expand All @@ -39,7 +39,7 @@ export default function MySorobanReactProvider({
<SorobanReactProvider
chains={chains}
appName={'Soroswap'}
connectors={connectors}
connectors={walletConnectors}
activeChain={activeChain}
{...rest}
>
Expand Down
Loading

0 comments on commit ab389e1

Please sign in to comment.