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 18, 2024
1 parent f7a61eb commit f5986b6
Show file tree
Hide file tree
Showing 129 changed files with 2,389 additions and 1,305 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.

1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
3 changes: 3 additions & 0 deletions apps/explorer/src/components/AddressesCardGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function AddressesCardGraph(): JSX.Element {
? addressMetrics.cumulativeAddresses.toString()
: '--'
}
showSupportingLabel={false}
/>
</div>

Expand All @@ -67,6 +68,7 @@ export function AddressesCardGraph(): JSX.Element {
? addressMetrics.cumulativeActiveAddresses.toString()
: '--'
}
showSupportingLabel={false}
/>
</div>
</div>
Expand All @@ -78,6 +80,7 @@ export function AddressesCardGraph(): JSX.Element {
? addressMetrics.dailyActiveAddresses.toString()
: '--'
}
showSupportingLabel={false}
/>
<div className="flex min-h-[180px] flex-1 flex-col items-center justify-center rounded-xl transition-colors">
{isPending ? (
Expand Down
2 changes: 2 additions & 0 deletions apps/explorer/src/components/TransactionsCardGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function TransactionsCardGraph() {
size={LabelTextSize.Large}
label="Total"
text={totalTransactions ? formatBalance(totalTransactions, 0) : '--'}
showSupportingLabel={false}
/>
</div>

Expand All @@ -97,6 +98,7 @@ export function TransactionsCardGraph() {
? lastEpochTotalTransactions.toString()
: '--'
}
showSupportingLabel={false}
/>
</div>
</div>
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
Loading

0 comments on commit f5986b6

Please sign in to comment.