-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from lidofinance/feature/metamask-and-injecte…
…d-adapters MetaMask and Browser Extension wallet adapters
- Loading branch information
Showing
76 changed files
with
787 additions
and
539 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/connect-wallet-modal/src/components/WalletsModal/WalletsModalForEth.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from 'react'; | ||
import { useReefKnotContext } from '@reef-knot/core-react'; | ||
import { | ||
ConnectInjected, | ||
ConnectLedger, | ||
ConnectWC, | ||
ConnectCoinbase, | ||
ConnectBrowser, | ||
} from '../../connectButtons'; | ||
import { WalletsModal } from './WalletsModal'; | ||
import type { ButtonComponentsByConnectorId, WalletsModalProps } from './types'; | ||
|
||
const buttonComponentsByConnectorId: ButtonComponentsByConnectorId = { | ||
default: ConnectInjected, // fallback | ||
browserExtension: ConnectBrowser, | ||
walletConnect: ConnectWC, | ||
coinbaseWallet: ConnectCoinbase, | ||
ledgerHID: ConnectLedger, | ||
}; | ||
|
||
type WalletsModalForEthProps = Omit< | ||
WalletsModalProps, | ||
'buttonComponentsByConnectorId' | 'walletDataList' | ||
>; | ||
|
||
export function WalletsModalForEth(props: WalletsModalForEthProps) { | ||
const { walletDataList } = useReefKnotContext(); | ||
|
||
return ( | ||
<WalletsModal | ||
{...props} | ||
walletDataList={walletDataList} | ||
buttonComponentsByConnectorId={buttonComponentsByConnectorId} | ||
/> | ||
); | ||
} |
64 changes: 64 additions & 0 deletions
64
packages/connect-wallet-modal/src/components/WalletsModal/getWalletsButtons.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from 'react'; | ||
import { | ||
ButtonComponentsByConnectorId, | ||
ButtonsCommonProps, | ||
WalletsModalProps, | ||
} from './types'; | ||
import { WalletAdapterData } from '@reef-knot/types'; | ||
|
||
export function addWalletTo( | ||
walletsList: string[], | ||
walletId: string, | ||
condition: boolean, // meant to be a wallet-detector function result | ||
) { | ||
// If condition is true (usually means that a wallet is detected), | ||
// move it to the first place in the wallets list, so a user can see it right away | ||
if (condition) { | ||
walletsList.unshift(walletId); | ||
} else { | ||
walletsList.push(walletId); | ||
} | ||
} | ||
|
||
export function getWalletsButtons({ | ||
commonProps, | ||
buttonComponentsByConnectorId, | ||
walletDataList = [], | ||
hiddenWallets = [], | ||
}: { | ||
commonProps: ButtonsCommonProps; | ||
buttonComponentsByConnectorId: ButtonComponentsByConnectorId; | ||
walletDataList: WalletAdapterData[]; | ||
hiddenWallets: WalletsModalProps['hiddenWallets']; | ||
}) { | ||
let wallets: string[] = []; | ||
|
||
walletDataList.forEach((walletData) => { | ||
const { walletId, detector } = walletData; | ||
addWalletTo(wallets, walletId, !!detector?.()); | ||
}); | ||
|
||
wallets = [...wallets].filter( | ||
// Filtering wallets marked as hidden | ||
(wallet) => !hiddenWallets.includes(wallet), | ||
); | ||
|
||
return wallets.map((walletId) => { | ||
// Handle new wallet adapters | ||
const walletData = walletDataList.find( | ||
(data) => data.walletId === walletId, | ||
); | ||
if (!walletData) throw 'walletData is not found in the walletDataList'; | ||
const connectorId = walletData.connector.id; | ||
|
||
const component = | ||
buttonComponentsByConnectorId[connectorId] ?? | ||
buttonComponentsByConnectorId.default; | ||
|
||
return React.createElement(component, { | ||
key: walletId, | ||
...commonProps, | ||
...walletData, | ||
}); | ||
}); | ||
} |
1 change: 1 addition & 0 deletions
1
packages/connect-wallet-modal/src/components/WalletsModal/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './WalletsModal'; | ||
export * from './WalletsModalForEth'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.