Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add subscribe to payment #9

Merged
merged 8 commits into from
Jan 18, 2024
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
2 changes: 1 addition & 1 deletion payment_app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "eth-sdk && graphclient build && next dev",
"dev": "eth-sdk && graphclient build && next dev -p 4000",
"build": "eth-sdk && graphclient build && next build",
"start": "next start",
"lint": "next lint",
Expand Down
2 changes: 2 additions & 0 deletions shop/.env.default
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
ALCHEMY_ID=
NEXT_PUBLIC_PUSHER_APP_CLUSTER=
NEXT_PUBLIC_PUSHER_APP_KEY=
WALLETCONNECT_PROJECT_ID=
210 changes: 210 additions & 0 deletions shop/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions shop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@gelatonetwork/relay-sdk": "^5.5.5",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
Expand All @@ -27,6 +28,7 @@
"framer-motion": "^10.18.0",
"lucide-react": "^0.309.0",
"next": "14.0.4",
"pusher-js": "^8.4.0-rc2",
"qrcode": "^1.5.3",
"react": "^18",
"react-day-picker": "^8.10.0",
Expand Down
27 changes: 27 additions & 0 deletions shop/src/app/payment/components/payment-popup/gelato.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
GelatoRelay,
TransactionStatusResponse,
} from '@gelatonetwork/relay-sdk'

export async function awaitGelatoTask(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably going to be used both in the app as well as the shop so at some point we might want to move this into a shared sdk, but not necessary for the first version.

taskId: string,
): Promise<TransactionStatusResponse | null> {
const relay = new GelatoRelay()
return await new Promise((resolve, reject) => {
const maxRetry = 100
let retryNum = 0
const interval = setInterval(async () => {
retryNum++
if (retryNum > maxRetry) {
clearInterval(interval)
reject('Max retry reached')
}
const taskStatus = await relay.getTaskStatus(taskId)
console.log('Gelato task status:', taskStatus)
if (taskStatus?.taskState == 'ExecSuccess') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few steps in between, that you will see in the log statements.
It might be even better if we could track those intermediate steps between gelato task submission and the ExecSuccess result, to give the user a more fine grained progress update.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example you could make this function accept a callback function as a parameter that gets called on every update, that can then be used in react to update the state / progress.

clearInterval(interval)
resolve(taskStatus)
}
}, 500)
})
}
Loading