Skip to content

Commit

Permalink
chore(transfer): linting
Browse files Browse the repository at this point in the history
  • Loading branch information
jessevanmuijden committed Jul 20, 2023
1 parent bffeff4 commit 5c39a8d
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 84 deletions.
2 changes: 1 addition & 1 deletion common/config/rush/repo-state.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush.
{
"pnpmShrinkwrapHash": "a31e420779e3b795c18ccdb0f014563cb09ac915",
"pnpmShrinkwrapHash": "a6b2414ab97b9cd239b6df977803e8dfdf765fdd",
"preferredVersionsHash": "bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f"
}
9 changes: 4 additions & 5 deletions packages/apps/docs/src/scripts/detectBrokenLinks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ function getBrokenLinks(filePath, links) {
// places where the link could live
const fileMDX = `${links[index]}.mdx`;
const fileTSX = `${links[index]}.tsx`;
const fileIndex =
links[index]
.split('/')
.slice(0, links[index].split('/').length - 1)
.join('/') + '/index';
const fileIndex = `${links[index]
.split('/')
.slice(0, links[index].split('/').length - 1)
.join('/')}/index`;
const fileIndexMDX = `${fileIndex}.mdx`;
const fileIndexTSX = `${fileIndex}.tsx`;

Expand Down
28 changes: 17 additions & 11 deletions packages/apps/transfer/src/pages/faucet/existing/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ export type RequestStatus = 'not started' | 'pending' | 'succeeded' | 'failed';
interface FundExistingAccountResponseBody {
result: {
status: string;
error: undefined | {
message: string;
};
error:
| undefined
| {
message: string;
};
};
}

interface FundExistingAccountResponse extends Record<string, FundExistingAccountResponseBody> {}
interface FundExistingAccountResponse
extends Record<string, FundExistingAccountResponseBody> {}

const ExistingAccountFaucetPage: FC = () => {
const { t } = useTranslation('common');
Expand All @@ -59,24 +62,27 @@ const ExistingAccountFaucetPage: FC = () => {
setRequestStatus({ status: 'pending' });

try {
const result = await fundExistingAccount(
const result = (await fundExistingAccount(
accountName,
chainID,
AMOUNT_OF_COINS_FUNDED,
) as FundExistingAccountResponse;
)) as FundExistingAccountResponse;

const error = Object.values(result).find(response => response.result.status === 'failure');
const error = Object.values(result).find(
(response) => response.result.status === 'failure',
);

if (error) {
setRequestStatus({ status: 'failed', message: error.result.error?.message || t('An error occurred.')});
setRequestStatus({
status: 'failed',
message: error.result.error?.message || t('An error occurred.'),
});
return;
}

setRequestStatus({ status: 'succeeded' });
} catch (err) {
let message = err instanceof Error
? err.message
: String(err);
const message = err instanceof Error ? err.message : String(err);

setRequestStatus({ status: 'failed', message });
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Breadcrumbs, TextField } from '@kadena/react-ui';

import {
StyledAccountForm,
StyledForm,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Pact, signWithChainweaver, getClient, isSignedCommand } from '@kadena/client';
import {
getClient,
isSignedCommand,
Pact,
signWithChainweaver,
} from '@kadena/client';
import { Button } from '@kadena/react-components';

import { Container, EditorGrid } from './styles';
Expand Down Expand Up @@ -40,7 +45,13 @@ const FunctionPage = () => {
setOutput('');
const scopedEval = new ScopedEval();
console.log(code);
scopedEval.eval(code, { Pact, getClient, signWithChainweaver, isSignedCommand, Logger });
scopedEval.eval(code, {
Pact,
getClient,
signWithChainweaver,
isSignedCommand,
Logger,
});
};

useEffect(() => {
Expand Down Expand Up @@ -95,7 +106,12 @@ const FunctionPage = () => {
</Button>
)}
</>
<AceViewer code={code} width={'100%'} readonly={false} onChange={(value: string) => setCode(value)} />
<AceViewer
code={code}
width={'100%'}
readonly={false}
onChange={(value: string) => setCode(value)}
/>
</div>
<div>
<h3>{t('Output')}</h3>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
ChainwebChainId,
ICommandResult,
} from '@kadena/chainweb-node-client';
import { ChainwebChainId, ICommandResult } from '@kadena/chainweb-node-client';
import { getClient } from '@kadena/client';
import { IPactEvent, IPactExec, PactValue } from '@kadena/types';

Expand Down Expand Up @@ -73,7 +70,7 @@ export async function getTransferData({
});
const chainInfos = await Promise.all(chainInfoPromises);

const request = chainInfos.find(chainInfo => requestKey in chainInfo);
const request = chainInfos.find((chainInfo) => requestKey in chainInfo);

if (!request) {
return { error: t('No request key found') };
Expand All @@ -93,13 +90,12 @@ export async function getTransferData({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
found?.continuation?.continuation.args as Array<any>;

const { step, stepHasRollback, pactId } = found
?.continuation as IPactExec;
const { step, stepHasRollback, pactId } = found?.continuation as IPactExec;

return {
tx: {
sender: {
chain: "1", // todo: fix typing. // found.chainId.toString() as ChainwebChainId,
chain: '1', // todo: fix typing. // found.chainId.toString() as ChainwebChainId,
account: senderAccount,
},
receiver: {
Expand Down
10 changes: 5 additions & 5 deletions packages/apps/transfer/src/services/faucet/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { ChainwebChainId, ChainwebNetworkId } from '@kadena/chainweb-node-client';
import {
ChainwebChainId,
ChainwebNetworkId,
} from '@kadena/chainweb-node-client';
import { getClient, isSignedCommand, Pact } from '@kadena/client';
import { genKeyPair, sign } from '@kadena/cryptography-utils';
import { PactNumber } from '@kadena/pactjs';
Expand Down Expand Up @@ -69,10 +72,7 @@ export const fundExistingAccount = async (
chainId,
});

transaction.sigs = [
{ sig: signature1.sig },
{ sig: signature2.sig },
];
transaction.sigs = [{ sig: signature1.sig }, { sig: signature2.sig }];

const { submit, pollStatus } = getClient(apiHost);

Expand Down
12 changes: 7 additions & 5 deletions packages/apps/transfer/src/services/modules/describe-module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChainwebChainId } from '@kadena/chainweb-node-client';
import { Pact, getClient } from '@kadena/client';
import { getClient, Pact } from '@kadena/client';
import { createExp } from '@kadena/pactjs';

import {
Expand Down Expand Up @@ -29,10 +29,12 @@ export const describeModule = async (
): Promise<IModuleResult> => {
debug(describeModule.name);
const networkId = chainNetwork[network].network;
const { local } = getClient(getKadenaConstantByNetwork(network).apiHost({
networkId,
chainId,
}));
const { local } = getClient(
getKadenaConstantByNetwork(network).apiHost({
networkId,
chainId,
}),
);

const transaction = Pact.builder
.execution(Pact.modules['describe-module'](moduleName))
Expand Down
12 changes: 7 additions & 5 deletions packages/apps/transfer/src/services/modules/list-module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChainwebChainId } from '@kadena/chainweb-node-client';
import { Pact, getClient } from '@kadena/client';
import { getClient, Pact } from '@kadena/client';
import { createExp } from '@kadena/pactjs';

import {
Expand Down Expand Up @@ -27,10 +27,12 @@ export const listModules = async (
): Promise<IModulesResult> => {
debug(listModules.name);
const networkId = chainNetwork[network].network;
const { local } = getClient(getKadenaConstantByNetwork(network).apiHost({
networkId,
chainId,
}));
const { local } = getClient(
getKadenaConstantByNetwork(network).apiHost({
networkId,
chainId,
}),
);

const transaction = Pact.builder
.execution(Pact.modules['list-modules']())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ChainwebNetworkId,
} from '@kadena/chainweb-node-client';
import { getContCommand, pollSpvProof } from '@kadena/client';

import { getTransferData } from '../cross-chain-transfer-finish/get-transfer-data';

import {
Expand Down
2 changes: 1 addition & 1 deletion packages/libs/react-ui/src/components/Footer/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FooterContainer, IFooterProps, FooterVariant } from './Footer';
import { FooterContainer, FooterVariant, IFooterProps } from './Footer';
import { FooterIconItem, IFooterIconItemProps } from './FooterIconItem';
import { FooterLinkItem, IFooterLinkItemProps } from './FooterLinkItem';
import { FooterPanel, IFooterPanelProps } from './FooterPanel';
Expand Down
24 changes: 10 additions & 14 deletions packages/tools/cookbook/src/accounts/create-account.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Pact, signWithChainweaver, getClient, isSignedCommand } from '@kadena/client';
import {
getClient,
isSignedCommand,
Pact,
signWithChainweaver,
} from '@kadena/client';

import { accountKey } from '../utils/account-key';
import { apiHost } from '../utils/api-host';

const HELP: string = `Usage example: \n\nts-node create-account.js k:{gasProviderPublicKey} k:{receiverPublicKey}`;
const NETWORK_ID: 'testnet04' | 'mainnet01' | 'development' =
'testnet04';
const NETWORK_ID: 'testnet04' | 'mainnet01' | 'development' = 'testnet04';
const API_HOST: string = apiHost('1', 'testnet.', NETWORK_ID);

if (process.argv.length !== 4) {
Expand All @@ -30,18 +34,13 @@ async function createAccount(

const transaction = Pact.builder
.execution(
Pact.modules.coin['create-account'](
receiver,
() => '(read-keyset "ks")',
)
Pact.modules.coin['create-account'](receiver, () => '(read-keyset "ks")'),
)
.addData('ks', {
keys: [accountKey(receiver)],
pred: 'keys-all',
})
.addSigner(gasProviderPublicKey, (withCap: any) => [
withCap('coin.GAS'),
])
.addSigner(gasProviderPublicKey, (withCap: any) => [withCap('coin.GAS')])
.setMeta({ chainId: '1', sender: gasProvider })
.setNetworkId(NETWORK_ID)
.createTransaction();
Expand All @@ -53,10 +52,7 @@ async function createAccount(
return;
}

const {
submit,
pollStatus,
} = getClient(API_HOST);
const { submit, pollStatus } = getClient(API_HOST);

const requestKey = await submit(signedTransaction);
console.log('request key', requestKey);
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/cookbook/src/accounts/details.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Pact, getClient } from '@kadena/client';
import { getClient, Pact } from '@kadena/client';

import { apiHost } from '../utils/api-host';

Expand Down
2 changes: 1 addition & 1 deletion packages/tools/cookbook/src/accounts/get-balance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Pact, getClient } from '@kadena/client';
import { getClient, Pact } from '@kadena/client';

import { apiHost } from '../utils/api-host';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Pact, signWithChainweaver, getClient, isSignedCommand } from '@kadena/client';
import {
getClient,
isSignedCommand,
Pact,
signWithChainweaver,
} from '@kadena/client';
import { IPactDecimal } from '@kadena/types';

import { accountKey } from '../utils/account-key';
import { apiHost } from '../utils/api-host';

const HELP: string = `Usage example: \n\nts-node transfer-create-with-chainweaver.ts k:{senderPublicKey} k:{receiverPublicKey} {amount}`;
const NETWORK_ID: 'testnet04' | 'mainnet01' | 'development' =
'testnet04';
const NETWORK_ID: 'testnet04' | 'mainnet01' | 'development' = 'testnet04';
const API_HOST: string = apiHost('1', 'testnet.', NETWORK_ID);

if (process.argv.length !== 5) {
Expand All @@ -32,27 +36,24 @@ async function transferCreate(
const senderPublicKey = accountKey(sender);
const pactDecimal: IPactDecimal = { decimal: `${amount}` };

const {
submit,
pollStatus,
} = getClient(API_HOST);
const { submit, pollStatus } = getClient(API_HOST);

const transaction = Pact.builder
.execution(
Pact.modules.coin['transfer-create'](
sender,
receiver,
() => '(read-keyset "ks")',
pactDecimal
)
Pact.modules.coin['transfer-create'](
sender,
receiver,
() => '(read-keyset "ks")',
pactDecimal,
),
)
.addData('ks', {
keys: [accountKey(receiver)],
pred: 'keys-all',
})
.addSigner(senderPublicKey, (withCap: any) => [
withCap('coin.TRANSFER', sender, receiver, pactDecimal),
withCap('coin.GAS'),
withCap('coin.TRANSFER', sender, receiver, pactDecimal),
withCap('coin.GAS'),
])
.setMeta({ chainId: '1', sender: sender })
.setNetworkId(NETWORK_ID)
Expand Down
Loading

0 comments on commit 5c39a8d

Please sign in to comment.