Skip to content

Commit

Permalink
feat(devx): Add filter flag to Iota CLI
Browse files Browse the repository at this point in the history
Signed-off-by: salaheldinsoliman <[email protected]>
  • Loading branch information
salaheldinsoliman committed Sep 17, 2024
1 parent 9e9c0ed commit 8e723d4
Show file tree
Hide file tree
Showing 64 changed files with 1,435 additions and 389 deletions.
3 changes: 2 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"sponsored-transactions",
"kiosk-demo",
"kiosk-cli",
"@iota/zklogin"
"@iota/zklogin",
"@iota/iotans-toolkit"
],
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
"onlyUpdatePeerDependentsWhenOutOfRange": true
Expand Down
6 changes: 0 additions & 6 deletions .changeset/ten-vans-cross.md

This file was deleted.

113 changes: 112 additions & 1 deletion apps/apps-backend/src/features/features.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ const walletDapps = [
icon: 'https://iotafrens.com/icons/favicon.ico',
tags: ['Social'],
},
{
name: 'Iota Name Service (IotaNS)',
description: 'Find your .iota name!',
link: 'https://iotans.io/',
icon: 'https://raw.githubusercontent.com/IotaNSdapp/docs/main/IotaNS-small2.jpg',
tags: ['Infra'],
},
{
name: 'Wormhole Connect',
description:
Expand Down Expand Up @@ -152,6 +159,9 @@ export const developmentFeatures = {
'0x30a644c3485ee9b604f52165668895092191fcaf5489a846afa7fc11cdb9b24a',
],
},
iotans: {
defaultValue: false,
},
'team-address-overrides': {
defaultValue: {
addresses: [
Expand Down Expand Up @@ -205,7 +215,15 @@ export const developmentFeatures = {
defaultValue: 0.0025,
},
'wallet-dapps': {
defaultValue: [],
defaultValue: [
{
name: 'Iota Name Service (IotaNS)',
description: 'Find your .iota name!',
link: 'https://iotans.io/',
icon: 'https://raw.githubusercontent.com/IotaNSdapp/docs/main/IotaNS-small2.jpg',
tags: ['Infra'],
},
],
rules: [
{
condition: {
Expand Down Expand Up @@ -379,6 +397,83 @@ export const developmentFeatures = {
},
],
},
'iotans-enable-okx-wallet': {
defaultValue: false,
rules: [
{
condition: {
network: {
$ne: 'mainnet',
},
},
force: true,
},
],
},
'iotans-enable-day-one-nft-domain-claim': {
defaultValue: false,
},
'iotans-nft-personalization': {
defaultValue: false,
rules: [
{
condition: {
network: {
$ne: 'mainnet',
},
},
force: true,
},
],
},
'iotans-front-page-banner': {
defaultValue: {
enabled: false,
dismissKey: 'quests-3-interstitial-live',
imageUrl: 'https://fe-assets.iota.org/quests_3_updated_large_corrected.svg',
bannerUrl: 'https://tech.iota.org/quest-3/',
},
},
'iotans-enable-coupons': {
defaultValue: false,
},
'iotans-enable-discord': {
defaultValue: false,
rules: [
{
condition: {
network: {
$ne: 'mainnet',
},
},
force: true,
},
],
},
'iotans-free-claims': {
defaultValue: false,
},
'iotans-banner': {
defaultValue: {
content:
"IotaNS is experiencing some issues. We're working to fix the problem and appreciate your patience.",
isActive: false,
isDismissable: true,
},
},
'iotans-enable-subname': {
defaultValue: false,
rules: [
{
condition: {
network: {
$ne: 'mainnet',
},
},
force: true,
},
],
},
expiration_period: {
defaultValue: 30,
rules: [
Expand All @@ -392,6 +487,22 @@ export const developmentFeatures = {
},
],
},
'iotans-name-burn-expired-name': {
defaultValue: false,
rules: [
{
force: true,
},
],
},
'iotans-name-enable-v2-design': {
defaultValue: false,
rules: [
{
force: true,
},
],
},
'validator-page-staking': {
defaultValue: true,
},
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/api/SentryHttpTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { IotaHTTPTransport } from '@iota/iota-sdk/client';
import * as Sentry from '@sentry/react';

const IGNORED_METHODS: string[] = [];
const IGNORED_METHODS = ['iotax_resolveNameServiceNames', 'iotax_resolveNameServiceAddresses'];

export class SentryHttpTransport extends IotaHTTPTransport {
private url: string;
Expand Down
1 change: 1 addition & 0 deletions apps/core/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './useFormatCoin';
export * from './useTimeAgo';
export * from './useGetValidatorsEvents';
export * from './useGetValidatorsApy';
export * from './nameService';
export * from './useGetTransferAmount';
export * from './useGetObject';
export * from './useGetDynamicFields';
Expand Down
57 changes: 57 additions & 0 deletions apps/core/src/hooks/nameService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) Mysten Labs, Inc.
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { useFeatureIsOn } from '@growthbook/growthbook-react';
import { useIotaClient } from '@iota/dapp-kit';
import { useQuery } from '@tanstack/react-query';

const IOTA_NS_FEATURE_FLAG = 'iotans';

// This should align with whatever names we want to be able to resolve.
const IOTA_NS_DOMAINS = ['.iota'];
export function isIotaNSName(name: string) {
return IOTA_NS_DOMAINS.some((domain) => name.endsWith(domain));
}

export function useIotaNSEnabled() {
return useFeatureIsOn(IOTA_NS_FEATURE_FLAG);
}

export function useResolveIotaNSAddress(name?: string | null, enabled?: boolean) {
const client = useIotaClient();
const enabledIotaNs = useIotaNSEnabled();

return useQuery({
queryKey: ['resolve-iotans-address', name],
queryFn: async () => {
return await client.resolveNameServiceAddress({
name: name!,
});
},
enabled: !!name && enabled && enabledIotaNs,
refetchOnWindowFocus: false,
retry: false,
});
}

export function useResolveIotaNSName(address?: string | null) {
const client = useIotaClient();
const enabled = useIotaNSEnabled();

return useQuery({
queryKey: ['resolve-iotans-name', address],
queryFn: async () => {
// NOTE: We only fetch 1 here because it's the default name.
const { data } = await client.resolveNameServiceNames({
address: address!,
limit: 1,
});

return data[0] || null;
},
enabled: !!address && enabled,
refetchOnWindowFocus: false,
retry: false,
});
}
9 changes: 7 additions & 2 deletions apps/core/src/hooks/useIotaAddressValidation.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { useIotaNSEnabled } from '.';
import { useIotaClient } from '@iota/dapp-kit';
import { useMemo } from 'react';
import { createIotaAddressValidation } from '../utils';

export function useIotaAddressValidation() {
const client = useIotaClient();
const iotaNSEnabled = useIotaNSEnabled();

return useMemo(() => {
return createIotaAddressValidation();
}, []);
return createIotaAddressValidation(client, iotaNSEnabled);
}, [client, iotaNSEnabled]);
}
10 changes: 8 additions & 2 deletions apps/core/src/utils/transaction/createNftSendValidationSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { type IotaClient } from '@iota/iota-sdk/client';
import * as Yup from 'yup';
import { createIotaAddressValidation } from '../validation';
import { ValidationError } from 'yup';

export function createNftSendValidationSchema(senderAddress: string, objectId: string) {
export function createNftSendValidationSchema(
senderAddress: string,
objectId: string,
client?: IotaClient,
iotaNSEnabled?: boolean,
) {
return Yup.object({
to: createIotaAddressValidation()
to: createIotaAddressValidation(client, iotaNSEnabled)
.test(
'sender-address',
'NFT is owned by this address',
Expand Down
20 changes: 19 additions & 1 deletion apps/core/src/utils/validation/createIotaAdressValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,36 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { IotaClient } from '@iota/iota-sdk/client';
import { isIotaNSName } from '../../hooks';
import { isValidIotaAddress } from '@iota/iota-sdk/utils';
import * as Yup from 'yup';
import { ValidationError } from 'yup';

export { ValidationError };

export function createIotaAddressValidation() {
export function createIotaAddressValidation(client?: IotaClient, iotaNSEnabled?: boolean) {
const resolveCache = new Map<string, boolean>();

return Yup.string()
.ensure()
.trim()
.required()
.test('is-iota-address', 'Invalid address. Please check again.', async (value) => {
if (client && iotaNSEnabled && isIotaNSName(value)) {
if (resolveCache.has(value)) {
return resolveCache.get(value)!;
}

const address = await client.resolveNameServiceAddress({
name: value,
});

resolveCache.set(value, !!address);

return !!address;
}

return isValidIotaAddress(value);
})
.label("Recipient's address");
Expand Down
10 changes: 8 additions & 2 deletions apps/explorer/src/components/gas-breakdown/GasBreakdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { CoinFormat, type TransactionSummary, useFormatCoin } from '@iota/core';
import {
CoinFormat,
type TransactionSummary,
useFormatCoin,
useResolveIotaNSName,
} from '@iota/core';
import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils';
import { Heading, Text } from '@iota/ui';

Expand Down Expand Up @@ -95,6 +100,7 @@ interface GasBreakdownProps {

export function GasBreakdown({ summary }: GasBreakdownProps): JSX.Element | null {
const gasData = summary?.gas;
const { data: iotansDomainName } = useResolveIotaNSName(gasData?.owner);

if (!gasData) {
return null;
Expand Down Expand Up @@ -126,7 +132,7 @@ export function GasBreakdown({ summary }: GasBreakdownProps): JSX.Element | null
<Text variant="pBody/medium" color="steel-darker">
Paid by
</Text>
<AddressLink address={owner} />
<AddressLink label={iotansDomainName || undefined} address={owner} />
</div>
)}

Expand Down
9 changes: 4 additions & 5 deletions apps/explorer/src/components/owned-coins/CoinIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

import { useCoinMetadata } from '@iota/core';
import { Unstaked } from '@iota/icons';
import { IotaLogoMark as Iota } from '@iota/ui-icons';
import { Iota, Unstaked } from '@iota/icons';
import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils';
import { cva, type VariantProps } from 'class-variance-authority';

Expand All @@ -26,7 +25,7 @@ const imageStyle = cva(['flex rounded-2xl'], {

function IotaCoin(): JSX.Element {
return (
<Iota className="flex h-full w-full rounded-2xl p-xxxs text-neutral-0 dark:text-neutral-100" />
<Iota className="flex h-full w-full items-center justify-center rounded-2xl bg-iota p-1.5 text-body text-white" />
);
}

Expand All @@ -37,7 +36,7 @@ type NonIotaCoinProps = {
function NonIotaCoin({ coinType }: NonIotaCoinProps): JSX.Element {
const { data: coinMeta } = useCoinMetadata(coinType);
return (
<div className="flex h-full w-full items-center justify-center rounded-2xl">
<div className="flex h-full w-full items-center justify-center rounded-2xl bg-gray-40 text-hero-darkest text-opacity-30">
{coinMeta?.iconUrl ? (
<ImageIcon
size="sm"
Expand All @@ -47,7 +46,7 @@ function NonIotaCoin({ coinType }: NonIotaCoinProps): JSX.Element {
circle
/>
) : (
<div className="flex h-full w-full items-center justify-center rounded-2xl">
<div className="flex h-full w-full items-center justify-center rounded-2xl border-2 border-hero-darkest border-opacity-10">
<Unstaked className="h-2.5 w-2.5" />
</div>
)}
Expand Down
Loading

0 comments on commit 8e723d4

Please sign in to comment.