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

AMB-4966 #892

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
config: {
usesNonExemptEncryption: false
},
bundleIdentifier: 'io.test.airdao',
bundleIdentifier: 'io.airdao.app',
googleServicesFile: './firebase/GoogleService-Info.plist',
infoPlist: {
UIBackgroundModes: ['fetch', 'remote-notification'],
Expand All @@ -37,13 +37,13 @@ module.exports = {
foregroundImage: './assets/adaptive-icon.png',
backgroundColor: '#ffffff'
},
package: 'io.test.airdao',
package: 'io.airdao.app',
permissions: [
'android.permission.CAMERA',
'android.permission.RECORD_AUDIO'
],
playStoreUrl:
'https://play.google.com/store/apps/details?id=io.test.airdao.app',
'https://play.google.com/store/apps/details?id=io.airdao.app.app',
googleServicesFile: './firebase/google-services.json'
},
notification: {
Expand Down
33 changes: 33 additions & 0 deletions src/api/harbor/abi/harbor-unstake-log-abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export const UNSTAKE_LOG_ABI = [
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'address',
name: 'account',
type: 'address'
},
{
indexed: false,
internalType: 'uint256',
name: 'amount',
type: 'uint256'
},
{
indexed: false,
internalType: 'uint256',
name: 'unlockTime',
type: 'uint256'
},
{
indexed: false,
internalType: 'uint256',
name: 'creationTime',
type: 'uint256'
}
],
name: 'UnstakeLocked',
type: 'event'
}
];
59 changes: 59 additions & 0 deletions src/api/harbor/harbor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { RawRecord } from '@nozbe/watermelondb';
import Config from '@constants/config';
import { HARBOR_ABI } from '@api/harbor/abi/harbor';
import { Cache, CacheKey } from '@lib/cache';
import { UNSTAKE_LOG_ABI } from '@api/harbor/abi/harbor-unstake-log-abi';
import { ILogs } from '@entities/harbor/model/types';

function calculateAPR(interestNumber: number, interestPeriodNumber: number) {
const r = interestNumber / 1000000000;
Expand Down Expand Up @@ -124,6 +126,62 @@ const getClaimAmount = async (address: string) => {
}
};

const getWithdrawalRequests = async (address: string) => {
try {
const contract = new ethers.Contract(
Config.LIQUID_STAKING_ADDRESS,
UNSTAKE_LOG_ABI,
provider
);
const filter = contract.filters.UnstakeLocked(address);
const rawWithdrawalsList = await contract.queryFilter(filter);
const withdrawalsList: ILogs[] = [];

const formatData = (date: Date) =>
date
.toLocaleString('en-GB', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
hour12: false
})
.replace(',', '');

for (let i = 0; i < rawWithdrawalsList.length; i++) {
const currEvent: any = rawWithdrawalsList[i];

const requestDateTime = new Date(
Number(currEvent.args.creationTime) * 1000
);
const formattedRequestDateTime = formatData(requestDateTime);

const unlockDateTime = new Date(Number(currEvent.args.unlockTime) * 1000);
const formattedUnlockDateTime = formatData(unlockDateTime);

const status = unlockDateTime < new Date() ? 'Success' : 'Pending';

const amount = BigNumber.from(currEvent.args.amount);

// add event to the beginning of the list to sort it from newest to oldest
withdrawalsList.unshift({
amount,
tokenAddress: currEvent.address,
requestData: formattedRequestDateTime,
unlockData: formattedUnlockDateTime,
status
});
}

return withdrawalsList.filter(
(item) => item.tokenAddress === Config.LIQUID_STAKING_ADDRESS
);
} catch (e) {
throw e;
}
};

const processStake = async (
wallet: RawRecord | undefined,
value: BigNumber
Expand Down Expand Up @@ -208,6 +266,7 @@ export const harborService = {
getUnStakeLockTime,
getTier,
getClaimAmount,
getWithdrawalRequests,
processStake,
processWithdraw,
processClaimReward
Expand Down
2 changes: 1 addition & 1 deletion src/components/modular/AnimatedTabsV2/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const styles = StyleSheet.create({
tabHeader: {
fontFamily: 'Inter_700Bold',
color: COLORS.midnight,
fontSize: 16,
fontSize: scale(16),
marginLeft: scale(8)
},
tabContainer: {
Expand Down
14 changes: 7 additions & 7 deletions src/components/templates/InputWithoutTokenSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const InputWithoutTokenSelect = forwardRef<
<View style={[styles.wrapper, inputError ? styles.errorWrap : {}]}>
{label && (
<Text
fontSize={14}
fontSize={scale(14)}
fontFamily="Inter_500Medium"
color={COLORS.neutral800}
>
Expand Down Expand Up @@ -199,9 +199,9 @@ export const InputWithoutTokenSelect = forwardRef<
</Pressable>
</View>
<Row justifyContent="space-between" alignItems="center">
<Text fontSize={12}>
<Text fontSize={scale(12)}>
{t('common.balance')}:{' '}
<Text fontSize={12} color={COLORS.neutral900}>
<Text fontSize={scale(12)} color={COLORS.neutral900}>
{NumberUtils.formatNumber(
+NumberUtils.limitDecimalCount(
token.balance.formattedBalance,
Expand All @@ -215,15 +215,15 @@ export const InputWithoutTokenSelect = forwardRef<
<Button style={styles.button} onPress={onPressMaxAmount}>
<Text
fontFamily="Inter_600SemiBold"
fontSize={12}
fontSize={scale(12)}
color={COLORS.brand600}
>
{t('bridge.preview.button.max')}
</Text>
</Button>
) : (
<View>
<Text fontSize={12} color={COLORS.error500}>
<Text fontSize={scale(12)} color={COLORS.error500}>
{inputError}
</Text>
</View>
Expand Down Expand Up @@ -252,13 +252,13 @@ export const InputWithoutTokenSelect = forwardRef<
<Row alignItems="center">
<TokenLogo token={exchange.token} />
<Spacer horizontal value={scale(8)} />
<Text fontSize={14} color={COLORS.neutral900}>
<Text fontSize={scale(14)} color={COLORS.neutral900}>
{exchange.token}
</Text>
</Row>
<Text
color={exchange.value ? COLORS.neutral900 : COLORS.neutral400}
fontSize={14}
fontSize={scale(14)}
>
{+exchange?.value > 0 ? exchange.value : 0}
</Text>
Expand Down
14 changes: 14 additions & 0 deletions src/entities/harbor/model/harbor-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import { harborService } from '@api/harbor/harbor-service';
export const useHarborStore = create<HarborStoreModel>((set) => ({
data: DEFAULT_DATA,
loading: false,
withdrawListLoader: false,
activeAmbTier: REWARD_TIERS_LIST.amb[0],
activeBondTier: REWARD_TIERS_LIST.bond[2],
bondAmount: '0',
ambAmount: '0',
claimAmount: BigNumber.from(0),
withdrawalList: [],
getClaimAmount: async (address: string) => {
set({ claimAmount: await harborService.getClaimAmount(address) });
},
Expand All @@ -24,6 +26,18 @@ export const useHarborStore = create<HarborStoreModel>((set) => ({
setActiveAmbTier: (activeAmbTier: TierRewardItem) => set({ activeAmbTier }),
setActiveBondTier: (activeBondTier: TierRewardItem) =>
set({ activeBondTier }),
updateWithdrawList: async (address: string) => {
try {
set({ withdrawListLoader: true });
const withdrawalList = await harborService.getWithdrawalRequests(address);
set({ withdrawalList });
} finally {
set({ withdrawListLoader: false });
}
},
clearWithdrawList: async () => {
set({ withdrawalList: [] });
},
updateAll: async (address: string) => {
try {
set({ loading: true });
Expand Down
11 changes: 11 additions & 0 deletions src/entities/harbor/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,24 @@ export interface TierRewardList {
amb: TierRewardItem[];
bond: TierRewardItem[];
}
export interface ILogs {
amount: BigNumber;
tokenAddress: string;
requestData: string;
unlockData: string;
status: string;
}

export interface HarborStoreModel {
data: HarborDataModel;
withdrawalList: ILogs[];
withdrawListLoader: boolean;
activeAmbTier: TierRewardItem;
setActiveAmbTier: (payload: TierRewardItem) => void;
activeBondTier: TierRewardItem;
claimAmount: BigNumber;
updateWithdrawList: (payload: string) => void;
clearWithdrawList: () => void;
getClaimAmount: (payload: string) => void;
setActiveBondTier: (payload: TierRewardItem) => void;
bondAmount: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const ErrorTemplate = ({ onClose }: PreviewFormModel) => {
<Spacer value={scale(12)} />
<Text
color={COLORS.neutral900}
fontSize={24}
fontSize={scale(24)}
fontFamily="Inter_700Bold"
>
{t('common.status.failed')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,27 @@ export const FormTemplate = ({
{!!item?.name && (
<Text
fontFamily={'Inter_500Medium'}
fontSize={14}
fontSize={scale(14)}
color={COLORS.neutral600}
>
{t(item.name)}
</Text>
)}
<Row>
<Text
fontSize={14}
fontSize={scale(14)}
color={COLORS.neutral900}
style={item?.textStyle || {}}
>
{item.value}{' '}
</Text>
{!!item.timeSymbol && (
<Text fontSize={14} color={COLORS.neutral900}>
<Text fontSize={scale(14)} color={COLORS.neutral900}>
{t(item.timeSymbol)}
</Text>
)}
{!!item.symbol && (
<Text fontSize={14} color={COLORS.neutral900}>
<Text fontSize={scale(14)} color={COLORS.neutral900}>
{item.symbol}
</Text>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { StringUtils } from '@utils/string';
import { COLORS } from '@constants/colors';
import { contentBox } from '@components/styles';
import { Toast, ToastPosition, ToastType } from '@components/modular';
import { scale } from '@utils/scaling';

interface CopyHashModel {
hash: string;
Expand All @@ -28,8 +29,9 @@ export const CopyHash = ({ hash }: CopyHashModel) => {
<Pressable onPress={onTxPress}>
<Row style={contentBox}>
<GlobeIcon color={COLORS.neutral600} />
<Text>{t('common.transaction')}</Text>
<Text fontSize={scale(12)}>{t('common.transaction')}</Text>
<Text
fontSize={scale(12)}
style={{
textDecorationLine: 'underline',
color: COLORS.neutral900
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ export const SuccessTemplate = ({
return (
<View style={{ paddingVertical: scale(6) }}>
<Row justifyContent="space-between">
<Text fontSize={14} color={COLORS.neutral900}>
<Text fontSize={scale(14)} color={COLORS.neutral900}>
{t(item.name)}
</Text>
<Text
fontSize={14}
fontSize={scale(14)}
color={COLORS.neutral900}
style={item.textStyle || {}}
>
Expand Down Expand Up @@ -94,15 +94,15 @@ export const SuccessTemplate = ({
)}
<Spacer value={scale(12)} />
<PrimaryButton onPress={onPreviewClose}>
<Text fontSize={14} color={COLORS.neutral0}>
<Text fontSize={scale(14)} color={COLORS.neutral0}>
{t('kosmos.button.close')}
</Text>
</PrimaryButton>
{isWithdrawModal && (
<>
<Spacer value={scale(12)} />
<SecondaryButton onPress={goToMyRequests}>
<Text fontSize={14} color={COLORS.neutral900}>
<Text fontSize={scale(14)} color={COLORS.neutral900}>
{t('harbor.requests.header')}
</Text>
</SecondaryButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const SuccessTitle = ({
<Spacer value={scale(8)} />
<Text
fontFamily="Inter_600SemiBold"
fontSize={14}
fontSize={scale(14)}
color={COLORS.neutral900}
align="center"
style={titleData.textStyle || {}}
Expand All @@ -40,7 +40,7 @@ export const SuccessTitle = ({
<Text
fontFamily="Inter_700Bold"
color={COLORS.neutral900}
fontSize={24}
fontSize={scale(24)}
>
{' '}
{titleData.value} {titleData.symbol}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const StakeInfoContainer = ({
</Text>
</Row>
<View style={{ alignItems: 'flex-end' }}>
<Text fontSize={12}>{t('harbor.staked.amount')}</Text>
<Text fontSize={scale(12)}>{t('harbor.staked.amount')}</Text>
<Spacer value={scale(8)} />
<Text style={styles.topText} color={COLORS.neutral900}>
{NumberUtils.limitDecimalCount(formatEther(userStaked), 2)}
Expand Down
Loading
Loading