Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/app/(mobile-ui)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { twMerge } from 'tailwind-merge'
import '../../styles/globals.css'
import SupportDrawer from '@/components/Global/SupportDrawer'
import { useSupportModalContext } from '@/context/SupportModalContext'
import { useRouter } from 'next/navigation'

// Allow access to some public paths without authentication
const publicPathRegex = /^\/(request\/pay|claim|pay\/.+$|support)/
Expand All @@ -34,6 +35,7 @@ const Layout = ({ children }: { children: React.ReactNode }) => {
const isHistory = pathName === '/history'
const isSupport = pathName === '/support'
const alignStart = isHome || isHistory || isSupport
const router = useRouter()

useEffect(() => {
// check for JWT token
Expand Down Expand Up @@ -77,6 +79,12 @@ const Layout = ({ children }: { children: React.ReactNode }) => {
// Allow access to public paths without authentication
const isPublicPath = publicPathRegex.test(pathName)

useEffect(() => {
if (!isPublicPath && !isFetchingUser && !user) {
router.push('/setup')
}
}, [user, isFetchingUser])

if (!isReady || (isFetchingUser && !user && !hasToken && !isPublicPath)) {
return (
<div className="flex h-[100dvh] w-full flex-col items-center justify-center">
Expand Down
13 changes: 9 additions & 4 deletions src/app/actions/claimLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getPublicClient, type ChainId } from '@/app/actions/clients'
import { fetchTokenDetails } from '@/app/actions/tokens'
import { getLinkFromReceipt, fetchWithSentry, jsonParse } from '@/utils'
import { PEANUT_API_URL, PEANUT_WALLET_CHAIN } from '@/constants'
import type { SendLink } from '@/services/services.types'

export const getLinkDetails = unstable_cache(
async (link: string): Promise<any> => {
Expand Down Expand Up @@ -82,7 +83,11 @@ export async function getNextDepositIndex(contractVersion: string): Promise<numb
})) as number
}

export async function claimSendLink(pubKey: string, recipient: string, password: string) {
export async function claimSendLink(
pubKey: string,
recipient: string,
password: string
): Promise<SendLink | { error: string }> {
const response = await fetchWithSentry(`${PEANUT_API_URL}/send-links/${pubKey}/claim`, {
method: 'POST',
headers: {
Expand All @@ -97,9 +102,9 @@ export async function claimSendLink(pubKey: string, recipient: string, password:
if (!response.ok) {
const body = await response.json()
if (!!body.error || !!body.message) {
throw new Error(body.message ?? body.error)
return { error: body.message ?? body.error }
}
throw new Error(`HTTP error! status: ${response.status}`)
return { error: `HTTP error! status: ${response.status}` }
}
return jsonParse(await response.text())
return jsonParse(await response.text()) as SendLink
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ const MantecaDepositShareDetails = ({
</>
)}
<PaymentInfoRow label="Exchange Rate" value={`1 USD = ${exchangeRate} ${currencySymbol}`} />
<PaymentInfoRow label="Network fees" value={networkFees} />
<PaymentInfoRow
label="Provider fees"
value={networkFees}
moreInfoText="Our providers and the blockchain charge a small fee for every transaction. This fee is already accounted for in the amount you see."
/>
<PaymentInfoRow label="Peanut fee" value="Sponsored by Peanut!" hideBottomBorder />
</Card>
</div>
Expand Down
15 changes: 15 additions & 0 deletions src/components/Kyc/InitiateMantecaKYCModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useMantecaKycFlow } from '@/hooks/useMantecaKycFlow'
import { CountryData } from '@/components/AddMoney/consts'
import { Button } from '../0_Bruddle'
import { PeanutDoesntStoreAnyPersonalInformation } from './KycVerificationInProgressModal'
import { useEffect } from 'react'

interface Props {
isOpen: boolean
Expand Down Expand Up @@ -38,6 +39,20 @@ const InitiateMantecaKYCModal = ({
country,
})

useEffect(() => {
const handleMessage = (event: MessageEvent) => {
if (event.data.source === 'peanut-kyc-success') {
onKycSuccess?.()
}
}

window.addEventListener('message', handleMessage)

return () => {
window.removeEventListener('message', handleMessage)
}
}, [])

return (
<>
<ActionModal
Expand Down
63 changes: 8 additions & 55 deletions src/services/sendLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,10 @@ import { PEANUT_API_URL } from '@/constants'
import { fetchWithSentry, jsonParse, jsonStringify } from '@/utils'
import { generateKeysFromString, getParamsFromLink } from '@squirrel-labs/peanut-sdk'
import Cookies from 'js-cookie'
import type { SendLink } from '@/services/services.types'

export enum ESendLinkStatus {
creating = 'creating',
completed = 'completed',
CLAIMING = 'CLAIMING',
CLAIMED = 'CLAIMED',
CANCELLED = 'CANCELLED',
FAILED = 'FAILED',
}

type SendLinkStatus = `${ESendLinkStatus}`

export type SendLink = {
pubKey: string
depositIdx: number
chainId: string
contractVersion: string
textContent?: string
fileUrl?: string
status: SendLinkStatus
createdAt: Date
senderAddress: string
amount: bigint
tokenAddress: string
sender: {
userId: string
username: string
fullName: string
bridgeKycStatus: string
accounts: {
identifier: string
type: string
}[]
}
claim?: {
amount: string
txHash: string
tokenAddress: string
recipientAddress?: string
recipient?: {
userId: string
username: string
fullName: string
bridgeKycStatus: string
accounts: {
identifier: string
type: string
}[]
}
}
events: {
timestamp: Date
status: SendLinkStatus
}[]
}
export { ESendLinkStatus } from '@/services/services.types'
export type { SendLinkStatus, SendLink } from '@/services/services.types'

export type ClaimLinkData = SendLink & { link: string; password: string; tokenSymbol: string; tokenDecimals: number }

Expand Down Expand Up @@ -203,7 +152,11 @@ export const sendLinksApi = {
claim: async (recipient: string, link: string): Promise<SendLink> => {
const params = getParamsFromLink(link)
const pubKey = generateKeysFromString(params.password).address
return await claimSendLink(pubKey, recipient, params.password)
const response = await claimSendLink(pubKey, recipient, params.password)
if ('error' in response) {
throw new Error(response.error)
}
return response
},

/**
Expand Down
55 changes: 55 additions & 0 deletions src/services/services.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,58 @@ export interface CreateQrPaymentResponse {
qrPayment: QrPaymentResponse
charge: TRequestChargeResponse
}

export enum ESendLinkStatus {
creating = 'creating',
completed = 'completed',
CLAIMING = 'CLAIMING',
CLAIMED = 'CLAIMED',
CANCELLED = 'CANCELLED',
FAILED = 'FAILED',
}

export type SendLinkStatus = `${ESendLinkStatus}`

export type SendLink = {
pubKey: string
depositIdx: number
chainId: string
contractVersion: string
textContent?: string
fileUrl?: string
status: SendLinkStatus
createdAt: Date
senderAddress: string
amount: bigint
tokenAddress: string
sender: {
userId: string
username: string
fullName: string
bridgeKycStatus: string
accounts: {
identifier: string
type: string
}[]
}
claim?: {
amount: string
txHash: string
tokenAddress: string
recipientAddress?: string
recipient?: {
userId: string
username: string
fullName: string
bridgeKycStatus: string
accounts: {
identifier: string
type: string
}[]
}
}
events: {
timestamp: Date
status: SendLinkStatus
}[]
}
Loading