Skip to content

Commit

Permalink
Merge pull request #89 from YoubetDao/feat/add-address-for-receiver
Browse files Browse the repository at this point in the history
feat: add address for receiver in pull request
  • Loading branch information
wfnuser authored Dec 11, 2024
2 parents 8e1e52d + 57ee3bc commit 5e4a8c5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 38 deletions.
3 changes: 2 additions & 1 deletion src/pages/pull-request/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ function PullRequestsTable(): React.ReactElement {
</Button>
}
prGithubId={pr.githubId}
addressFrom={address}
sender={address}
receiver={pr.user.wallet}
chain={chain}
/>
)
Expand Down
54 changes: 27 additions & 27 deletions src/pages/pull-request/reward-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@ const formSchema = z.object({
amount: z.string().regex(/^(0|[1-9]\d*)(\.\d+)?$/, {
message: 'Amount must be a positive number',
}),
address: z.string().regex(/^0x[a-fA-F0-9]{40}$/, { message: 'Invalid Ethereum address' }),
receiver: z.string().regex(/^0x[a-fA-F0-9]{40}$/, { message: 'Invalid Ethereum address' }),
githubId: z.string().min(1, { message: 'GitHub ID is required' }),
coin: z.string().min(1, { message: 'Coin is required' }),
})

interface IRewardForm {
trigger: React.ReactNode
prGithubId: number
addressFrom: `0x${string}`
sender: `0x${string}`
receiver: `0x${string}`
chain: Chain
}

export const RewardDialogForm = ({ trigger, prGithubId, addressFrom, chain }: IRewardForm) => {
export const RewardDialogForm = ({ trigger, prGithubId, sender, receiver, chain }: IRewardForm) => {
const queryClient = useQueryClient()
const { toast } = useToast()
const { sendTransactionAsync } = useSendTransaction()
Expand All @@ -47,6 +48,7 @@ export const RewardDialogForm = ({ trigger, prGithubId, addressFrom, chain }: IR
resolver: zodResolver(formSchema),
defaultValues: {
coin: USDT_SYMBOL,
receiver,
},
})

Expand All @@ -65,15 +67,15 @@ export const RewardDialogForm = ({ trigger, prGithubId, addressFrom, chain }: IR

if (values.coin !== USDT_SYMBOL) {
transaction = await sendTransactionAsync({
to: values.address as `0x${string}`,
to: values.receiver as `0x${string}`,
value: parseEther(values.amount),
})
} else {
transaction = await writeContractAsync({
abi: USDT_ABI,
address: PAYMENT_USDT_ADDRESS, // USDT contract address on Current Payment Chain
functionName: 'transfer',
args: [values.address, parseFloat(values.amount) * Math.pow(10, USDT_DECIMAL)],
args: [values.receiver, parseFloat(values.amount) * Math.pow(10, USDT_DECIMAL)],
})
}

Expand All @@ -86,10 +88,10 @@ export const RewardDialogForm = ({ trigger, prGithubId, addressFrom, chain }: IR
transactionInfo: {
amount: parseFloat(values.amount),
decimals: chain.nativeCurrency.decimals,
from: addressFrom,
from: sender,
network: chain.name,
symbol: chain.nativeCurrency.symbol,
to: values.address,
to: values.receiver,
transactionId: transaction,
},
type: 'Crypto',
Expand Down Expand Up @@ -156,6 +158,7 @@ export const RewardDialogForm = ({ trigger, prGithubId, addressFrom, chain }: IR
</FormItem>
)}
/>

<FormField
control={form.control}
name="coin"
Expand All @@ -177,26 +180,7 @@ export const RewardDialogForm = ({ trigger, prGithubId, addressFrom, chain }: IR
)}
/>
</section>
<FormField
control={form.control}
name="address"
render={({ field }) => (
<FormItem>
<section className="flex items-center">
<FormLabel className="w-20 flex-shrink-0 text-white">Address</FormLabel>
<FormControl>
<Input
placeholder="Enter wallet address"
autoComplete="off"
{...field}
value={field.value || ''}
/>
</FormControl>
</section>
<FormMessage />
</FormItem>
)}
/>

<FormField
control={form.control}
name="githubId"
Expand Down Expand Up @@ -241,6 +225,22 @@ export const RewardDialogForm = ({ trigger, prGithubId, addressFrom, chain }: IR
</SelectContent>
</Select>
</FormDescription>

<FormField
control={form.control}
name="receiver"
render={({ field }) => (
<FormItem>
<section className="flex items-center">
<FormLabel className="w-20 flex-shrink-0 text-white">Receiver</FormLabel>
<FormControl>
<Input placeholder="Enter receiver address" autoComplete="off" {...field} disabled />
</FormControl>
</section>
<FormMessage />
</FormItem>
)}
/>
</div>
<DialogFooter className="flex flex-1 justify-end pt-4">
<Button variant="secondary" type="submit">
Expand Down
13 changes: 3 additions & 10 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export interface User {
login: string
htmlUrl: string
avatarUrl: string
wallet: `0x${string}`
}

export interface FetchIssuesParams {
Expand Down Expand Up @@ -122,16 +123,8 @@ export interface PullRequest {
mergedAt: string | null
htmlUrl: string
project: string
user: {
login: string
htmlUrl: string
avatarUrl: string
}
assignees: {
login: string
htmlUrl: string
avatarUrl: string
}[]
user: User
assignees: User[]
labels: string[]
namespace: string
rewardGranted: boolean
Expand Down

0 comments on commit 5e4a8c5

Please sign in to comment.