forked from FuelLabs/fuels-wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create connection request screen (FuelLabs#156)
- Loading branch information
1 parent
89fecff
commit bf9a4b5
Showing
14 changed files
with
181 additions
and
36 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
1 change: 1 addition & 0 deletions
1
packages/app/src/systems/CRX/background/services/BackgroundService.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
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
40 changes: 40 additions & 0 deletions
40
packages/app/src/systems/DApp/pages/ConnectionRequest/ConnectionRequest.stories.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,40 @@ | ||
import type { Meta, Story } from '@storybook/react'; | ||
import { graphql } from 'msw'; | ||
|
||
import { ConnectionRequest } from './ConnectionRequest'; | ||
|
||
import { AccountService, MOCK_ACCOUNTS } from '~/systems/Account'; | ||
import { MOCK_ASSETS_NODE } from '~/systems/Asset/__mocks__/assets'; | ||
|
||
export default { | ||
component: ConnectionRequest, | ||
title: 'DApp/Pages/ConnectionRequest', | ||
parameters: { | ||
layout: 'fullscreen', | ||
viewport: { | ||
defaultViewport: 'chromeExtension', | ||
}, | ||
}, | ||
loaders: [ | ||
async () => { | ||
await AccountService.clearAccounts(); | ||
await AccountService.addAccount({ data: MOCK_ACCOUNTS[0] }); | ||
return {}; | ||
}, | ||
], | ||
} as Meta; | ||
|
||
export const Usage: Story<unknown> = () => <ConnectionRequest />; | ||
Usage.parameters = { | ||
msw: [ | ||
graphql.query('getBalances', (req, res, ctx) => { | ||
return res( | ||
ctx.data({ | ||
balances: { | ||
edges: MOCK_ASSETS_NODE, | ||
}, | ||
}) | ||
); | ||
}), | ||
], | ||
}; |
100 changes: 100 additions & 0 deletions
100
packages/app/src/systems/DApp/pages/ConnectionRequest/ConnectionRequest.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,100 @@ | ||
import { cssObj } from '@fuel-ui/css'; | ||
import { Button, Card, Flex, Icon, Link, List, Text } from '@fuel-ui/react'; | ||
import { useCallback } from 'react'; | ||
|
||
import { useAccount } from '~/systems/Account'; | ||
import { Layout } from '~/systems/Core'; | ||
import { TopBarType } from '~/systems/Core/components/Layout/TopBar'; | ||
import { ConnectInfo } from '~/systems/DApp'; | ||
|
||
const PERMISSION_LIST = [ | ||
'View your wallet address', | ||
'Request transactions approval', | ||
'Request message signature', | ||
'Read your transactions history', | ||
]; | ||
const NOT_ALLOWED_LIST = ['View your private keys']; | ||
|
||
export function ConnectionRequest() { | ||
const { account, isLoading } = useAccount(); | ||
const origin = 'dapp.com'; | ||
const authorize = useCallback((accounts: Array<string>) => { | ||
// eslint-disable-next-line no-console | ||
console.log(accounts); | ||
}, []); | ||
|
||
if (!account) return null; | ||
|
||
return ( | ||
<Layout title="Connection Request" isLoading={isLoading}> | ||
<Layout.TopBar type={TopBarType.external} /> | ||
<Layout.Content css={styles.content}> | ||
<ConnectInfo origin={origin} account={account} /> | ||
<Card css={styles.connectionDetails}> | ||
<Text as="h2" color="gray12" css={{ mb: '$2' }}> | ||
This site will be able to: | ||
</Text> | ||
<List icon={Icon.is('Check')} iconColor="accent9"> | ||
{PERMISSION_LIST.map((permission) => ( | ||
<List.Item css={styles.listItem} key={permission}> | ||
{permission} | ||
</List.Item> | ||
))} | ||
</List> | ||
<List icon={Icon.is('X')} iconColor="red10"> | ||
{NOT_ALLOWED_LIST.map((permission) => ( | ||
<List.Item css={styles.listItem} key={permission}> | ||
{permission} | ||
</List.Item> | ||
))} | ||
</List> | ||
</Card> | ||
<Flex css={{ flex: '1 0' }} justify="center" align={'flex-end'}> | ||
<Text fontSize="sm" as={'h2'} className="warning"> | ||
Only connect with sites you trust.{' '} | ||
<Link href="#" color="accent11"> | ||
Learn more | ||
</Link> | ||
. | ||
</Text> | ||
</Flex> | ||
</Layout.Content> | ||
<Layout.BottomBar> | ||
<Button color="gray" variant="ghost"> | ||
Reject | ||
</Button> | ||
<Button | ||
type="submit" | ||
color="accent" | ||
onPress={() => authorize([account.address])} | ||
> | ||
Connect | ||
</Button> | ||
</Layout.BottomBar> | ||
</Layout> | ||
); | ||
} | ||
|
||
const styles = { | ||
listItem: cssObj({ | ||
fontSize: '$sm', | ||
}), | ||
content: cssObj({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
paddingBottom: '$0', | ||
'& h2': { | ||
fontSize: '$sm', | ||
}, | ||
'& a': { | ||
fontSize: '$sm', | ||
fontWeight: '$bold', | ||
}, | ||
}), | ||
connectionDetails: cssObj({ | ||
marginTop: '$4', | ||
px: '$3', | ||
paddingTop: '$2', | ||
paddingBottom: '$4', | ||
}), | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/app/src/systems/DApp/pages/ConnectionRequest/index.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 @@ | ||
export * from './ConnectionRequest'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './ConnectionRequest'; | ||
export * from './SignatureRequest'; | ||
export * from './TxApprove'; |
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