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: Tezos Provider #1

Merged
merged 6 commits into from
Dec 17, 2024
Merged

feat: Tezos Provider #1

merged 6 commits into from
Dec 17, 2024

Conversation

dianasavvatina
Copy link
Collaborator

@dianasavvatina dianasavvatina commented Oct 18, 2024

Adding Tezos Provider for WalletConnect SDK.
See README for usage examples.

Usage example: reown-com/web-examples#697

Testing:

yarn prettier
yarn lint
yarn test
yarn build

Moved tezosProvider from WalletConnect Monorepo, PR#5357

.prettierrc Outdated
@@ -0,0 +1,6 @@
{
"tabWidth": 2,
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's more of an editorconfig thing

.prettierrc Outdated
@@ -0,0 +1,6 @@
{
"tabWidth": 2,
"useTabs": false,
Copy link
Collaborator

Choose a reason for hiding this comment

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

and this

.prettierrc Outdated
"tabWidth": 2,
"useTabs": false,
"trailingComma": "all",
"printWidth": 100
Copy link
Collaborator

Choose a reason for hiding this comment

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

and this

},
files: ["**/*.ts"],
rules: {
"@typescript-eslint/ban-ts-ignore": ["off"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

are you confident of turning all of those off?

package.json Outdated
],
"scripts": {
"clean": "rm -rf dist",
"build": "tsup-node --dts",
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can puts the dts setting into the tsup config itself down below

return await this.tezosSend(op);
};

public tezosSendProposal = async (op: TezosProposalOperation): Promise<TezosSendResponse> => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure if all those methods need the tezos prefix. it's obvious from the class name that it's tezos related

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The operations contain the names of WalletConnect requests: tezos_send, tezos_sign, tezos_getaccounts.
I try to find a way to distinguish requests to peer (on top of these 3) and auxilary requests, like getBalance(), connect(), getContractAddress().
If you think, that it's not needed, I'll rename:

tezosSend -> send
tezosSign -> sign
tezosGetAccounts -> getAccounts

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah, I don't think it adds much value

return await this.tezosSend(op);
};

public tezosSendIncreasePaidStorage = async (
Copy link
Collaborator

Choose a reason for hiding this comment

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

there is no need to await unless you want to catch errors or something. so it should be

public async sendIncreasePaidStorage(op: PartialTezosIncreasePaidStorageOperation) {
  return this.tezosSend(op);
}

package.json Outdated
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@swc/core": "^1.7.35",
Copy link
Collaborator

Choose a reason for hiding this comment

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

so do you use swc or tsup in the end?

tsconfig.json Outdated
"ignoreDeprecations": "5.0"

},
"include": ["./src/**/*.ts", "./src"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

"include": ["src"]

tsconfig.json Outdated
"include": ["./src/**/*.ts", "./src"],
"exclude": [
"node_modules",
"test",
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't exclude test

@dianasavvatina dianasavvatina force-pushed the diana@tezos-provider branch 3 times, most recently from f94006b to 630dc2f Compare November 14, 2024 16:33
tsconfig.json Outdated

},
"include": ["src"],
"exclude": [
Copy link
Collaborator

Choose a reason for hiding this comment

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

not needed

"lib": ["ES2020", "DOM"],
"module": "ES2020",
"target": "ES2020",
"moduleResolution": "Node",
Copy link
Collaborator

Choose a reason for hiding this comment

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

why node if that's a front-end app? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I used WalletConnect monorepo as a reference. There is a number of providers and all of them used main config:
https://github.com/WalletConnect/walletconnect-monorepo/blob/v2.0/tsconfig.json#L18

    "lib": ["ES2020", "DOM"],
    "module": "ES2020",
    "target": "ES2020",
    "moduleResolution": "Node",

I try to keep my code aligned.

tsconfig.json Show resolved Hide resolved
package.json Outdated
"package.json": "^2.0.1",
"rollup": "^4.24.0",
"typescript": "^5.6.3",
"yarn.lock": "^0.0.1-security"
Copy link
Collaborator

Choose a reason for hiding this comment

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

?

package.json Outdated
"type": "module",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
"unpkg": "dist/index.umd.js",
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you have it?

package.json Outdated
"test:pre": "rm -rf ./test/test.db",
"test:run": "jest",
"test": "yarn test:pre; yarn test:run",
"prettier": "prettier --check '{src,test}/**/*.{js,ts,jsx,tsx}' --write",
Copy link
Collaborator

Choose a reason for hiding this comment

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

just prettier --write .

package.json Outdated
"test:run": "jest",
"test": "yarn test:pre; yarn test:run",
"prettier": "prettier --check '{src,test}/**/*.{js,ts,jsx,tsx}' --write",
"lint": "eslint -c 'eslint.config.mjs' --fix './src/**/*.ts'",
Copy link
Collaborator

Choose a reason for hiding this comment

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

IIRC eslint 9 (which config you are using) has the list of files already.
no need to use quotes

package.json Outdated
},
"dependencies": {
"@airgap/beacon-types": "^4.2.2",
"@taquito/rpc": "~20.0.1",
Copy link
Collaborator

Choose a reason for hiding this comment

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

outdated, use yarn upgrade-interactive to fix such things

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed deps. Checked that lib is built in WalletConnect example for tezos provider

package.json Outdated
"@walletconnect/logger": "^2.1.2",
"@walletconnect/types": "2.13.3",
"@walletconnect/universal-provider": "^2.17.1",
"axios": "^1.7.7",
Copy link
Collaborator

Choose a reason for hiding this comment

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

you use it in only 1 place. consider replacing with a built-in fetch. less dependencies -> smaller output

],
"scripts": {
"clean": "rm -rf dist",
"build": "tsup-node",
Copy link
Collaborator

Choose a reason for hiding this comment

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

since it's a library, most likely you need to either us tsup or tsup-node + peerDependencies in the package.json

package.json Outdated
"@walletconnect/logger": "^2.1.2",
"@walletconnect/types": "^2.17.2",
"@walletconnect/universal-provider": "^2.17.2",
"i": "^0.3.7",
Copy link
Collaborator

Choose a reason for hiding this comment

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

??

@@ -0,0 +1,3 @@
global.fetch = jest.fn();

jest.clearAllMocks();
Copy link
Collaborator

Choose a reason for hiding this comment

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

put this into jest.config

} as TezosProviderOpts);
await provider.connect({ chains: [TezosChainDataMainnet] });

// mockRequest = jest.fn();
Copy link
Collaborator

@serjonya-trili serjonya-trili Nov 22, 2024

Choose a reason for hiding this comment

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

not needed

const mockRequest = jest.fn();

beforeEach(async () => {
(UniversalProvider.init as jest.Mock).mockResolvedValue({
Copy link
Collaborator

@serjonya-trili serjonya-trili Nov 22, 2024

Choose a reason for hiding this comment

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

jest.mocked(...) is a type safe version. please prefer it (and in other places too)

@dianasavvatina dianasavvatina removed the request for review from ajinkyaraj-23 December 9, 2024 11:28
Copy link
Collaborator

@OKendigelyan OKendigelyan left a comment

Choose a reason for hiding this comment

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

LGTM!

@dianasavvatina dianasavvatina merged commit d61cf63 into main Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants