-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #373 from peanutprotocol/feat/cashout-status
Feat/cashout status
- Loading branch information
Showing
14 changed files
with
360 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { NextRequest } from 'next/server' | ||
import { NextResponse } from 'next/server' | ||
import * as consts from '@/constants' | ||
|
||
export async function POST(request: NextRequest) { | ||
try { | ||
const { pubKey } = await request.json() | ||
const apiKey = process.env.PEANUT_API_KEY! | ||
|
||
const response = await fetch(`${consts.PEANUT_API_URL}/cashouts/${pubKey}/status`, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'api-key': apiKey, | ||
}, | ||
}) | ||
|
||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`) | ||
} | ||
|
||
const data = await response.json() | ||
|
||
return NextResponse.json(data) | ||
} catch (error) { | ||
console.error('Failed to get cashout status:', error) | ||
return new NextResponse('Internal Server Error', { status: 500 }) | ||
} | ||
} |
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,46 @@ | ||
import type { NextRequest } from 'next/server' | ||
import { NextResponse } from 'next/server' | ||
import * as consts from '@/constants' | ||
import { generateKeysFromString } from '@squirrel-labs/peanut-sdk' | ||
import { url } from 'inspector' | ||
|
||
export async function POST(request: NextRequest) { | ||
try { | ||
const { | ||
pubKey, | ||
bridgeCustomerId, | ||
liquidationAddressId, | ||
cashoutTransactionHash, | ||
externalAccountId, | ||
chainId, | ||
tokenName, | ||
} = await request.json() | ||
|
||
const response = await fetch(`${consts.PEANUT_API_URL}/cashouts`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
bridgeCustomerId: bridgeCustomerId, | ||
liquidationAddressId: liquidationAddressId, | ||
cashoutTransactionHash: cashoutTransactionHash, | ||
externalAccountId: externalAccountId, | ||
chainId: chainId, | ||
tokenName: tokenName, | ||
pubKey: pubKey, | ||
}), | ||
}) | ||
|
||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`) | ||
} | ||
|
||
const data = await response.json() | ||
|
||
return NextResponse.json(data) | ||
} catch (error) { | ||
console.error('Failed to submit cashout link:', error) | ||
return new NextResponse('Internal Server Error', { status: 500 }) | ||
} | ||
} |
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,14 @@ | ||
import * as components from '@/components' | ||
import Layout from '@/components/Global/Layout' | ||
|
||
export const dynamic = 'force-dynamic' | ||
|
||
// TODO: add metadata | ||
|
||
export default function CashoutStatusPage() { | ||
return ( | ||
<Layout> | ||
<components.CashoutStatus /> | ||
</Layout> | ||
) | ||
} |
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,60 @@ | ||
'use client' | ||
import { useEffect, useState } from 'react' | ||
import * as assets from '@/assets' | ||
import { generateKeysFromString } from '@squirrel-labs/peanut-sdk' | ||
import * as utils from '@/utils' | ||
import Link from 'next/link' | ||
import Icon from '../Global/Icon' | ||
|
||
export const CashoutStatus = () => { | ||
const [cashoutStatus, setCashoutStatus] = useState<'FOUND' | 'NOT FOUND' | undefined>(undefined) | ||
const [cashoutStatusData, setCashoutStatusData] = useState<utils.CashoutTransaction | undefined>(undefined) | ||
|
||
const getAndSetCashoutStatus = async () => { | ||
try { | ||
const response = await utils.getCashoutStatus(window.location.href) | ||
setCashoutStatusData(response) | ||
setCashoutStatus('FOUND') | ||
} catch (error) { | ||
console.error(error) | ||
setCashoutStatus('NOT FOUND') | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
getAndSetCashoutStatus() | ||
}, []) | ||
|
||
return ( | ||
<div className="card"> | ||
{!cashoutStatus ? ( | ||
<div className="relative flex w-full items-center justify-center"> | ||
<div className="animate-spin"> | ||
<img src={assets.PEANUTMAN_LOGO.src} alt="logo" className="h-6 sm:h-10" /> | ||
<span className="sr-only">Loading...</span> | ||
</div> | ||
</div> | ||
) : cashoutStatus === 'FOUND' ? ( | ||
<div className="mx-auto flex max-w-[96%] flex-col items-center justify-center gap-4 pb-20 text-center"> | ||
<label className="text-h2">Cashout status</label> | ||
<div className="flex flex-col justify-center gap-3"> | ||
<label className="text-start text-h8 font-light"> | ||
{cashoutStatusData && utils.CashoutStatusDescriptions[cashoutStatusData?.status]}{' '} | ||
</label> | ||
</div> | ||
<Link | ||
className="absolute bottom-0 flex h-20 w-[27rem] w-full flex-row items-center justify-start gap-2 border-t-[1px] border-black bg-purple-3 px-4.5 dark:text-black" | ||
href={`/profile`} | ||
> | ||
<div className=" border border-n-1 p-0 px-1"> | ||
<Icon name="dashboard" className="-mt-0.5" /> | ||
</div> | ||
Go to profile | ||
</Link> | ||
</div> | ||
) : ( | ||
cashoutStatus === 'NOT FOUND' && 'Cashout Not Found' | ||
)} | ||
</div> | ||
) | ||
} |
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 +1,2 @@ | ||
export * from './Cashout' | ||
export * from './CashoutStatus' |
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
Empty file.
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.