-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
4,002 additions
and
820 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,45 @@ | ||
import { MongoClient } from 'mongodb'; | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
const uri = process.env.MONGODB_URI; | ||
|
||
if (!uri) { | ||
throw new Error('Please add your Mongo URI to .env.local'); | ||
} | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
if (req.method !== 'GET') { | ||
return res.status(405).json({ message: 'Method not allowed' }); | ||
} | ||
|
||
const { address } = req.query; | ||
|
||
if (!address) { | ||
return res.status(400).json({ message: 'Wallet address is required' }); | ||
} | ||
|
||
try { | ||
const client = await MongoClient.connect(uri as string); | ||
const db = client.db('referral'); | ||
const walletsCollection = db.collection('wallets'); | ||
|
||
const wallet = await walletsCollection.findOne({ address }); | ||
|
||
await client.close(); | ||
|
||
if (!wallet) { | ||
return res.status(404).json({ message: 'Wallet not found' }); | ||
} | ||
|
||
return res.status(200).json({ | ||
referredBy: wallet.referredBy, | ||
referralAccountPubKey: wallet.referralAccountPubKey | ||
}); | ||
} catch (error) { | ||
console.error('Error fetching wallet:', error); | ||
return res.status(500).json({ message: 'Error fetching wallet' }); | ||
} | ||
} |
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.