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

/send checks create/claim shovel integrations #655

Open
wants to merge 3 commits into
base: feat/send-checks-ui-mvp
Choose a base branch
from
Open
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
33 changes: 33 additions & 0 deletions packages/app/features/checks/utils/useSendChecksClaimed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useSendAccount } from 'app/utils/send-accounts'
import { supabaseAdmin } from 'app/utils/supabase/admin'
import { useCallback } from 'react'
import debug from 'debug'
import type { Hex } from 'viem'

const logger = debug.log

export const useSendChecksClaimed = () => {
const { data: sendAccount } = useSendAccount()
return useCallback(async () => {
return await getSendChecksClaimed(sendAccount?.address)
}, [sendAccount?.address])
}

export const getSendChecksClaimed = async (redeemer?: Hex) => {
if (!redeemer) {
logger('Cannot get send checks claimed. `redeemer` is undefined.')
return
}

const { data, error } = await supabaseAdmin
.from('send_check_claimed')
.select('*')
.eq('redeemer', redeemer)

if (error) {
logger(`Error fetching send checks claimed for redeemer: [${redeemer}]`, error)
throw error
}

return data
}
32 changes: 32 additions & 0 deletions packages/app/features/checks/utils/useSendChecksCreated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useSendAccount } from 'app/utils/send-accounts'
import { supabaseAdmin } from 'app/utils/supabase/admin'
import { useCallback } from 'react'
import debug from 'debug'

const logger = debug.log

export const useGetCreatedSendChecks = () => {
const { data: sendAccount } = useSendAccount()

return useCallback(async () => {
return await getCreatedSendChecks(sendAccount?.address)
}, [sendAccount?.address])
}

export const getCreatedSendChecks = async (from?: string) => {
if (!from) {
logger('Cannot get send checks created. `from` is undefined.')
return
}
const { data, error } = await supabaseAdmin
.from('send_check_created')
.select('*')
.eq('from', from)

if (error) {
logger('Error fetching created send checks', error)
throw error
}

return data
}
190 changes: 190 additions & 0 deletions packages/shovel/etc/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,196 @@
"start": "$BASE_BLOCK_START"
}
]
},
{
"name": "send_check_created",
"enabled": true,
"block": [
{
"name": "chain_id",
"column": "chain_id"
},
{
"name": "block_time",
"column": "block_time"
},
{
"name": "tx_hash",
"column": "tx_hash"
},
{
"name": "log_addr",
"column": "log_addr",
"filter_op": "contains",
"filter_arg": [
"0xe1f30594e663400EeA4e51e2B5603204cfE81712"
]
}
],
"event": {
"type": "event",
"anonymous": false,
"inputs": [
{
"name": "token",
"type": "address",
"indexed": false,
"column": "token"
},
{
"name": "amount",
"type": "uint256",
"indexed": false,
"column": "amount"
},
{
"name": "from",
"type": "address",
"indexed": false,
"column": "from"
}
],
"name": "CheckCreated"
},
"table": {
"name": "send_check_created",
"columns": [
{
"name": "chain_id",
"type": "numeric"
},
{
"name": "block_time",
"type": "numeric"
},
{
"name": "tx_hash",
"type": "bytea"
},
{
"name": "log_addr",
"type": "bytea"
},
{
"name": "token",
"type": "bytea"
},
{
"name": "amount",
"type": "numeric"
},
{
"name": "from",
"type": "bytea"
}
]
},
"sources": [
{
"name": "base_logs",
"start": "$BASE_BLOCK_START"
}
]
},
{
"name": "send_check_claimed",
"enabled": true,
"block": [
{
"name": "chain_id",
"column": "chain_id"
},
{
"name": "block_time",
"column": "block_time"
},
{
"name": "tx_hash",
"column": "tx_hash"
},
{
"name": "log_addr",
"column": "log_addr",
"filter_op": "contains",
"filter_arg": [
"0xe1f30594e663400EeA4e51e2B5603204cfE81712"
]
}
],
"event": {
"type": "event",
"anonymous": false,
"inputs": [
{
"name": "token",
"type": "address",
"indexed": false,
"column": "token"
},
{
"name": "amount",
"type": "uint256",
"indexed": false,
"column": "amount"
},
{
"name": "from",
"type": "address",
"indexed": false,
"column": "from"
},
{
"name": "redeemer",
"type": "address",
"indexed": false,
"column": "redeemer"
}
],
"name": "CheckClaimed"
},
"table": {
"name": "send_check_claimed",
"columns": [
{
"name": "chain_id",
"type": "numeric"
},
{
"name": "block_time",
"type": "numeric"
},
{
"name": "tx_hash",
"type": "bytea"
},
{
"name": "log_addr",
"type": "bytea"
},
{
"name": "token",
"type": "bytea"
},
{
"name": "amount",
"type": "numeric"
},
{
"name": "from",
"type": "bytea"
},
{
"name": "redeemer",
"type": "bytea"
}
]
},
"sources": [
{
"name": "base_logs",
"start": "$BASE_BLOCK_START"
}
]
}
]
}
10 changes: 10 additions & 0 deletions packages/shovel/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
sendAccountSigningKeyAdded,
sendAccountSigningKeyRemoved,
sendtagCheckoutReceiptsIntegration,
sendCheckCreatedIntegration,
sendCheckClaimedIntegration,
} from './integrations'

// baseSrcBlockHeaders is to be used for integrations that require block headers
Expand Down Expand Up @@ -66,6 +68,14 @@ export const integrations: Integration[] = [
...sendtagCheckoutReceiptsIntegration,
sources: [{ name: baseSrcLogs.name, start: '$BASE_BLOCK_START' }],
},
{
...sendCheckCreatedIntegration,
sources: [{ name: baseSrcLogs.name, start: '$BASE_BLOCK_START' }],
},
{
...sendCheckClaimedIntegration,
sources: [{ name: baseSrcLogs.name, start: '$BASE_BLOCK_START' }],
},
]

const c = makeConfig({
Expand Down
2 changes: 2 additions & 0 deletions packages/shovel/src/integrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export { integration as sendAccountSigningKeyAdded } from './send-account-signin
export { integration as sendAccountSigningKeyRemoved } from './send-account-signing-key-removed'
export { integration as sendAccountReceivesIntegration } from './send-account-receives'
export { integration as sendtagCheckoutReceiptsIntegration } from './sendtag-checkout-receipts'
export { integration as sendCheckCreatedIntegration } from './send-check-created'
export { integration as sendCheckClaimedIntegration } from './send-check-claimed'
73 changes: 73 additions & 0 deletions packages/shovel/src/integrations/send-check-claimed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import type { BlockData, Column, Integration, Table } from '@indexsupply/shovel-config'
import { sendCheckAddress } from '@my/wagmi'

export const sendCheckClaimedTable: Table = {
name: 'send_check_claimed',
columns: [
{ name: 'chain_id', type: 'numeric' },
{ name: 'block_time', type: 'numeric' },
{ name: 'tx_hash', type: 'bytea' },
{ name: 'log_addr', type: 'bytea' },
{ name: 'token', type: 'bytea' },
{ name: 'amount', type: 'numeric' },
{ name: 'from', type: 'bytea' },
{ name: 'redeemer', type: 'bytea' },
] as Column[],
} as const

export const integration: Omit<Integration, 'sources'> = {
name: 'send_check_claimed',
enabled: true,
block: [
{
name: 'chain_id',
column: 'chain_id',
},
{
name: 'block_time',
column: 'block_time',
},
{
name: 'tx_hash',
column: 'tx_hash',
},
{
name: 'log_addr',
column: 'log_addr',
filter_op: 'contains',
filter_arg: [...new Set(Object.values(sendCheckAddress))].sort() as `0x${string}`[],
},
] as BlockData[],
event: {
type: 'event',
anonymous: false,
inputs: [
{
name: 'token',
type: 'address',
indexed: false,
column: 'token',
},
{
name: 'amount',
type: 'uint256',
indexed: false,
column: 'amount',
},
{
name: 'from',
type: 'address',
indexed: false,
column: 'from',
},
{
name: 'redeemer',
type: 'address',
indexed: false,
column: 'redeemer',
},
],
name: 'CheckClaimed',
},
table: sendCheckClaimedTable,
} as const
Loading
Loading