-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from amhedcb/amhed/confirmation-code
Adds confirmation code
- Loading branch information
Showing
21 changed files
with
1,209 additions
and
1,112 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,28 @@ | ||
name: Run Tests | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [20.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile | ||
- name: Build | ||
run: yarn build | ||
- name: Run tests | ||
run: yarn test |
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 |
---|---|---|
|
@@ -8,7 +8,8 @@ | |
"start": "next start", | ||
"lint": "next lint", | ||
"test": "jest", | ||
"postinstall": "prisma generate" | ||
"postinstall": "prisma generate", | ||
"prepush": "yarn test" | ||
}, | ||
"dependencies": { | ||
"@prisma/client": "^3.6.0", | ||
|
@@ -28,10 +29,19 @@ | |
"eslint": "^8.2.0", | ||
"eslint-config-next": "^12.0.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"jest": "^27.0.6", | ||
"jest": "^29.7.0", | ||
"lint-staged": "^12.0.6", | ||
"prettier": "^2.4.1", | ||
"prisma": "^3.6.0", | ||
"ts-jest": "^29.2.5", | ||
"typescript": "^4.4.4" | ||
} | ||
}, | ||
"lint-staged": { | ||
"**/*.{js,jsx,ts,tsx}": [ | ||
"eslint --fix", | ||
"prettier --write", | ||
"jest --bail --findRelatedTests" | ||
] | ||
}, | ||
"packageManager": "[email protected]+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72" | ||
} |
38 changes: 38 additions & 0 deletions
38
prisma/migrations/20240925193950_simplify_tables/migration.sql
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,38 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the `ContactlessPaymentMessage` table. If the table is not empty, all the data it contains will be lost. | ||
- You are about to drop the `ContactlessPaymentTxData` table. If the table is not empty, all the data it contains will be lost. | ||
- You are about to drop the `Nonce` table. If the table is not empty, all the data it contains will be lost. | ||
- You are about to drop the `PaymentTx` table. If the table is not empty, all the data it contains will be lost. | ||
*/ | ||
-- DropTable | ||
DROP TABLE "ContactlessPaymentMessage"; | ||
|
||
-- DropTable | ||
DROP TABLE "ContactlessPaymentTxData"; | ||
|
||
-- DropTable | ||
DROP TABLE "Nonce"; | ||
|
||
-- DropTable | ||
DROP TABLE "PaymentTx"; | ||
|
||
-- CreateTable | ||
CREATE TABLE "ContactlessPaymentTxOrMsg" ( | ||
"uuid" TEXT NOT NULL, | ||
"verificationCode" TEXT NOT NULL, | ||
"toAddress" TEXT NOT NULL, | ||
"chainId" TEXT NOT NULL, | ||
"contractAddress" TEXT NOT NULL, | ||
"value" TEXT NOT NULL, | ||
"txParams" JSONB, | ||
"rpcProxySubmissionParams" JSONB, | ||
"dappName" TEXT, | ||
"dappUrl" TEXT, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "ContactlessPaymentTxOrMsg_pkey" PRIMARY KEY ("uuid") | ||
); |
12 changes: 12 additions & 0 deletions
12
prisma/migrations/20240925194407_simplify_more/migration.sql
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,12 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `contractAddress` on the `ContactlessPaymentTxOrMsg` table. All the data in the column will be lost. | ||
- You are about to drop the column `toAddress` on the `ContactlessPaymentTxOrMsg` table. All the data in the column will be lost. | ||
- You are about to drop the column `value` on the `ContactlessPaymentTxOrMsg` table. All the data in the column will be lost. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "ContactlessPaymentTxOrMsg" DROP COLUMN "contractAddress", | ||
DROP COLUMN "toAddress", | ||
DROP COLUMN "value"; |
8 changes: 8 additions & 0 deletions
8
prisma/migrations/20240925203116_include_payload_type/migration.sql
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,8 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `payloadType` to the `ContactlessPaymentTxOrMsg` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "ContactlessPaymentTxOrMsg" ADD COLUMN "payloadType" TEXT NOT NULL; |
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20240925220433_include_additional_payload/migration.sql
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,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "ContactlessPaymentTxOrMsg" ADD COLUMN "additionalPayload" JSONB; |
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,3 +1,5 @@ | ||
// TODO: Amhed: Move these to /types folder | ||
|
||
export const fiatTokenAbi = [ | ||
{ | ||
anonymous: false, | ||
|
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,8 @@ | ||
export function generateRandomString(length = 8): string { | ||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
let result = ''; | ||
for (let i = 0; i < length; i++) { | ||
result += characters.charAt(Math.floor(Math.random() * characters.length)); | ||
} | ||
return result; | ||
} |
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,63 +1,33 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
import { getPrismaClient } from '@helpers/database'; | ||
import { formatTxDataResponse } from '@/helpers/formatTxDataResponse'; | ||
import { ethers } from 'ethers'; | ||
import { formatTxMessageResponse } from '@/helpers/formatTxMessageResponse'; | ||
import { getPaymentTxOrMsg } from '@/services/paymentTxOrMsgService'; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
const prisma = getPrismaClient(); | ||
|
||
if (req.method === 'GET') { | ||
try { | ||
const { uuid, buyerAddress } = req.query; | ||
const { uuid, senderAddress } = req.query; | ||
|
||
if (typeof uuid !== 'string') { | ||
if (!uuid || typeof uuid !== 'string') { | ||
return res.status(400).json({ message: 'Invalid UUID' }); | ||
} | ||
|
||
if (!!buyerAddress && ((typeof buyerAddress !== 'string') || !ethers.utils.isAddress(buyerAddress))) { | ||
return res.status(400).json({ message: 'Invalid buyer address' }); | ||
if ( | ||
!!senderAddress && | ||
(typeof senderAddress !== 'string' || !ethers.utils.isAddress(senderAddress)) | ||
) { | ||
return res.status(400).json({ message: 'Invalid sender address' }); | ||
} | ||
|
||
const paymentTxPromise = prisma.paymentTx.findUnique({ | ||
where: { uuid }, | ||
}); | ||
const txDataPromise = prisma.contactlessPaymentTxData.findUnique({ | ||
where: { uuid }, | ||
}); | ||
const txMessagePromise = prisma.contactlessPaymentMessage.findUnique({ | ||
where: { uuid }, | ||
}); | ||
|
||
const [paymentTx, txData, txMessage] = (await Promise.allSettled([paymentTxPromise, txDataPromise, txMessagePromise])).map(promiseResult => { | ||
if (promiseResult.status === 'fulfilled') { | ||
return promiseResult.value | ||
}; | ||
|
||
return undefined; | ||
}); | ||
|
||
if (!txData && !paymentTx && !txMessage) { | ||
return res.status(404).json({ message: 'Not Found' }); | ||
} | ||
|
||
if (paymentTx) { | ||
res.status(200).json({ payloadType: 'eip681', ...paymentTx }); | ||
} else if (txData) { | ||
// Substitute the buyer address into the tx call data if applicable | ||
const formattedTxData = await formatTxDataResponse({ txData, buyerAddress }); | ||
res.status(200).json({ payloadType: 'contractCall', ...formattedTxData }) | ||
} else { | ||
// Substitute the buyer address into the message's from field if applicable | ||
const formattedTxMessage = formatTxMessageResponse({ txMessage, buyerAddress }); | ||
res.status(200).json({ payloadType: 'eip712', ...formattedTxMessage }); | ||
} | ||
const paymentTxOrMsg = await getPaymentTxOrMsg(uuid as string); | ||
res.status(200).json(paymentTxOrMsg); | ||
} catch (error) { | ||
console.error('Error retrieving payment transaction:', error); | ||
res.status(500).json({ message: `Error retrieving payment transaction: ${(error as Error).message}` }); | ||
res | ||
.status(500) | ||
.json({ message: `Error retrieving payment transaction: ${(error as Error).message}` }); | ||
} | ||
} else { | ||
res.setHeader('Allow', ['GET']); | ||
res.status(405).end(`Method ${req.method} Not Allowed`); | ||
} | ||
} | ||
} |
Oops, something went wrong.