-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
96 additions
and
21 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
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,48 @@ | ||
import { useCallback, useEffect, useState } from "react"; | ||
import { SubscribeButton } from "./Wallet.styles"; | ||
import { useConnection } from "hooks"; | ||
|
||
const Web3Subscribe = () => { | ||
const { wallet } = useConnection(); | ||
const [isCBWallet, setIsCBWallet] = useState(false); | ||
const [isSubscribed, setISubscribed] = useState<boolean>(false); | ||
const [isLoading, setIsLoading] = useState<boolean>(true); | ||
|
||
const handleSubscribe = useCallback(() => { | ||
if (isCBWallet) { | ||
(window as any).CBWSubscribe.toggleSubscription(); | ||
} | ||
}, [isCBWallet]); | ||
|
||
// Check if CBWallet is available | ||
useEffect(() => { | ||
setIsCBWallet(wallet?.label === "Coinbase Wallet"); | ||
}, [wallet]); | ||
|
||
useEffect(() => { | ||
(window as any).CBWSubscribe.createSubscriptionUI({ | ||
partnerAddress: "0x7765007Ef1b9B75378F481613D842Fd7613e26f2", | ||
partnerName: "Across Protocol", | ||
modalTitle: "Subscribe to Across", | ||
modalBody: "Subscribe to Across to receive updates and notifications.", | ||
onSubscriptionChange: setISubscribed, | ||
onLoading: setIsLoading, | ||
}); | ||
}, []); | ||
|
||
const subscribeButtonText = isLoading | ||
? "Loading..." | ||
: isSubscribed | ||
? "Unsubscribe" | ||
: "Subscribe"; | ||
|
||
return isCBWallet ? ( | ||
<SubscribeButton onClick={handleSubscribe}> | ||
{subscribeButtonText} | ||
</SubscribeButton> | ||
) : ( | ||
<></> | ||
); | ||
}; | ||
|
||
export default Web3Subscribe; |