-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(final): explore page and cleanup
- Loading branch information
1 parent
34f14b6
commit 58d46cb
Showing
20 changed files
with
285 additions
and
508 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,145 +1,9 @@ | ||
import { | ||
AppConfig, | ||
FinishedAuthData, | ||
UserSession, | ||
openSignatureRequestPopup, | ||
showConnect | ||
} from '@stacks/connect'; | ||
import { verifyMessageSignatureRsv } from '@stacks/encryption'; | ||
import { StacksTestnet } from '@stacks/network'; | ||
import { | ||
callReadOnlyFunction, | ||
cvToValue, | ||
getAddressFromPublicKey, | ||
uintCV | ||
} from '@stacks/transactions'; | ||
import { ReactElement, useState } from 'react'; | ||
import { ReactElement } from 'react'; | ||
|
||
import LoginPage from './pages/Login'; | ||
|
||
function App(): ReactElement { | ||
const [address, setAddress] = useState(''); | ||
const [isSignatureVerified, setIsSignatureVerified] = useState(false); | ||
const [hasFetchedReadOnly, setHasFetchedReadOnly] = useState(false); | ||
|
||
// Initialize your app configuration and user session here | ||
const appConfig = new AppConfig(['store_write', 'publish_data']); | ||
const userSession = new UserSession({ appConfig }); | ||
|
||
const message = 'Hello, Hiro Hacks!'; | ||
const network = new StacksTestnet(); | ||
|
||
// Define your authentication options here | ||
const authOptions = { | ||
userSession, | ||
appDetails: { | ||
name: 'My App', | ||
icon: 'src/favicon.svg' | ||
}, | ||
onFinish: (data: FinishedAuthData) => { | ||
// Handle successful authentication here | ||
const userData = data.userSession.loadUserData(); | ||
console.log(userData); | ||
setAddress(userData.profile.stxAddress.testnet); // or .testnet for testnet | ||
}, | ||
onCancel: () => { | ||
// Handle authentication cancellation here | ||
}, | ||
redirectTo: '/' | ||
}; | ||
|
||
const connectWallet = () => { | ||
showConnect(authOptions); | ||
}; | ||
|
||
const disconnectWallet = () => { | ||
if (userSession.isUserSignedIn()) { | ||
userSession.signUserOut('/'); | ||
setAddress(''); | ||
} | ||
}; | ||
|
||
const fetchReadOnly = async (senderAddress: string) => { | ||
// Define your contract details here | ||
const contractAddress = 'ST000000000000000000002AMW42H'; | ||
const contractName = 'pox-3'; | ||
const functionName = 'is-pox-active'; | ||
|
||
const functionArgs = [uintCV(10)]; | ||
|
||
try { | ||
const result = await callReadOnlyFunction({ | ||
network, | ||
contractAddress, | ||
contractName, | ||
functionName, | ||
functionArgs, | ||
senderAddress | ||
}); | ||
setHasFetchedReadOnly(true); | ||
console.log(cvToValue(result)); | ||
} catch (error) { | ||
console.error('Error fetching read-only function:', error); | ||
} | ||
}; | ||
|
||
const signMessage = () => { | ||
if (userSession.isUserSignedIn()) { | ||
openSignatureRequestPopup({ | ||
message, | ||
network, | ||
onFinish: async ({ publicKey, signature }) => { | ||
// Verify the message signature using the verifyMessageSignatureRsv function | ||
const verified = verifyMessageSignatureRsv({ | ||
message, | ||
publicKey, | ||
signature | ||
}); | ||
if (verified) { | ||
// The signature is verified, so now we can check if the user is a keyholder | ||
setIsSignatureVerified(true); | ||
console.log( | ||
'Address derived from public key', | ||
getAddressFromPublicKey(publicKey, network.version) | ||
); | ||
} | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
return <LoginPage />; | ||
|
||
// return ( | ||
// <div className="text-center"> | ||
// <h1 className="text-xl">Friend.tech</h1> | ||
// <div> | ||
// <button onClick={disconnectWallet}>Disconnect Wallet</button> | ||
// </div> | ||
// <div> | ||
// <p> | ||
// {address} is {isKeyHolder ? '' : 'not'} a key holder | ||
// </p> | ||
// <div> | ||
// <input | ||
// type="text" | ||
// id="address" | ||
// name="address" | ||
// placeholder="Enter address" | ||
// /> | ||
// <button onClick={() => checkIsKeyHolder(address)}> | ||
// Check Key Holder | ||
// </button> | ||
// <div> | ||
// <p>Key Holder Check Result: {isKeyHolder ? 'Yes' : 'No'}</p> | ||
// </div> | ||
// </div> | ||
// </div> | ||
// <div> | ||
// Sign this message: <button onClick={signMessage}>Sign</button> | ||
// </div> | ||
// </div> | ||
// ); | ||
} | ||
|
||
export default App; |
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 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
Oops, something went wrong.