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

import ERTP types #104

Merged
merged 9 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ jobs:
- run: yarn lint
- run: yarn test
- run: yarn docs
- run: yarn format --check
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"eslint-config-jessie": "^0.0.6",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsdoc": "^46.2.6",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-no-only-tests": "^3.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-components/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ module.exports = {
'@typescript-eslint/no-unused-vars': 'warn',
'no-console': 'warn',
},
}
};
2 changes: 1 addition & 1 deletion packages/react-components/.prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"printWidth": 80,
"endOfLine": "auto",
"arrowParens": "avoid"
}
}
4 changes: 2 additions & 2 deletions packages/react-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"./dist/style.css": "./dist/style.css"
},
"scripts": {
"build": "tsc && vite build",
"build": "tsc && NODE_OPTIONS=--max-old-space-size=4096 vite build",
"lint": "eslint --ext .js,.jsx,.ts,.tsx",
"lint:fix": "eslint --ext .js,.jsx,.ts,.tsx --fix",
"test": "vitest run --passWithNoTests",
Expand Down Expand Up @@ -51,7 +51,7 @@
"eslint": "8.46.0",
"eslint-config-prettier": "9.0.0",
"eslint-config-standard-with-typescript": "37.0.0",
"eslint-plugin-import": "2.28.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "16.0.1",
"eslint-plugin-promise": "6.1.1",
"eslint-plugin-react": "7.33.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-components/postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module.exports = {
tailwindcss: {},
autoprefixer: {},
},
}
};
10 changes: 8 additions & 2 deletions packages/react-components/src/lib/components/AmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const noop = () => {
/* no-op */
};

type Props = {
export type AmountInputProps = {
value: NatValue | null;
decimalPlaces: number;
className?: React.HtmlHTMLAttributes<HTMLInputElement>['className'];
Expand All @@ -15,7 +15,13 @@ type Props = {
};

const RenderAmountInput = (
{ value, decimalPlaces, className, onChange = noop, disabled = false }: Props,
{
value,
decimalPlaces,
className,
onChange = noop,
disabled = false,
}: AmountInputProps,
ref?: Ref<HTMLInputElement>,
) => {
const { displayString, handleInputChange } = useAmountInput({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { agoricChain, prettyTestChainName } from '../config/index.js';
import { ChangeChainCombobox } from '@interchain-ui/react';
import { useState } from 'react';

type Props = {
export type NetworkDropdownProps = {
networkConfigs: NetworkConfig[];
label?: ChangeChainCombobox['label'];
size?: ChangeChainCombobox['size'];
Expand Down Expand Up @@ -33,7 +33,7 @@ export const NetworkDropdown = ({
maxHeight,
size = 'md',
appearance = 'bold',
}: Props) => {
}: NetworkDropdownProps) => {
const { networkConfig, setNetworkConfig } = useAgoricNetwork();
assert(
networkConfig && setNetworkConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import { useAgoricNetwork } from '../hooks';
import BldIcon from '../icons/Bld';
import type { ChangeEvent } from 'react';

type Props = {
export type NodeSelectorModalProps = {
isOpen?: boolean;
onClose: () => void;
};

export const NodeSelectorModal = ({ onClose, isOpen = false }: Props) => {
export const NodeSelectorModal = ({
onClose,
isOpen = false,
}: NodeSelectorModalProps) => {
const { networkConfig, setNetworkConfig } = useAgoricNetwork();
const defaultRest = networkConfig?.apis?.rest?.at(0);
const defaultRpc = networkConfig?.apis?.rpc?.at(0);
Expand Down
12 changes: 7 additions & 5 deletions packages/react-components/src/lib/context/AgoricContext.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { createContext } from 'react';
import {
type AmountValue,
makeAgoricWalletConnection,
} from '@agoric/web-components';
import { makeAgoricWalletConnection } from '@agoric/web-components';
import type { ChainStorageWatcher } from '@agoric/rpc';
import type { Brand, Amount, AssetKind } from '@agoric/ertp/src/types';
import type {
Brand,
Amount,
AssetKind,
AmountValue,
} from '@agoric/ertp/src/types';

export type PurseJSONState<T extends AssetKind> = {
brand: Brand;
Expand Down
8 changes: 4 additions & 4 deletions packages/react-components/src/lib/context/AgoricProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import type { MainWalletBase, WalletConnectOptions } from '@cosmos-kit/core';

import '@interchain-ui/react/styles';

type Props = {
export type AgoricProviderProps = PropsWithChildren<{
wallets: MainWalletBase[];
defaultNetworkConfig: NetworkConfig;
walletConnectOptions?: WalletConnectOptions;
onConnectionError?: (e: unknown) => void;
};
}>;

export const AgoricProvider = (props: PropsWithChildren<Props>) => {
export const AgoricProvider = (props: AgoricProviderProps) => {
return (
<NetworkProvider defaultNetworkConfig={props.defaultNetworkConfig}>
<AgoricProviderInner {...props} />
Expand All @@ -29,7 +29,7 @@ const AgoricProviderInner = ({
walletConnectOptions,
children,
onConnectionError,
}: PropsWithChildren<Props>) => {
}: AgoricProviderProps) => {
const { networkConfig } = useContext(NetworkContext);
assert(networkConfig, 'Network config missing from context');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import { subscribeLatest } from '@agoric/notifier';
import type { ChainName } from 'cosmos-kit';
import type { AssetKind } from '@agoric/ertp/src/types';

type Props = {
export type AgoricProviderLiteProps = PropsWithChildren<{
chainName?: ChainName;
useCustomEndpoints?: boolean;
onConnectionError?: (e: unknown) => void;
};
}>;

/**
* Provides access to Agoric-specific account features such as smart wallet
Expand All @@ -48,7 +48,7 @@ export const AgoricProviderLite = ({
onConnectionError = () => {},
chainName = 'agoric',
useCustomEndpoints = true,
}: PropsWithChildren<Props>) => {
}: AgoricProviderLiteProps) => {
const [walletConnection, setWalletConnection] = useState<
AgoricWalletConnection | undefined
>(undefined);
Expand Down
9 changes: 7 additions & 2 deletions packages/react-components/src/lib/hooks/amountInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ type Args = {
};

export const useAmountInput = ({ value, decimalPlaces, onChange }: Args) => {
const amountString = stringifyValue(value, AssetKind.NAT, decimalPlaces);
const amountString =
value === null ? '' : stringifyValue(value, AssetKind.NAT, decimalPlaces);

const [fieldString, setFieldString] = useState(
value === null ? '' : amountString,
Expand All @@ -26,7 +27,11 @@ export const useAmountInput = ({ value, decimalPlaces, onChange }: Args) => {
setFieldString(str);

try {
const parsed = parseAsValue(str, AssetKind.NAT, decimalPlaces);
const parsed = parseAsValue(
str,
AssetKind.NAT,
decimalPlaces,
) as NatValue;
onChange(parsed);
} catch {
console.debug('Invalid input', str);
Expand Down
2 changes: 1 addition & 1 deletion packages/react-components/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ module.exports = {
extend: {},
},
plugins: [],
}
};
4 changes: 4 additions & 0 deletions packages/react-components/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["../../typedoc.base.json"],
"entryPoints": ["src/lib/index.ts"]
}
24 changes: 12 additions & 12 deletions packages/react-components/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import react from '@vitejs/plugin-react'
import path from 'node:path'
import { defineConfig } from 'vitest/config'
import dts from 'vite-plugin-dts'
import tailwindcss from 'tailwindcss'
import { UserConfigExport } from 'vite'
import { name } from './package.json'
import react from '@vitejs/plugin-react';
import path from 'node:path';
import { defineConfig } from 'vitest/config';
import dts from 'vite-plugin-dts';
import tailwindcss from 'tailwindcss';
import { UserConfigExport } from 'vite';
import { name } from './package.json';

const app = async (): Promise<UserConfigExport> => {
/**
* Removes everything before the last
* @octocat/library-repo -> library-repo
* vite-component-library-template -> vite-component-library-template
*/
const formattedName = name.match(/[^/]+$/)?.[0] ?? name
const formattedName = name.match(/[^/]+$/)?.[0] ?? name;

return defineConfig({
plugins: [
Expand All @@ -31,7 +31,7 @@ const app = async (): Promise<UserConfigExport> => {
entry: path.resolve(__dirname, 'src/lib/index.ts'),
name: formattedName,
formats: ['es', 'umd'],
fileName: (format) => `${formattedName}.${format}.js`,
fileName: format => `${formattedName}.${format}.js`,
},
rollupOptions: {
external: ['react', 'react/jsx-runtime', 'react-dom', 'tailwindcss'],
Expand All @@ -49,7 +49,7 @@ const app = async (): Promise<UserConfigExport> => {
globals: true,
environment: 'jsdom',
},
})
}
});
};
// https://vitejs.dev/config/
export default app
export default app;
6 changes: 3 additions & 3 deletions packages/rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ For more complete examples and setup see [Agoric/ui-kit](https://github.com/Agor
```ts
import {
makeAgoricChainStorageWatcher,
AgoricChainStoragePathKind as Kind
AgoricChainStoragePathKind as Kind,
} from '@agoric/rpc';

const watcher = makeAgoricChainStorageWatcher(rpc, chainName);
Expand All @@ -13,8 +13,8 @@ const stopWatching = watcher.watchLatest<string[]>(
[Kind.Children, 'published.vaultFactory.managers'],
managerIds => {
console.log('Got vault manager IDs:', managerIds);
}
)
},
);

// Stop watching.
stopWatching();
Expand Down
2 changes: 1 addition & 1 deletion packages/rpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@vitest/coverage-c8": "^0.25.3",
"axios-mock-adapter": "^1.22.0",
"eslint": "^8.22.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-require-extensions": "^0.1.3",
"happy-dom": "^9.20.3",
"postinstall-postinstall": "^2.1.0",
Expand Down
18 changes: 8 additions & 10 deletions packages/rpc/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"noEmit": false,
"declaration": true,
"declarationMap": true
},
"exclude": [
"test/"
]
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"noEmit": false,
"declaration": true,
"declarationMap": true
},
"exclude": ["test/"]
}
11 changes: 2 additions & 9 deletions packages/rpc/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"useDefineForClassFields": true,
"lib": [
"DOM",
"DOM.Iterable",
"ESNext"
],
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"allowJs": false,
Expand All @@ -16,10 +12,7 @@
"isolatedModules": true,
"baseUrl": "src"
},
"include": [
"src",
"index.ts"
],
"include": ["src", "index.ts"],
"references": [
{
"path": "./tsconfig.node.json"
Expand Down
8 changes: 2 additions & 6 deletions packages/rpc/typedoc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"extends": [
"../../typedoc.base.json"
],
"entryPoints": [
"index.ts",
]
"extends": ["../../typedoc.base.json"],
"entryPoints": ["index.ts"]
}
2 changes: 1 addition & 1 deletion packages/web-components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { makeAgoricWalletConnection } from '@agoric/web-components';

const watcher = makeAgoricChainStorageWatcher(rpc, chainName);
const connection = await makeAgoricWalletConnection(watcher);
const {pursesNotifier, publicSubscribersNotifier} = chainConnection;
const { pursesNotifier, publicSubscribersNotifier } = chainConnection;

// Sign an on-chain offer transaction.
connection.makeOffer(...offer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-check

export { makeAgoricWalletConnection } from './src/wallet-connection/walletConnection.js';
export {
agoricRegistryTypes,
Expand Down
9 changes: 6 additions & 3 deletions packages/web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
"@agoric/cache": "^0.3.2",
"@agoric/casting": "^0.4.3-u13.0",
"@agoric/cosmic-proto": "0.3.0",
"@agoric/ertp": "^0.16.2",
"@agoric/ertp": "^0.16.3-dev-e2e36cc.0",
"@agoric/notifier": "^0.6.3-dev-8c14632.0",
"@agoric/smart-wallet": "^0.5.3",
"@endo/captp": "^3.1.1",
"@endo/eventual-send": "^0.17.5",
"@endo/marshal": "^0.8.5"
},
"devDependencies": {
"eslint-config-airbnb-base": "15.0.0",
"@agoric/eslint-config": "0.4.1-u12.0",
"@agoric/rpc": "^0.9.0",
"@keplr-wallet/types": "^0.11.37",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "15.0.0",
"ses": "0.18.7",
"vitest": "^0.34.1"
},
Expand All @@ -47,8 +47,11 @@
"jsdoc/require-property-description": "off",
"jsdoc/require-returns": "off",
"jsdoc/check-tag-names": "off",
"jsdoc/require-param-type": "off",
"jsdoc/tag-lines": "off",
"import/no-extraneous-dependencies": "off"
"import/no-unresolved": "off",
"import/no-extraneous-dependencies": "off",
"import/order": "off"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
Expand Down
Loading
Loading