Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
claireolmstead committed Feb 6, 2024
1 parent 88e5978 commit ef0c664
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 50 deletions.
17 changes: 0 additions & 17 deletions src/components/BecomeAProvider.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
<script lang="ts">
import { dotApi } from '$lib/stores';
import { onMount } from 'svelte';
import type { web3Enable, web3FromSource } from '@polkadot/extension-dapp';
import { defaultDotApi } from '$lib/storeTypes';
import type { DotApi } from '$lib/storeTypes';
import { user } from '$lib/stores/userStore';
import { nonProviderAccountsStore } from '$lib/stores/accountsStore';
import BlockSection from './BlockSection.svelte';
Expand All @@ -13,22 +8,10 @@
import EmailProviderRequest from './EmailProviderRequest.svelte';
import { pageContent } from '$lib/stores/pageContentStore';
let localDotApi: DotApi = defaultDotApi;
let thisWeb3FromSource: typeof web3FromSource;
let thisWeb3Enable: typeof web3Enable;
// a callback for when the user cancels this action
export let cancelAction = () => {
pageContent.login();
};
onMount(async () => {
const extension = await import('@polkadot/extension-dapp');
thisWeb3FromSource = extension.web3FromSource;
thisWeb3Enable = extension.web3Enable;
});
dotApi.subscribe((api) => (localDotApi = api));
</script>

<div id="become-a-provider" class="content-block column w-single-block">
Expand Down
1 change: 0 additions & 1 deletion src/components/CreateProvider.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import { user } from '$lib/stores/userStore';
import { getMsaInfo } from '$lib/polkadotApi';
import type { MsaInfo } from '$lib/storeTypes';
import { nonProviderAccountsStore, providerAccountsStore } from '$lib/stores/accountsStore';
import { pageContent } from '$lib/stores/pageContentStore';
let newProviderName = '';
Expand Down
1 change: 0 additions & 1 deletion src/components/Nav.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script lang="ts">
import { navigating } from '$app/stores';
import { onMount } from 'svelte';
import iconLogo from '$lib/assets/icon-logo.png';
Expand Down
9 changes: 5 additions & 4 deletions src/components/SelectNetworkAndAccount.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@
try {
networkErrorMsg = '';
controlKeysErrorMsg = '';
const curApi = await createApi(network.endpoint!?.toString());
if (!network.endpoint) throw new Error("Undefined endpoint.");
const curApi = await createApi(network.endpoint?.origin);
await fetchAccountsForNetwork(network, thisWeb3Enable, thisWeb3Accounts, curApi.api as ApiPromise);
await curApi.api?.disconnect();
} catch (e) {
console.log(e);
networkErrorMsg = `Could not connect to ${
network.endpoint?.toString() || 'empty value'
network.endpoint?.origin || 'empty value'
}. Please enter a valid and reachable Websocket URL.`;
console.error(networkErrorMsg);
}
Expand Down Expand Up @@ -111,7 +112,7 @@
on:keydown={customNetworkChanged}
/>
{/if}
<div id="network-error-msg" class="text-sm text-error">{networkErrorMsg}</div>
<div id="network-error-msg" class="text-error text-sm">{networkErrorMsg}</div>
<DropDownMenu
id="controlkeys"
label={accountSelectorTitle}
Expand All @@ -122,5 +123,5 @@
formatter={formatAccount}
disabled={accountsStore.size == 0}
/>
<div id="controlkey-error-msg" class="text-sm text-error">{controlKeysErrorMsg}</div>
<div id="controlkey-error-msg" class="text-error text-sm">{controlKeysErrorMsg}</div>
</div>
14 changes: 7 additions & 7 deletions src/lib/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ export async function submitAddControlKey(
);
useKeyring
? await submitExtrinsicWithKeyring(
extrinsic,
extrinsic,
signingAccount as KeyringPair,
txnStatusCallback,
txnFinishedCallback
)
)
: await submitExtrinsicWithExtension(
extension as InjectedExtension,
extrinsic,
signingAccount.address,
txnStatusCallback,
txnFinishedCallback
);
);
} else {
console.debug('api is not available.');
}
Expand Down Expand Up @@ -114,7 +114,7 @@ export async function submitStake(
signingAccount.address,
callback,
txnFinishedCallback
);
);
} else {
console.debug('api is not available.');
}
Expand Down Expand Up @@ -274,7 +274,7 @@ export async function submitCreateProvider(
signingAccount.address,
txnStatusCallback,
txnFinishedCallback
);
);
return true;
}
return false;
Expand All @@ -301,7 +301,7 @@ export async function submitRequestToBeProvider(
signingAccount.address,
txnStatusCallback,
txnFinishedCallback
);
);
return true;
}
console.error('submit failed because api is', api);
Expand Down Expand Up @@ -329,7 +329,7 @@ export async function submitCreateMsa(
signingAccount.address,
txnStatusCallback,
txnFinishedCallback
);
);
return true;
}
return false;
Expand Down
9 changes: 2 additions & 7 deletions src/lib/polkadotApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,14 @@ async function updateChainInfo(api: ApiPromise) {
}

export async function createAndConnectToApi(networkEndpoint: string) {
let initializedDotApi = await createApi(networkEndpoint);
console.log('*** createAndConnectToApi ****', initializedDotApi.selectedEndpoint);
console.log('*** here 3 selectedEndpoint****', initializedDotApi);

const initializedDotApi = await createApi(networkEndpoint);
dotApi.set(initializedDotApi);

await updateChainInfo(initializedDotApi.api);
}

export async function createApi(networkEndpoint: string): Promise<DotApi> {
const wsProvider = new WsProvider(networkEndpoint);
console.log('*** wsProvider networkEndpoint ****', wsProvider.endpoint);


const apiPromise = await ApiPromise.create({
provider: wsProvider,
throwOnConnect: true,
Expand Down
12 changes: 1 addition & 11 deletions test/e2e/page.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/svelte';
import { cleanup, fireEvent, render, waitFor } from '@testing-library/svelte';
import '@testing-library/jest-dom';
import Page from '$routes/+page.svelte';

// global.alert = () => {};
// vitest mocking
globalThis.alert = () => {};

const getByTextContent = (text) => {
// Passing function to `getByText`
return screen.getByText((content, element) => {
const hasText = (element) => element.textContent === text;
const elementHasText = hasText(element);
const childrenDontHaveText = Array.from(element?.children || []).every((child) => !hasText(child));
return elementHasText && childrenDontHaveText;
});
};

describe('End to End Tests', () => {
// TODO: @testing-library/svelte claims to add this automatically but it doesn't work without explicit afterEach
afterEach(() => cleanup());
Expand Down
1 change: 0 additions & 1 deletion test/unit-and-integration/capacity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { cleanup, render, waitFor } from '@testing-library/svelte';
import '@testing-library/jest-dom';
import { storeChainInfo, dotApi } from '../../src/lib/stores';
import Capacity from '$components/Capacity.svelte';
import { getByTextContent } from '../helpers';
import { user } from '../../src/lib/stores/userStore';
import { ChainInfo } from '../../src/lib/storeTypes';

Expand Down
2 changes: 1 addition & 1 deletion test/unit-and-integration/provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cleanup, render, waitFor } from '@testing-library/svelte';
import { cleanup, render } from '@testing-library/svelte';
import '@testing-library/jest-dom';
import { dotApi, storeCurrentAction, storeChainInfo } from '../../src/lib/stores';
import { user } from '../../src/lib/stores/userStore';
Expand Down

0 comments on commit ef0c664

Please sign in to comment.