-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sov 464 d 2 wc connect wallet button (#27)
* feat: add DisconnectSubmenu component * feat: use menu for dissconnect submenu * dissconnet menu * feat: wallet identity * feat: improve wallet Identity * resolve PR issues * resolve PR issues * Delete App.test.tsx * Update package.json * fix: DisconnectSubmenu * feat: ConnectWalletButton component * feat: wallet connection setup * feat: wallet connect button finished * fix: resolve PR issues * update @sovryn/onboard-core * fix: onboard version * fix: disable wallet connect button in pending state * chore: move WalletIdentity to ui library * chore: add WalletIdentity storybook examples * resolve: PR issues * fix: canvas test issue * chore: set startLength default prop value * test: WalletIdentity * fix: wallet identity padding * chore: remove hardcoded labels from DisconnectSubmenu (and update tests/stories) * chore: add WalletIdentity label override example in dapp code * fix: update button text color * feat: add DisconnectSubmenu component * feat: use menu for dissconnect submenu * dissconnet menu * feat: wallet identity * feat: improve wallet Identity * resolve PR issues * resolve PR issues * fix: DisconnectSubmenu * feat: ConnectWalletButton component * feat: wallet connection setup * feat: wallet connect button finished * fix: resolve PR issues * update @sovryn/onboard-core * chore: move WalletIdentity to ui library * fix: canvas test issue * test: WalletIdentity * fix: wallet identity padding * style: update dropdown colors * chore: fix package.json Co-authored-by: Victor Creed <[email protected]> Co-authored-by: Victor Creed <[email protected]> Co-authored-by: soulBit <[email protected]>
- Loading branch information
1 parent
e48c293
commit bccc22f
Showing
37 changed files
with
1,038 additions
and
284 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
Empty file.
49 changes: 49 additions & 0 deletions
49
apps/frontend/src/app/2_molecules/ConnectWalletButton/ConnectWalletButton.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,49 @@ | ||
import React, { FC, PropsWithChildren } from 'react'; | ||
|
||
import { Button } from '@sovryn/ui'; | ||
import { WalletIdentity } from '@sovryn/ui'; | ||
|
||
export type ConnectWalletButtonProps = { | ||
onConnect: () => void; | ||
onDisconnect: () => void; | ||
address: string | undefined; | ||
pending?: boolean; | ||
className?: string; | ||
dataActionId?: string; | ||
}; | ||
|
||
export const ConnectWalletButton: FC< | ||
PropsWithChildren<ConnectWalletButtonProps> | ||
> = ({ | ||
address, | ||
pending, | ||
onDisconnect, | ||
onConnect, | ||
className, | ||
dataActionId, | ||
}) => { | ||
if (!address) { | ||
return ( | ||
<Button | ||
text="Connect wallet" | ||
onClick={onConnect} | ||
className={className} | ||
dataActionId={dataActionId} | ||
disabled={pending} | ||
/> | ||
); | ||
} else { | ||
return ( | ||
<WalletIdentity | ||
onDisconnect={onDisconnect} | ||
address={address} | ||
dataActionId={dataActionId} | ||
className={className} | ||
submenuLabels={{ | ||
copyAddress: 'Copy Address', | ||
disconnect: 'Disconnect', | ||
}} | ||
/> | ||
); | ||
} | ||
}; |
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 @@ | ||
export * from './ConnectWalletButton/ConnectWalletButton'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useCallback, useEffect, useState } from 'react'; | ||
|
||
import { startWith } from 'rxjs/operators'; | ||
|
||
import { WalletState } from '@sovryn/onboard-core'; | ||
import { connectWallet$ } from '@sovryn/onboard-core/dist/streams'; | ||
|
||
import { onboard } from '../lib/connector'; | ||
|
||
export const useWalletConnect = () => { | ||
const [pending, setPending] = useState(false); | ||
const [wallets, setWallets] = useState<WalletState[]>( | ||
onboard.state.get().wallets, | ||
); | ||
|
||
const connectWallet = useCallback(() => { | ||
onboard.connectWallet(); | ||
}, []); | ||
const disconnectWallet = useCallback(async () => { | ||
await onboard.disconnectWallet(); | ||
}, []); | ||
|
||
useEffect(() => { | ||
const sub = connectWallet$ | ||
.asObservable() | ||
.subscribe(({ inProgress }) => setPending(inProgress)); | ||
return () => sub.unsubscribe(); | ||
}, []); | ||
|
||
useEffect(() => { | ||
const sub = onboard.state | ||
.select('wallets') | ||
.pipe(startWith(onboard.state.get().wallets)) | ||
.subscribe(setWallets); | ||
return () => sub.unsubscribe(); | ||
}, []); | ||
|
||
return { | ||
connectWallet, | ||
disconnectWallet, | ||
wallets, | ||
pending, | ||
}; | ||
}; |
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,15 +1,22 @@ | ||
import React from 'react'; | ||
|
||
import ReactDOM from 'react-dom/client'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
|
||
import { OnboardProvider } from '@sovryn/onboard-react'; | ||
|
||
import App from './app/5_pages/App/App'; | ||
import { onboard } from './lib/connector'; | ||
import './styles/tailwindcss/index.css'; | ||
|
||
const root = ReactDOM.createRoot( | ||
document.getElementById('root') as HTMLElement, | ||
); | ||
root.render( | ||
<React.StrictMode> | ||
<App /> | ||
<BrowserRouter> | ||
<App /> | ||
<OnboardProvider onboard={onboard} /> | ||
</BrowserRouter> | ||
</React.StrictMode>, | ||
); |
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,30 @@ | ||
import Onboard from '@sovryn/onboard-core'; | ||
import injectedModule from '@sovryn/onboard-injected'; | ||
|
||
const injected = injectedModule(); | ||
export const onboard = Onboard({ | ||
wallets: [injected], | ||
chains: [ | ||
{ | ||
id: '0x1e', | ||
rpcUrl: 'https://public-node.rsk.co', | ||
label: 'RSK', | ||
token: 'RBTC', | ||
blockExplorerUrl: 'https://explorer.rsk.co', | ||
}, | ||
{ | ||
id: '0x1', | ||
rpcUrl: 'https://cloudflare-eth.com/v1/mainnet', | ||
label: 'Ethereum Mainnet', | ||
token: 'ETH', | ||
blockExplorerUrl: 'https://etherscan.io', | ||
}, | ||
{ | ||
id: '0x1f', | ||
rpcUrl: 'https://public-node.testnet.rsk.co', | ||
label: 'RSK testnet', | ||
token: 'tRBTC', | ||
blockExplorerUrl: 'https://explorer.testnet.rsk.co', | ||
}, | ||
], | ||
}); |
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,9 @@ | ||
export const prettyTx = ( | ||
text: string, | ||
startLength: number = 6, | ||
endLength: number = 4, | ||
) => { | ||
const start = text.substr(0, startLength); | ||
const end = text.substr(-endLength); | ||
return `${start} ··· ${end}`; | ||
}; |
This file was deleted.
Oops, something went wrong.
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,4 +1,8 @@ | ||
module.exports = { | ||
presets: [require('@sovryn/tailwindcss-config/index.js')], | ||
content: ['./src/**/*.{html,ts,tsx,css}', './public/**/*.html'], | ||
content: [ | ||
'./src/**/*.{html,ts,tsx,css}', | ||
'./public/**/*.html', | ||
'../../packages/ui/src/**/*.{html,ts,tsx,css}', | ||
], | ||
}; |
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
Oops, something went wrong.