Skip to content

Commit

Permalink
refactor: update MATIC to crypto or OP depending on the context
Browse files Browse the repository at this point in the history
  • Loading branch information
ghimiresdp committed Jan 30, 2025
1 parent c167d5e commit 992e9ff
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 36 deletions.
2 changes: 1 addition & 1 deletion locales/en/admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
"STATISTICS": "Statistics",
"SETTINGS": "Settings"
}
}
}
6 changes: 3 additions & 3 deletions locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"HEADING": "CIT Faucet",
"ADDRESS_LABEL": "Enter your wallet address",
"ADDRESS_HELP_TEXT": "Your wallet address must be whitelisted to get funds.",
"GET_MATIC_COINS": "Get Matic Coins",
"GET_CRYPTO_COINS": "Get OP Coins",
"TOKEN_CLAIM_ERROR": "Tokens Claimed Failed",
"TOKEN_CLAIM_ERROR_DESCRIPTION": "There was an error claiming tokens, please try again later",
"TOKEN_CLAIM_SUCCESS": "Tokens Claimed Successfully",
Expand All @@ -21,7 +21,7 @@
"LOCK_DURATION": "Lock Duration",
"LOCKED": "The faucet is currently locked!!",
"OFFERING": "Offering",
"SEND_MATIC_AT": "Send me Matic coin at"
"SEND_CRYPTO_AT": "Send me OP at"
},
"nav": {
"ADMIN": "Admin",
Expand Down Expand Up @@ -59,4 +59,4 @@
"CURRENT_ALLOWANCE": "Current Allowance",
"CURRENT_BALANCE": "Current Balance"
}
}
}
6 changes: 3 additions & 3 deletions locales/ja/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"HEADING": "CIT ファセット",
"ADDRESS_LABEL": "ウォレットアドレスを入力してください",
"ADDRESS_HELP_TEXT": "資金を得るには、ウォレット アドレスがホワイトリストに登録されている必要があります。",
"GET_MATIC_COINS": "マティックコインを入手",
"GET_CRYPTO_COINS": "OPコインを入手",
"TOKEN_CLAIM_ERROR": "トークンの要求に失敗しました",
"TOKEN_CLAIM_ERROR_DESCRIPTION": "トークンの請求中にエラーが発生しました。後でもう一度お試しください",
"TOKEN_CLAIM_SUCCESS": "トークンが正常に請求されました",
Expand All @@ -21,7 +21,7 @@
"LOCK_DURATION": "ロック期間",
"LOCKED": "ファセットは現在ロックされています!!",
"OFFERING": "献金",
"SEND_MATIC_AT": "次のアドレスに Matic コインを送"
"SEND_CRYPTO_AT": "次のアドレスに OP コインを送"
},
"nav": {
"ADMIN": "管理者",
Expand Down Expand Up @@ -59,4 +59,4 @@
"CURRENT_ALLOWANCE": "現在の許容量",
"CURRENT_BALANCE": "現在の残高"
}
}
}
43 changes: 20 additions & 23 deletions src/pages/api/faucet.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { ApiError, ApiResponseCodes, ApiSuccess } from '@/types';
import { isAddress } from 'ethers/lib/utils';
import { sendMatic } from '@/utils/contract/etherUtils';

import { sendCrypto } from '@/utils/contract/etherUtils';

async function handlePost(req: NextApiRequest, resp: NextApiResponse<ApiSuccess | ApiError>) {
/**
* @dev This method handles POST requests to the faucet API where user can request some matic coins as rewards
* @dev This method handles POST requests to the faucet API where user can request some crypto coins as rewards
*/
const { address } = req.body;
// add validation here
Expand All @@ -25,21 +24,23 @@ async function handlePost(req: NextApiRequest, resp: NextApiResponse<ApiSuccess
});
}

sendMatic(address).then((txn) => {
return resp.status(200).json({
code: ApiResponseCodes.SUCCESS,
message: 'SUCCESSFULLY_SENT_TOKENS',
data: {
transaction: txn,
},
});
}).catch((err) => {
return resp.status(500).json({
code: ApiResponseCodes.CONTRACT_ERROR,
message: 'ERROR_WHILE_SENDING_TOKENS',
details: err,
sendCrypto(address)
.then((txn) => {
return resp.status(200).json({
code: ApiResponseCodes.SUCCESS,
message: 'SUCCESSFULLY_SENT_TOKENS',
data: {
transaction: txn,
},
});
})
.catch((err) => {
return resp.status(500).json({
code: ApiResponseCodes.CONTRACT_ERROR,
message: 'ERROR_WHILE_SENDING_TOKENS',
details: err,
});
});
});
}

async function handleGet(req: NextApiRequest, resp: NextApiResponse) {
Expand Down Expand Up @@ -72,13 +73,9 @@ async function handleGet(req: NextApiRequest, resp: NextApiResponse) {
message: 'SUCCESSFULLY_SENT_TOKENS',
data: address,
});

}

export default async function FaucetApi(
req: NextApiRequest,
resp: NextApiResponse,
) {
export default async function FaucetApi(req: NextApiRequest, resp: NextApiResponse) {
switch (req.method) {
case 'POST':
return handlePost(req, resp);
Expand All @@ -91,4 +88,4 @@ export default async function FaucetApi(
code: 'INVALID_REQUEST',
});
}
}
}
10 changes: 5 additions & 5 deletions src/pages/faucet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const FaucetPage = () => {
const faqs = [
{
question: 'What is Faucet?',
answer: `To request funds, simply enter your wallet address and hit “Send Me MATIC”. We
answer: `To request funds, simply enter your wallet address and hit “Send Me OP. We
support wallets as received addresses but not smart contracts.`,
},
{
Expand All @@ -70,7 +70,7 @@ const FaucetPage = () => {
{
question: 'How does it work?',
answer: `You can request ${formatUnits((offering as BigNumberish) ?? '0', 18)}
MATIC if the faucet is unlocked. The current unlock duration is
OP if the faucet is unlocked. The current unlock duration is
${formatDuration(Number(lockDuration))} after your successful request.`,
},
];
Expand All @@ -88,7 +88,7 @@ const FaucetPage = () => {
<CardBody>
{address && isConnected && (
<Stack mb={5}>
<Text>{t('faucet.SEND_MATIC_AT')}</Text>
<Text>{t('faucet.SEND_CRYPTO_AT')}</Text>
<Badge
mb={5}
fontSize={'lg'}
Expand Down Expand Up @@ -170,7 +170,7 @@ const FaucetPage = () => {
});
}}
>
{t(locked ? 'faucet.LOCKED' : 'faucet.GET_MATIC_COINS')}
{t(locked ? 'faucet.LOCKED' : 'faucet.GET_CRYPTO_COINS')}
</Button>
</FormControl>
</CardBody>
Expand Down Expand Up @@ -205,7 +205,7 @@ const FaucetPage = () => {
<HStack my={5}>
<Text minWidth={'120px'}>{t('faucet.OFFERING')}:</Text>
<Badge colorScheme={'red'} borderRadius={'full'} px={5} py={1}>
{formatUnits((offering as BigNumberish) ?? '0', 18)} MATIC
{formatUnits((offering as BigNumberish) ?? '0', 18)} OP
</Badge>
</HStack>
<Box>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/contract/etherUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const citSigner = new ethers.Wallet(
);
const faucet = new ethers.Contract(faucetAddress, faucetAbi, citSigner);

export function sendMatic(recipient: string) {
export function sendCrypto(recipient: string) {
return new Promise((resolve, reject) => {
faucet
.requestTokens(recipient, {
Expand Down

0 comments on commit 992e9ff

Please sign in to comment.