Skip to content

Commit

Permalink
[feature] [LearnAndEarn] add support other assets (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernardo Vieira authored Oct 23, 2023
1 parent a625cbe commit 8f181c5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
30 changes: 28 additions & 2 deletions src/views/LearnAndEarn/Helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,40 @@ import React from 'react';
import RichText from '../../libs/Prismic/components/RichText';
import String from '../../libs/Prismic/components/String';

export const ctaText = (status: string, reward: number, isLAEUser: boolean) => {
function tokenAddressToName(tokenAddress: string) {
// addresses for alfajores and mainnet
switch (tokenAddress?.toLowerCase()) {
case '0x73a2de6a8370108d43c3c80430c84c30df323ed2':
case '0x46c9757c5497c5b1f2eb73ae79b6b67d119b0b58':
return '$PACT';
case '0x874069fa1eb16d44d622f2e0ca25eea172369bc1':
case '0x765de816845861e75a25fca122bb6898b8b1282a':
return 'cUSD';
default:
return '$PACT';
}
}

export const ctaText = (
status: string,
reward: number,
rewardAsset: string,
isLAEUser: boolean
) => {
const { view } = usePrismicData();
const { earnRewards } = view.data;

switch (status) {
case 'available':
return isLAEUser ? (
<RichText content={earnRewards} medium variables={{ reward }} />
<RichText
content={earnRewards}
medium
variables={{
asset: tokenAddressToName(rewardAsset),
reward
}}
/>
) : (
<Message id="viewLessons" />
);
Expand Down
1 change: 1 addition & 0 deletions src/views/LearnAndEarn/LevelsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const LevelsTable = (props: any) => {
{ctaText(
elem?.status,
elem?.data?.reward,
elem?.asset,
isLAEUser
)}
</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/views/MicroCredit/Application/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ const ApplicationForm = (props: any) => {
submit: status
};

const response = await submitForm(matrixJson as any) as any;
const response = (await submitForm(matrixJson as any)) as any;

setApplicationId(response?.data?.id);

Expand Down
9 changes: 7 additions & 2 deletions src/views/MicroCredit/Contract/ContractForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import { handleSignature } from 'src/helpers/handleSignature';
import { selectCurrentUser } from '../../../state/slices/auth';
import { selectRates } from '../../../state/slices/rates';
import { useEffect, useRef, useState } from 'react';
import { useGetMicrocreditPreSignedMutation, useLazyGetBorrowerQuery } from 'src/api/microcredit';
import {
useGetMicrocreditPreSignedMutation,
useLazyGetBorrowerQuery
} from 'src/api/microcredit';
import { usePDF } from '@react-pdf/renderer';
import { useSelector } from 'react-redux';
import { useSignatures } from '@impact-market/utils/useSignatures';
Expand Down Expand Up @@ -221,7 +224,9 @@ const ContractForm = (props: any) => {
`${config.baseApiUrl}/microcredit/docs`,
{
body: JSON.stringify({
applicationId: formData?.forms[formData?.forms.length - 1]?.id || 1,
applicationId:
formData?.forms[formData?.forms.length - 1]
?.id || 1,
docs: [
{
category: 1,
Expand Down

0 comments on commit 8f181c5

Please sign in to comment.