Skip to content

Commit

Permalink
Merge pull request #771 from haqq-network/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
olegshilov authored Apr 2, 2024
2 parents bd51090 + d432992 commit fa834f2
Show file tree
Hide file tree
Showing 20 changed files with 1,481 additions and 1,740 deletions.
15 changes: 14 additions & 1 deletion apps/haqq-website/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const viewport: Viewport = {

const PostHogPageView = dynamic(
async () => {
const { PostHogPageView } = await import('../utils/posthog-page-view');
const { PostHogPageView } = await import('../components/posthog-page-view');
return { default: PostHogPageView };
},
{
Expand All @@ -46,13 +46,26 @@ const DynamicLinkRedirect = dynamic(
},
);

const IdentifyWalletUsers = dynamic(
async () => {
const { IdentifyWalletUsers } = await import(
'../components/identify-wallet-users'
);
return { default: IdentifyWalletUsers };
},
{
ssr: false,
},
);

export default function RootLayout({ children }: PropsWithChildren) {
return (
<html lang="en" className="ltr" dir="ltr" translate="no">
<PHProvider>
<body className="will-change-scroll">
<PostHogPageView />
<DynamicLinkRedirect />
<IdentifyWalletUsers />

{children}

Expand Down
33 changes: 33 additions & 0 deletions apps/haqq-website/components/identify-wallet-users.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use client';
import { useEffect } from 'react';
import { usePostHog } from 'posthog-js/react';
import type { WindowProvider } from 'wagmi';

declare global {
interface Window {
ethereum?: WindowProvider;
__HAQQWALLET__?: {
POSTHOG_DISTINCT_ID?: string;
};
}
}

export function IdentifyWalletUsers() {
const posthog = usePostHog();

useEffect(() => {
if (typeof window !== 'undefined') {
const isHaqqWallet = Boolean(window.ethereum?.isHaqqWallet);

if (isHaqqWallet) {
const distinctId =
window.__HAQQWALLET__?.POSTHOG_DISTINCT_ID ??
posthog.get_distinct_id();

posthog.identify(distinctId);
}
}
}, [posthog]);

return null;
}
18 changes: 17 additions & 1 deletion apps/islamic-website/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ async function getMessages(locale: string) {

const PostHogPageView = dynamic(
async () => {
const { PostHogPageView } = await import('../../utils/posthog-page-view');
const { PostHogPageView } = await import(
'../../components/posthog-page-view'
);
return { default: PostHogPageView };
},
{
Expand All @@ -65,6 +67,18 @@ const PostHogPageView = dynamic(
},
);

const IdentifyWalletUsers = dynamic(
async () => {
const { IdentifyWalletUsers } = await import(
'../../components/identify-wallet-users'
);
return { default: IdentifyWalletUsers };
},
{
ssr: false,
},
);

export default async function LocaleLayout({
children,
params: { locale },
Expand Down Expand Up @@ -108,6 +122,8 @@ export default async function LocaleLayout({
<PHProvider>
<body className="bg-islamic-bg-black font-alexandria flex min-h-screen flex-col text-white antialiased">
<PostHogPageView />
<IdentifyWalletUsers />

{isScamBannerShow && <ScamBanner />}
{isMobileUserAgent ? (
<MobileHeader
Expand Down
8 changes: 6 additions & 2 deletions apps/islamic-website/components/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,11 @@ export function MobileHeader({
<div className="leading-[0]">
<div className="flex flex-row items-center gap-[12px]">
{isBuyButtonVisible && (
<Link href="/markets" className="leading-[0]">
<Link
href="/markets"
className="leading-[0]"
data-attr="buy-islm"
>
<Button className="!h-[36px] !px-[16px] !py-[4px] !text-[14px] !leading-[28px]">
Buy ISLM
</Button>
Expand Down Expand Up @@ -507,7 +511,7 @@ export function DesktopHeader({
</HeaderDropdown>

{isBuyButtonVisible && (
<Link href="/markets" className="ml-[8px]">
<Link href="/markets" className="ml-[8px]" data-attr="buy-islm">
<Button>Buy ISLM</Button>
</Link>
)}
Expand Down
33 changes: 33 additions & 0 deletions apps/islamic-website/components/identify-wallet-users.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use client';
import { useEffect } from 'react';
import { usePostHog } from 'posthog-js/react';
import type { WindowProvider } from 'wagmi';

declare global {
interface Window {
ethereum?: WindowProvider;
__HAQQWALLET__?: {
POSTHOG_DISTINCT_ID?: string;
};
}
}

export function IdentifyWalletUsers() {
const posthog = usePostHog();

useEffect(() => {
if (typeof window !== 'undefined') {
const isHaqqWallet = Boolean(window.ethereum?.isHaqqWallet);

if (isHaqqWallet) {
const distinctId =
window.__HAQQWALLET__?.POSTHOG_DISTINCT_ID ??
posthog.get_distinct_id();

posthog.identify(distinctId);
}
}
}, [posthog]);

return null;
}
4 changes: 1 addition & 3 deletions apps/shell/src/components/app-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,8 @@ export function AppWrapper({ children }: PropsWithChildren) {

useEffect(() => {
if (isHaqqWallet) {
const distinctId = posthog.get_distinct_id();
const walletDistinctId = window.__HAQQWALLET__?.POSTHOG_DISTINCT_ID;

posthog.identify(walletDistinctId ?? distinctId);
posthog.identify(walletDistinctId ?? posthog.get_distinct_id());
}
}, [posthog, isHaqqWallet]);

Expand Down
10 changes: 7 additions & 3 deletions libs/haqq-website/wallet-page/src/lib/hero-block/hero-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export function HeroBlock() {
href={appStoreLink}
target="_blank"
rel="noopener noreferrer"
data-attr="download-ios"
>
<WalletDownloadButton type="apple" isAvailable />
</Link>
Expand All @@ -201,6 +202,7 @@ export function HeroBlock() {
href={playMarketLink}
target="_blank"
rel="noopener noreferrer"
data-attr="download-android"
>
<WalletDownloadButton type="google" isAvailable />
</Link>
Expand All @@ -212,6 +214,7 @@ export function HeroBlock() {
target="_blank"
rel="noopener noreferrer"
className="inline-block"
data-attr="download-apk"
download
>
<WalletDownloadButton type="apk" isAvailable />
Expand All @@ -226,8 +229,8 @@ export function HeroBlock() {
href={appStoreLink}
target="_blank"
rel="noopener noreferrer"
download
className="inline-block"
data-attr="download-ios"
>
<WalletDownloadWithQrButton
link={appStoreLink}
Expand All @@ -242,8 +245,8 @@ export function HeroBlock() {
href={playMarketLink}
target="_blank"
rel="noopener noreferrer"
download
className="inline-block"
data-attr="download-android"
>
<WalletDownloadWithQrButton
link={playMarketLink}
Expand All @@ -257,8 +260,9 @@ export function HeroBlock() {
href="https://github.com/haqq-network/haqq-wallet/releases/latest/download/haqq.apk"
target="_blank"
rel="noopener noreferrer"
download
className="inline-block"
data-attr="download-apk"
download
>
<WalletDownloadButton type="apk" isAvailable />
</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ export function WalletDownloadButton({
title?: string;
}) {
return (
<div
<span
className={clsx(
'group flex w-fit min-w-[172px] select-none items-center justify-center gap-x-[8px] rounded-xl px-[24px] py-[10px]',
'cursor-pointer bg-white text-[#2F2F2F]',
className,
)}
>
<div className="group-hover:text-islamic-primary-green group-hover:transition-colors group-hover:duration-300">
<span className="group-hover:text-islamic-primary-green group-hover:transition-colors group-hover:duration-300">
{type === 'apple' && <AppStoreLogoIcon />}
{type === 'google' && <GooglePlayLogoIcon />}
{type === 'apk' && <AndroidLogoIcon />}
</div>
<div className="flex flex-col text-start">
</span>
<span className="flex flex-col text-start">
<span className="group-hover:text-islamic-primary-green/50 text-[10px] leading-[12px] text-[#8E8E8E] group-hover:transition-colors group-hover:duration-300">
{title && title}
</span>
Expand All @@ -36,7 +36,7 @@ export function WalletDownloadButton({
{type === 'google' && 'Google Play'}
{type === 'apk' && 'Download .apk'}
</span>
</div>
</div>
</span>
</span>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function WalletPage() {
href="https://apps.apple.com/app/haqq-wallet-by-bored-gen/id6443843352"
target="_blank"
rel="noopener noreferrer"
data-attr="download-ios"
>
<WalletDownloadButton
type="apple"
Expand All @@ -50,6 +51,7 @@ export function WalletPage() {
href="https://play.google.com/store/apps/details?id=com.haqq.wallet"
target="_blank"
rel="noopener noreferrer"
data-attr="download-android"
>
<WalletDownloadButton
type="google"
Expand All @@ -63,6 +65,7 @@ export function WalletPage() {
target="_blank"
rel="noopener noreferrer"
download
data-attr="download-apk"
>
<WalletDownloadButton type="apk" />
</Link>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';
import { useCallback, useEffect, useRef, useState } from 'react';
import Link from 'next/link';
import { usePostHog } from 'posthog-js/react';
import { useNetwork } from 'wagmi';
import { getChainParams } from '@haqq/data-access-cosmos';
import { type EstimatedFeeResponse } from '@haqq/data-access-falconer';
Expand Down Expand Up @@ -60,9 +61,12 @@ export function DelegateModalHooked({
const toast = useToast();
const cancelPreviousRequest = useRef<(() => void) | null>(null);
const throttledDelegateAmount = useThrottle(delegateAmount, 300);
const posthog = usePostHog();

const handleSubmitDelegate = useCallback(async () => {
try {
posthog.capture('delegate started');

setDelegateEnabled(false);
const delegationPromise = delegate(
validatorAddress,
Expand All @@ -76,6 +80,7 @@ export function DelegateModalHooked({
success: (tx) => {
console.log('Delegation successful', { tx });
const txHash = tx?.txhash;
posthog.capture('delegate success');

return (
<ToastSuccess>
Expand All @@ -97,6 +102,7 @@ export function DelegateModalHooked({
);
},
error: (error) => {
posthog.capture('delegate failed');
return <ToastError>{error.message}</ToastError>;
},
});
Expand All @@ -111,10 +117,11 @@ export function DelegateModalHooked({
validatorAddress,
delegateAmount,
balance,
fee,
toast,
onClose,
posthog,
explorer.cosmos,
fee,
]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { Validator } from '@evmos/provider';
import Link from 'next/link';
import { usePostHog } from 'posthog-js/react';
import { useNetwork } from 'wagmi';
import { getChainParams } from '@haqq/data-access-cosmos';
import { type EstimatedFeeResponse } from '@haqq/data-access-falconer';
Expand Down Expand Up @@ -60,10 +61,12 @@ export function RedelegateModalHooked({
);
const cancelPreviousRequest = useRef<(() => void) | null>(null);
const throttledRedelegateAmount = useThrottle(redelegateAmount, 300);
const posthog = usePostHog();

const handleSubmitRedelegate = useCallback(async () => {
try {
if (validatorDestinationAddress && validatorAddress) {
posthog.capture('redelegate started');
setRedelegateEnabled(false);
const redelegationPromise = redelegate(
validatorAddress,
Expand All @@ -78,6 +81,7 @@ export function RedelegateModalHooked({
success: (tx) => {
console.log('Redelegation successful', { tx });
const txHash = tx?.txhash;
posthog.capture('redelegate success');

return (
<ToastSuccess>
Expand All @@ -99,6 +103,7 @@ export function RedelegateModalHooked({
);
},
error: (error) => {
posthog.capture('redelegate failed');
return <ToastError>{error.message}</ToastError>;
},
});
Expand All @@ -112,6 +117,7 @@ export function RedelegateModalHooked({
}, [
validatorDestinationAddress,
validatorAddress,
posthog,
redelegate,
redelegateAmount,
balance,
Expand Down
Loading

0 comments on commit fa834f2

Please sign in to comment.