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

feat: substrate support to SDK #154

Merged
merged 42 commits into from
Mar 1, 2023
Merged

feat: substrate support to SDK #154

merged 42 commits into from
Mar 1, 2023

Conversation

enemycnt
Copy link
Contributor

@enemycnt enemycnt commented Jan 27, 2023

Description

Related Issue Or Context

Closes: #93
Closes: #92
Closes: #144
Closes: #89

How Has This Been Tested? Testing details.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation

Checklist:

  • I have commented my code, particularly in hard-to-understand areas.
  • I have ensured that all acceptance criteria (or expected behavior) from issue are met
  • I have updated the documentation locally and in chainbridge-docs.
  • I have added tests to cover my changes.
  • I have ensured that all the checks are passing and green, I've signed the CLA bot

@enemycnt enemycnt requested a review from wainola January 27, 2023 17:26
@enemycnt enemycnt changed the title Add make runtime call to substrate feat: Add make runtime call to substrate Jan 27, 2023
examples/substrate-react-example/package.json Show resolved Hide resolved
examples/substrate-react-example/src/UserInfo.tsx Outdated Show resolved Hide resolved
examples/substrate-react-example/vite.config.ts Outdated Show resolved Hide resolved
packages/sdk/package.json Show resolved Hide resolved
packages/sdk/src/chains/Substrate/utils.ts Outdated Show resolved Hide resolved
packages/sdk/src/chains/Substrate/utils.ts Outdated Show resolved Hide resolved
packages/sdk/src/chains/Substrate/utils.ts Outdated Show resolved Hide resolved
wainola
wainola previously requested changes Feb 1, 2023
examples/substrate-react-example/index.html Show resolved Hide resolved
examples/substrate-react-example/index.html Outdated Show resolved Hide resolved
examples/substrate-react-example/package.json Show resolved Hide resolved
examples/substrate-react-example/src/App.tsx Outdated Show resolved Hide resolved
examples/substrate-react-example/src/App.tsx Outdated Show resolved Hide resolved
examples/substrate-react-example/src/App.tsx Outdated Show resolved Hide resolved
packages/sdk/src/chains/Substrate/utils.ts Outdated Show resolved Hide resolved
packages/sdk/src/chains/Substrate/utils.ts Outdated Show resolved Hide resolved
packages/sdk/src/chains/Substrate/utils.ts Outdated Show resolved Hide resolved
packages/sdk/src/chains/Substrate/utils.ts Outdated Show resolved Hide resolved
packages/sdk/src/chains/Substrate/utils.ts Outdated Show resolved Hide resolved
@enemycnt enemycnt changed the title feat: Add make runtime call to substrate feat: Add make runtime call to substrate / extrinsic tx Feb 7, 2023
Copy link

@Tbaut Tbaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look particularly at the sdk, went through the tests as well, and skipped the example.

Just left one small comment, there's nothing that really stood out to my eyes, it's pretty clean well done!

packages/sdk/src/chains/Substrate/utils.ts Outdated Show resolved Hide resolved
return Loader(
"Loading accounts (please review any extension's authorization)"
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code block with error handling could be improved by using constants for the status. It could also be separated into another method for error handling.

What is the possible error state when using "!== READY"? Can we compare the exact values as it gives the feeling of some potential unknown keyring value?

from: string;
to: string;
}): Promise<void> => {
console.log('form data', values);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console.log

console.log('form data', values);
if (values.amount && values.address) {
setIsLoading(true)
makeDeposit(values.amount, values.address, values.to).finally(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No error handling


return (
<form
action=""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty action could be removed

return (
<form
action=""
onSubmit={(...args) => void handleSubmit(submit)(...args)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a destructuring assignment for the object?

Comment on lines +21 to +22
key: account.address,
value: account.address,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use object destructuring

text: (account.meta.name as String).toUpperCase(),
icon: "user",
}));
const initialAddress =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to the method getInitialAddress

: "";
// Set the initial address
useEffect(() => {
!currentAccount &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor to readable expressions, like:

function accountExists() return !currentAccount && initialAddress.length > 0

if(accountExists()) {
  setCurrentAccount(keyring?.getPair(initialAddress))
}


Comment on lines +101 to +103
) : (
"No accounts found"
)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the early return of component if an account is not set:

if (!currentAccount) {
return "No accounts found"
}

return (


<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
}}
>

Account data


)

export default function Metadata(props: any) {
const state = useSubstrateState();
const api = state?.api;
return api?.rpc && api.rpc.state ? <Main {...props} /> : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are relying on the state we can use:
api?.rpc?.state
Or you can use lodash
get(api, 'rpc.state', null)


export type SubstrateContextType = {
state: StateType;
setCurrentAccount: (acct: unknown) => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the parameter be account?


useEffect(() => {
const { apiState, keyringState, api } = state;
if (apiState === "READY" && api && !keyringState && !keyringLoadAll) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constants for status like "READY"

useEffect(() => {
const { apiState, keyringState, api } = state;
if (apiState === "READY" && api && !keyringState && !keyringLoadAll) {
console.log("load");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove console.log

);
};

const useSubstrate = () => useContext(SubstrateContext);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make a guard if the context is not used with provider:

function useSubstrate() {
  const context = useContext(SubstrateContext)
  if (context === undefined) {
    throw new Error('useSubstrate must be used within a SubstrateContext')
  }
  return context
}

systemChain: string;
systemChainType: ChainType;
}> => {
const [systemChain, systemChainType] = await Promise.all([
Copy link
Contributor

@Lykhoyda Lykhoyda Feb 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify the code:

const chainPromise = api?.rpc?.system?.chainType ? api.rpc.system.chainType() : Promise.resolve(LiveChainType)
const [systemChain, systemChainType] = await Promise.all([
   api.rpc.system.chain()
   chainPromise()
])

Copy link
Contributor

@Lykhoyda Lykhoyda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving the PR with the request to add/fix the suggested improvements listed in a new issue:
#181

@P1sar P1sar requested review from wainola and Tbaut February 28, 2023 17:40
@enemycnt enemycnt dismissed stale reviews from wainola and BeroBurny March 1, 2023 09:27

In favor #181

@enemycnt enemycnt merged commit 856c231 into main Mar 1, 2023
@enemycnt enemycnt deleted the feat/substrate-basic-info branch March 1, 2023 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants