Skip to content

Commit

Permalink
@skylar/rc fixes (#4951)
Browse files Browse the repository at this point in the history
* fix poap issues (crash + unrecognized)

* poap copy

* l2 position fixes

* fix filtering

* move filtering after weird mainnet logic

* smol type clean up
  • Loading branch information
skylarbarrera authored and Ibrahim Taveras committed Jul 19, 2023
1 parent 28b71ec commit 438bec6
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 68 deletions.
46 changes: 38 additions & 8 deletions src/components/positions/PositionsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import Routes from '@/navigation/routesNames';
import { analyticsV2 } from '@/analytics';
import { event } from '@/analytics/event';
import { IS_ANDROID } from '@/env';
import { capitalize } from 'lodash';
import { RainbowPosition } from '@/resources/defi/types';
import { capitalize, uniqBy } from 'lodash';
import { RainbowDeposit, RainbowPosition } from '@/resources/defi/types';
import { ethereumUtils } from '@/utils';

type PositionCardProps = {
position: RainbowPosition;
Expand Down Expand Up @@ -48,6 +49,7 @@ function CoinIconStack({ tokens }: { tokens: CoinStackToken[] }) {
size={16}
symbol={token.symbol}
type={token.type}
ignoreBadge
/>
</Box>
);
Expand All @@ -71,17 +73,45 @@ export const PositionCard = ({ position }: PositionCardProps) => {

const depositTokens: CoinStackToken[] = useMemo(() => {
let tokens: CoinStackToken[] = [];
position.deposits.forEach((deposit: any) => {
deposit.underlying.forEach((item: any) => {
position.deposits.forEach((deposit: RainbowDeposit) => {
deposit.underlying.forEach(({ asset }) => {
tokens.push({
address: item.asset.asset_code,
type: AssetType.token,
symbol: item.asset.symbol,
address: asset.asset_code,
type: ethereumUtils.getAssetTypeFromNetwork(asset.network),
symbol: asset.symbol,
});
});
});
position.borrows.forEach((deposit: RainbowDeposit) => {
deposit.underlying.forEach(({ asset }) => {
tokens.push({
address: asset.asset_code,
type: ethereumUtils.getAssetTypeFromNetwork(asset.network),
symbol: asset.symbol,
});
});
});
position.borrows.forEach((deposit: RainbowDeposit) => {
deposit.underlying.forEach(({ asset }) => {
tokens.push({
address: asset.asset_code,
type: ethereumUtils.getAssetTypeFromNetwork(asset.network),
symbol: asset.symbol,
});
});
});
position.borrows.forEach((deposit: RainbowDeposit) => {
deposit.underlying.forEach(({ asset }) => {
tokens.push({
address: asset.asset_code,
type: ethereumUtils.getAssetTypeFromNetwork(asset.network),
symbol: asset.symbol,
});
});
});

return tokens;
const dedupedTokens = uniqBy(tokens, 'symbol');
return dedupedTokens?.slice(0, 5);
}, [position]);

const positionColor =
Expand Down
15 changes: 11 additions & 4 deletions src/hooks/useScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export default function useScanner(enabled: boolean, onSuccess: () => unknown) {
// poap mints
if (data.startsWith(`${POAP_BASE_URL}`)) {
const secretWord = data.split(`${POAP_BASE_URL}`)?.[1];
await getPoapAndOpenSheetWithSecretWord(secretWord, true);
return getPoapAndOpenSheetWithSecretWord(secretWord, true);
}

if (data.startsWith(`https://collectors.poap.xyz/mint/`)) {
Expand All @@ -201,12 +201,12 @@ export default function useScanner(enabled: boolean, onSuccess: () => unknown) {

if (data.startsWith(`https://poap.xyz/claim/`)) {
const qrHash = data.split('https://poap.xyz/claim/')?.[1];
return await getPoapAndOpenSheetWithQRHash(qrHash, true);
return getPoapAndOpenSheetWithQRHash(qrHash, true);
}

if (data.startsWith(`https://app.poap.xyz/claim/`)) {
const qrHash = data.split('https://app.poap.xyz/claim/')?.[1];
return await getPoapAndOpenSheetWithQRHash(qrHash, true);
return getPoapAndOpenSheetWithQRHash(qrHash, true);
}

if (data.startsWith(`${RAINBOW_PROFILES_BASE_URL}/poap`)) {
Expand All @@ -215,7 +215,14 @@ export default function useScanner(enabled: boolean, onSuccess: () => unknown) {
)?.[1];
logger.log('onScan: handling poap scan', { secretWordOrQrHash });
await getPoapAndOpenSheetWithSecretWord(secretWordOrQrHash, true);
await getPoapAndOpenSheetWithQRHash(secretWordOrQrHash, true);
return getPoapAndOpenSheetWithQRHash(secretWordOrQrHash, true);
}

if (data.startsWith(`rainbow://poap`)) {
const secretWordOrQrHash = data.split(`rainbow://poap/`)?.[1];
logger.log('onScan: handling poap scan', { secretWordOrQrHash });
await getPoapAndOpenSheetWithSecretWord(secretWordOrQrHash, true);
return getPoapAndOpenSheetWithQRHash(secretWordOrQrHash, true);
}

// Rainbow profile QR code
Expand Down
2 changes: 1 addition & 1 deletion src/languages/_english.json
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@
"view_on_poap": "View on POAP 􀮶",
"mint_poap": "􀑒 Mint POAP",
"minting": "Minting...",
"minted": "Poap Minted!",
"minted": "POAP Minted!",
"error": "Error Minting",
"error_messages": {
"limit_exceeded": "This POAP is fully minted out!",
Expand Down
2 changes: 1 addition & 1 deletion src/languages/_french.json
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@
"view_on_poap": "View on POAP 􀮶 :)",
"mint_poap": "􀑒 Mint POAP :)",
"minting": "Minting... :)",
"minted": "Poap Minted! :)",
"minted": "POAP Minted! :)",
"error": "Error Minting :)",
"error_messages": {
"limit_exceeded": "This POAP is fully minted out! :)",
Expand Down
44 changes: 24 additions & 20 deletions src/redux/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ import {
TransactionResponse,
} from '@ethersproject/providers';
import isValidDomain from 'is-valid-domain';
import { find, isEmpty, isNil, mapValues, partition, cloneDeep } from 'lodash';
import {
find,
isEmpty,
isNil,
mapValues,
partition,
cloneDeep,
filter,
} from 'lodash';
import { MMKV } from 'react-native-mmkv';
import { Dispatch } from 'redux';
import { ThunkDispatch } from 'redux-thunk';
Expand Down Expand Up @@ -905,7 +913,7 @@ export const maybeFetchF2CHashForPendingTransactions = async (
*/
export const addressAssetsReceived = (
message: AddressAssetsReceivedMessage,
assetsNetwork: Network | null = null
assetsNetwork: Network
) => (
dispatch: ThunkDispatch<
AppState,
Expand All @@ -924,23 +932,7 @@ export const addressAssetsReceived = (

const newAssets = message?.payload?.assets ?? {};

const positionsObj: RainbowPositions | undefined = queryClient.getQueryData(
positionsQueryKey({ address: accountAddress, currency: nativeCurrency })
);

const positionTokens = positionsObj?.positionTokens || [];

let updatedAssets = pickBy(
newAssets,
asset =>
!positionTokens.find(
positionToken => positionToken === `${asset.asset.asset_code}_token`
) &&
asset?.asset?.type !== AssetTypes.trash &&
!shitcoins.includes(asset?.asset?.asset_code?.toLowerCase())
);

let parsedAssets = parseAccountAssets(updatedAssets) as {
let parsedAssets = parseAccountAssets(newAssets) as {
[id: string]: ParsedAddressAsset;
};

Expand All @@ -961,7 +953,7 @@ export const addressAssetsReceived = (

const { accountAssetsData: existingAccountAssetsData } = getState().data;

if (!assetsNetwork) {
if (assetsNetwork === Network.mainnet) {
const existingL2DataOnly = pickBy(
existingAccountAssetsData,
(value: ParsedAddressAsset, index: string) => {
Expand All @@ -979,6 +971,18 @@ export const addressAssetsReceived = (
};
}

const positionsObj: RainbowPositions | undefined = queryClient.getQueryData(
positionsQueryKey({ address: accountAddress, currency: nativeCurrency })
);

const positionTokens = positionsObj?.positionTokens || [];

parsedAssets = pickBy(
parsedAssets,
asset =>
!positionTokens.find(positionToken => positionToken === asset.uniqueId)
);

parsedAssets = pickBy(
parsedAssets,
asset => !!Number(asset?.balance?.amount)
Expand Down
2 changes: 1 addition & 1 deletion src/redux/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ const listenOnAddressMessages = (socket: Socket) => (
socket.on(
messages.ADDRESS_ASSETS.RECEIVED,
(message: AddressAssetsReceivedMessage) => {
dispatch(addressAssetsReceived(message));
dispatch(addressAssetsReceived(message, Network.mainnet));
if (isValidAssetsResponseFromZerion(message)) {
logger.log(
'😬 Cancelling fallback data provider listener. Zerion is good!'
Expand Down
31 changes: 21 additions & 10 deletions src/resources/defi/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NativeCurrencyKey, ZerionAsset } from '@/entities';
import { Network } from '@/networks/types';

export type AddysPositionsResponse =
| {
Expand All @@ -17,6 +18,8 @@ export type NativeDisplay = {
display: string;
};

export type PositionAsset = ZerionAsset & { network: Network };

export type PositionDapp = {
name: string;
url: string;
Expand All @@ -35,46 +38,54 @@ export type PositionsTotals = {
deposits: NativeDisplay;
};
export type Claimable = {
asset: ZerionAsset;
asset: PositionAsset;
quantity: string;
};
export type Deposit = {
apr: string;
apy: string;
asset: ZerionAsset;
asset: PositionAsset;
quantity: string;
total_asset: string; // what does this mean?
underlying: { asset: ZerionAsset; quantity: string }[];
underlying: { asset: PositionAsset; quantity: string }[];
};
export type Borrow = {
apr: string;
apy: string;
asset: ZerionAsset;
asset: PositionAsset;
quantity: string;
total_asset: string; // what does this mean?
underlying: { asset: ZerionAsset; quantity: string }[];
underlying: { asset: PositionAsset; quantity: string }[];
};

export type RainbowClaimable = {
asset: ZerionAsset;
asset: PositionAsset;
quantity: string;
native: NativeDisplay;
};
export type RainbowDeposit = {
apr: string;
apy: string;
asset: ZerionAsset;
asset: PositionAsset;
quantity: string;
total_asset: string; // what does this mean?
underlying: { asset: ZerionAsset; quantity: string; native: NativeDisplay }[];
underlying: {
asset: PositionAsset;
quantity: string;
native: NativeDisplay;
}[];
};
export type RainbowBorrow = {
apr: string;
apy: string;
asset: ZerionAsset;
asset: PositionAsset;
quantity: string;
total_asset: string; // what does this mean?
underlying: { asset: ZerionAsset; quantity: string; native: NativeDisplay }[];
underlying: {
asset: PositionAsset;
quantity: string;
native: NativeDisplay;
}[];
};

// TODO: need to add dapp metadata once its added via BE
Expand Down
24 changes: 17 additions & 7 deletions src/resources/defi/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Deposit,
NativeDisplay,
Position,
PositionAsset,
PositionsTotals,
RainbowBorrow,
RainbowClaimable,
Expand All @@ -32,9 +33,13 @@ export const parsePosition = (
(deposit: Deposit): RainbowDeposit => {
deposit.underlying = deposit.underlying?.map(
(underlying: {
asset: ZerionAsset;
asset: PositionAsset;
quantity: string;
}): { asset: ZerionAsset; quantity: string; native: NativeDisplay } => {
}): {
asset: PositionAsset;
quantity: string;
native: NativeDisplay;
} => {
const nativeDisplay = convertRawAmountToNativeDisplay(
underlying.quantity,
underlying.asset.decimals,
Expand All @@ -59,9 +64,13 @@ export const parsePosition = (
(borrow: Borrow): RainbowBorrow => {
borrow.underlying = borrow.underlying.map(
(underlying: {
asset: ZerionAsset;
asset: PositionAsset;
quantity: string;
}): {
asset: PositionAsset;
quantity: string;
}): { asset: ZerionAsset; quantity: string; native: NativeDisplay } => {
native: NativeDisplay;
} => {
const nativeDisplay = convertRawAmountToNativeDisplay(
underlying.quantity,
underlying.asset.decimals,
Expand Down Expand Up @@ -176,9 +185,10 @@ export const parsePositions = (

parsedPositions.forEach(({ deposits }) => {
deposits.forEach(({ asset }) => {
const assetType = ethereumUtils.getAssetTypeFromNetwork(Network.mainnet);
const uniqueId = `${asset.asset_code}_${assetType}`;

const uniqueId = ethereumUtils.getUniqueId(
asset.asset_code.toLowerCase(),
asset.network
);
positionTokens.push(uniqueId);
});
});
Expand Down
24 changes: 12 additions & 12 deletions src/screens/mints/PoapSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,18 @@ const PoapSheet = () => {

const actionOnPress = useCallback(async () => {
if (claimStatus === 'claimed') {
if (!nft) goBack();

navigate(Routes.EXPANDED_ASSET_SHEET, {
asset: nft,
backgroundOpacity: 1,
cornerRadius: 'device',
external: false,
springDamping: 1,
topOffset: 0,
transitionDuration: 0.25,
type: 'unique_token',
});
if (nft) {
navigate(Routes.EXPANDED_ASSET_SHEET, {
asset: nft,
backgroundOpacity: 1,
cornerRadius: 'device',
external: false,
springDamping: 1,
topOffset: 0,
transitionDuration: 0.25,
type: 'unique_token',
});
}
} else {
if (poapMintType === 'secretWord') {
await claimPoapBySecret();
Expand Down

0 comments on commit 438bec6

Please sign in to comment.