-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add event handlers to earn component
- Loading branch information
1 parent
c03cf27
commit fec9f0d
Showing
4 changed files
with
59 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,37 @@ | ||
import { AppContext } from '@/components/AppProvider'; | ||
import { Earn } from '@coinbase/onchainkit/earn'; | ||
import { useContext } from 'react'; | ||
import { Earn, LifecycleStatus } from '@coinbase/onchainkit/earn'; | ||
import { TransactionError } from '@coinbase/onchainkit/transaction'; | ||
import { useCallback, useContext } from 'react'; | ||
import { TransactionReceipt } from 'viem'; | ||
|
||
export function EarnDemo() { | ||
const { vaultAddress } = useContext(AppContext); | ||
|
||
const handleOnSuccess = useCallback( | ||
(transactionReceipt?: TransactionReceipt) => { | ||
console.log('Success: ', transactionReceipt); | ||
}, | ||
[], | ||
); | ||
|
||
const handleOnError = useCallback((earnError: TransactionError) => { | ||
console.log('Error:', earnError); | ||
}, []); | ||
|
||
const handleOnStatus = useCallback((lifecycleStatus: LifecycleStatus) => { | ||
console.log('Status:', lifecycleStatus); | ||
}, []); | ||
|
||
if (!vaultAddress) { | ||
return <div>Please set a vault address</div>; | ||
} | ||
|
||
return <Earn vaultAddress={vaultAddress} />; | ||
return ( | ||
<Earn | ||
vaultAddress={vaultAddress} | ||
onSuccess={handleOnSuccess} | ||
onError={handleOnError} | ||
onStatus={handleOnStatus} | ||
/> | ||
); | ||
} |
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