Skip to content
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
4 changes: 2 additions & 2 deletions src/app/creator/build/[type]/AppliedModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import Loader from '@/components/Loader';
import { Modal } from '@/components/Modal';
import { Confirm } from '@/components/Modal/Confirm';
import { NoData } from '@/components/NoData';
import { writeBountyAbiActions } from '@/constants/abis/bounty';
import { BOUNTY_SUPPORTED_CHAIN } from '@/constants/chain';
import { contracts, payTokens } from '@/constants/contract';
import { useAllowance, useApprove } from '@/hooks/useERC20';
import { parseTokenUnits } from '@/utils/web3';

import { createTask } from '#/domain/bounty/repository';
import { EXPERIENCE_OPTIONS } from '#/lib/user';
import { denyBuilder, approveBuilder } from '#/services/creator';
import { useCreatorBountyBuilders } from '#/services/creator/hooks';
Expand Down Expand Up @@ -142,7 +142,7 @@ export function AppliedModal({ open, closeModal, bounty, applyCallback }) {

const write = async () => {
try {
const { hash } = await writeBountyAbiActions.createTask(_contracts.bounty, [
const { hash } = await createTask(_contracts.bounty, [
bounty.task,
currUser?.user_wallet,
payToken.address,
Expand Down
3 changes: 1 addition & 2 deletions src/app/creator/build/[type]/ManageModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ import { useNetwork, useWalletClient } from 'wagmi';
import { Button } from '@/components/Button';
import { Modal } from '@/components/Modal';
import { NoData } from '@/components/NoData';
import { withdraw } from '@/constants/bounty';
import { BOUNTY_SUPPORTED_CHAIN } from '@/constants/chain';
import { contracts, payTokens } from '@/constants/contract';
import { currentTime, fromNow } from '@/utils/date';
import { formatTime } from '@/utils/date';
import { parseTokenUnits, signBounty } from '@/utils/web3';

import { requestTermination } from '#/domain/bounty/repository';
import { requestTermination, withdraw } from '#/domain/bounty/repository';
import {
getProgressList,
finishConfirm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
* limitations under the License.
*/

import { abiContractFactory } from '#/shared/utils/abiContractFactory';

export const BountyABI = [
const abi = [
{ inputs: [], stateMutability: 'nonpayable', type: 'constructor' },
{ inputs: [], name: 'AlreadyExists', type: 'error' },
{ inputs: [], name: 'AlreadyWithdrawn', type: 'error' },
Expand Down Expand Up @@ -205,6 +203,4 @@ export const BountyABI = [
},
] as const;

export const { readActions: readBountyAbiActions, writeActions: writeBountyAbiActions } = abiContractFactory(BountyABI);

export default BountyABI;
export default abi;
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@
* limitations under the License.
*/

import { waitForTransaction } from '@wagmi/core';

import { PAGE_SIZE } from '@/constants/config';
import { contracts, payTokens } from '@/constants/contract';
import { isInteger, merge } from '@/utils';
import { createContractActions } from '@/utils/contract';
import httpClient from '@/utils/http';
import { parseTokenUnits } from '@/utils/web3';

import bountyAbi from './helper/abi';

const { writeActions: { createTask, withdraw: withdrawFromAbi } } = createContractActions(bountyAbi);

function resolveSkipped(page, size = PAGE_SIZE) {
let resolved = Number(page);
Expand All @@ -28,7 +37,7 @@ function resolveSkipped(page, size = PAGE_SIZE) {
return (resolved - 1) * size;
}

async function fetchList(params = {}) {
async function fetchList(params = {} as any) {
const { page = 1, sort, ...others } = params;

return httpClient.get('/build/general/bounties', {
Expand Down Expand Up @@ -59,13 +68,13 @@ async function fetchBuilderListForCreator(id, params) {
return httpClient.get(`/build/creator/bounties/${id}/builders`, { params });
}

async function fetchPublishedBountyList(params = {}) {
async function fetchPublishedBountyList(params = {} as any) {
const { userId, ...others } = params;

return fetchList({ ...others, team_uid: userId });
}

async function fetchAppliedBountyList(params = {}) {
async function fetchAppliedBountyList(params = {} as any) {
const { userId, sort, ...others } = params;

return httpClient.get(`/build/dashboard/bounties/public/${userId}`, {
Expand All @@ -77,9 +86,25 @@ async function requestTermination(id, data) {
return httpClient.post(`/build/creator/bounties/${id}/status/termination/propose`, data);
}

async function withdraw(walletClient, chainId, taskId, amount, deadline, signature) {
try {
const { hash } = await withdrawFromAbi(contracts[chainId].bounty, [
taskId,
parseTokenUnits(amount.toString(), payTokens[chainId].usdt.decimals).toBigInt(),
deadline,
signature,
]);
const wait = await waitForTransaction({ hash });
return { hash, wait };
} catch {
return { hash: 'error', wait: null };
}
}

export {
fetchList, fetchOne, applyOne,
fetchActivityList, fetchBuilderList, fetchBuilderListForCreator,
fetchPublishedBountyList, fetchAppliedBountyList,
requestTermination,
createTask, withdraw,
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import { useNetwork, useWalletClient } from 'wagmi';

import { Button } from '@/components/Button';
import { Modal } from '@/components/Modal';
import { withdraw } from '@/constants/bounty';

import {
finishConfirm,
finishDeny,
} from '#/services/bounties';

import { useBountyEnvCheck } from '../../hooks';
import { withdraw } from '../../repository';

function AgreeFinishedModal({open, close, bounty, revalidatePathAction}) {
const [loading, setLoading] = useState(false);
Expand Down
5 changes: 2 additions & 3 deletions src/domain/bounty/widgets/process-list/AppliedModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
import { parseTokenUnits } from '@/utils/web3';

import { approveBuilder } from '#/services/creator';
import { writeBountyAbiActions } from '#/shared/constants/abis/bounty';

import { useBountyEnvCheck } from '../../hooks';
import { fetchBuilderListForCreator } from '../../repository';
import { fetchBuilderListForCreator, createTask } from '../../repository';
import AppliedBuilderListView from '../../views/applied-builder-list';

function AppliedModal({ open, closeModal, bounty, revalidatePathAction }) {
Expand Down Expand Up @@ -77,7 +76,7 @@

const write = useCallback(async() => {
try {
const { hash } = await writeBountyAbiActions.createTask(_contracts.bounty, [
const { hash } = await createTask(_contracts.bounty, [
bounty.task,
currUser?.user_wallet,
payToken.address,
Expand All @@ -104,7 +103,7 @@
setApproveConfirmLoading(false);
toast.error(err.message);
}
}, [_contracts, approveConfirmIds, bounty, currUser, payToken, updateList]);

Check warning on line 106 in src/domain/bounty/widgets/process-list/AppliedModal.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useCallback has a missing dependency: 'revalidatePathAction'. Either include it or remove the dependency array. If 'revalidatePathAction' changes too often, find the parent component that defines it and wrap that definition in useCallback

Check warning on line 106 in src/domain/bounty/widgets/process-list/AppliedModal.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useCallback has a missing dependency: 'revalidatePathAction'. Either include it or remove the dependency array. If 'revalidatePathAction' changes too often, find the parent component that defines it and wrap that definition in useCallback

Check warning on line 106 in src/domain/bounty/widgets/process-list/AppliedModal.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useCallback has a missing dependency: 'revalidatePathAction'. Either include it or remove the dependency array. If 'revalidatePathAction' changes too often, find the parent component that defines it and wrap that definition in useCallback

const approveConfirm = useCallback(async () => {
setApproveConfirmLoading(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import { erc20ABI } from '@wagmi/core';

import { abiContractFactory } from '#/shared/utils/abiContractFactory';
import { createContractActions } from '@/utils/contract';

export const { readActions: readErc20AbiActions, writeActions: writeErc20AbiActions } = abiContractFactory(erc20ABI);
const { writeActions: { transfer: transferToken } } = createContractActions(erc20ABI);

export { transferToken };
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

import { abiContractFactory } from '#/shared/utils/abiContractFactory';

const abi = [
{
inputs: [],
Expand Down Expand Up @@ -787,6 +785,4 @@ const abi = [
},
] as const;

export const { readActions: readNftAbiActions, writeActions: writeNftAbiActions } = abiContractFactory(abi);

export default abi;
6 changes: 4 additions & 2 deletions src/domain/reputation/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
import { TransactionBlock } from '@mysten/sui.js/transactions';
import { waitForTransaction } from '@wagmi/core';

import { createContractActions } from '@/utils/contract';
import httpClient from '@/utils/http';

import type { Address } from '@wagmi/core';

import { writeNftAbiActions } from './helper/nftAbi';
import nftAbi from './helper/abi';

const { writeActions: { safeMint } } = createContractActions(nftAbi);

async function fetchGainedReputationList(userId) {
return httpClient.get(`/nft/general/public/${userId}/infos`);
Expand Down Expand Up @@ -65,7 +67,7 @@ async function mintNft({

const signed = signRes.data;

const { hash } = await writeNftAbiActions.safeMint(contract, [
const { hash } = await safeMint(contract, [
address,
id,
userId,
Expand Down
4 changes: 2 additions & 2 deletions src/entry/pages/course-detail/RightCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { parseTokenUnits } from '@/utils/web3';

import { enrollOne, updateTransaction } from '#/domain/challenge/repository';
import DatePlaceWidget from '#/domain/challenge/widgets/date-place';
import { writeErc20AbiActions } from '#/shared/constants/abis/erc20ABI';
import { transferToken } from '#/domain/crypto/repository';
// import { currentTime } from '@/utils/date'
import { useMediaUrl } from '#/state/application/hooks';

Expand Down Expand Up @@ -308,7 +308,7 @@ export default function LearnRightCard({
// args: [toAddress, _amount],
// })

const { hash } = await writeErc20AbiActions.transfer(
const { hash } = await transferToken(
data.challenges_extra?.course_challenges_extra_feeds_contract,
[toAddress, _amount.toBigInt()],
);
Expand Down
36 changes: 0 additions & 36 deletions src/shared/constants/bounty.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { readContract, writeContract } from '@wagmi/core';
import type { Address, ReadContractConfig, ReadContractResult, WriteContractPreparedArgs, WriteContractResult } from '@wagmi/core';
import type { Abi, ExtractAbiFunctionNames } from 'abitype';

export function abiContractFactory<
export function createContractActions<
TAbi extends Abi,
ViewFunctionNames extends ExtractAbiFunctionNames<TAbi, 'view' | 'pure'>,
WriteFunctionNames extends ExtractAbiFunctionNames<TAbi, 'payable' | 'nonpayable'>,
Expand Down
Loading