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: wallet api example #392

Merged
merged 31 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
57f770e
feat: initial wallet api example codebase
agent-dominatrix Jul 20, 2024
c55f363
chore: update lint rules
agent-dominatrix Jul 20, 2024
a3df20b
Mobile: UI enhancement and Fixes (#374)
sh-wallet Jul 19, 2024
f7cbfc6
fix: Extension bugs and improvements 1207 (#375)
AbbasAliLokhandwala Jul 20, 2024
2d9728e
chore: update releases script for manifest v3
agent-dominatrix Jul 20, 2024
9028b35
chore: bump manifest version
agent-dominatrix Jul 20, 2024
b50fcc6
fix: ledger fixes (#377)
sh-wallet Jul 24, 2024
8d944b9
Fixes 2207 (#376)
AbbasAliLokhandwala Jul 24, 2024
2a4037a
chore: update firefox package script
agent-dominatrix Jul 24, 2024
696c307
chore: bump manifest version
agent-dominatrix Jul 24, 2024
4962250
Mobile improvements (#383)
sh-wallet Aug 12, 2024
2ff3700
Custom nonce update (#386)
AbbasAliLokhandwala Aug 14, 2024
3bf2f78
Firefox UI fixes (#379)
AbbasAliLokhandwala Aug 19, 2024
bcc45d8
Mobile: custom nonce support (#387)
sh-wallet Aug 19, 2024
0519103
Extension: Gov proposal rebranding (#378)
AbbasAliLokhandwala Aug 20, 2024
4c2716a
Extension: ASI Branding (#380)
AbbasAliLokhandwala Aug 20, 2024
cd33002
Mobile: Added Autolock Support (#384)
sh-wallet Aug 21, 2024
b5970ed
Mobile: ASI Branding (#382)
sh-wallet Aug 21, 2024
1b0cf64
Mobile: iOS random crash fixes (#388)
sh-wallet Aug 21, 2024
5c67ddf
Mobile: App update feature (#385)
sh-wallet Aug 21, 2024
89596be
Mobile: Gov proposal feature (#381)
sh-wallet Aug 21, 2024
b5f0218
chore: add proto gen
agent-dominatrix Jul 22, 2024
d2e9489
wip: wallet api compatibility
agent-dominatrix Jul 24, 2024
16fd088
feat: improve wallet api example functionality
agent-dominatrix Aug 27, 2024
1814490
fix: minor improvements
agent-dominatrix Aug 27, 2024
a7aab9d
chore: remove keplr logo
agent-dominatrix Aug 27, 2024
1ebb4c4
chore: remove .yarn
agent-dominatrix Aug 27, 2024
f4be3de
Merge branch 'master' into feat/wallet-api-example
agent-dominatrix Aug 27, 2024
22ef4f1
chore: remove unnecessary log
agent-dominatrix Aug 28, 2024
f81c3e3
fix: remove keplr references
agent-dominatrix Aug 28, 2024
29e1de0
Merge branch 'main' into feat/wallet-api-example
agent-dominatrix Aug 28, 2024
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
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ packages/proto-types/!(proto-types-gen)/**/*.mjs
packages/proto-types/!(proto-types-gen)/**/*.cjs
packages/proto-types/!(proto-types-gen)/**/*.map
packages/proto-types/outputHash

wallet-api-example/*
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ packages/proto-types/outputHash

package.json
tsconfig.json

wallet-api-example/*
5 changes: 5 additions & 0 deletions packages/background/src/chains/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,11 @@ export class ChainsService {
origin,
}
)) as string;
await this.permissionService.addPermission(
[chainId],
getBasicAccessPermissionType(),
[origin]
);
console.log(`Switched to chain with chainId ${receivedChainId}`);
}

Expand Down
16 changes: 8 additions & 8 deletions packages/background/src/keyring/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ const handleCurrentAccountMsg: (
) => InternalHandler<CurrentAccountMsg> = (service) => {
return async (env, msg) => {
const chainId = await service.chainsService.getSelectedChain();
await service.permissionService.checkBasicAccessPermission(
await service.permissionService.checkOrGrantBasicAccessPermission(
env,
[chainId],
msg.origin
Expand Down Expand Up @@ -681,7 +681,7 @@ const handleSwitchAccountMsg: (
) => InternalHandler<SwitchAccountMsg> = (service) => {
return async (env, msg) => {
const chainId = await service.chainsService.getSelectedChain();
await service.permissionService.checkBasicAccessPermission(
await service.permissionService.checkOrGrantBasicAccessPermission(
env,
[chainId],
msg.origin
Expand All @@ -696,7 +696,7 @@ const handleListAccountsMsg: (
) => InternalHandler<ListAccountsMsg> = (service) => {
return async (env, msg) => {
const chainId = await service.chainsService.getSelectedChain();
await service.permissionService.checkBasicAccessPermission(
await service.permissionService.checkOrGrantBasicAccessPermission(
env,
[chainId],
msg.origin
Expand Down Expand Up @@ -736,7 +736,7 @@ const handleRequestSignAminoMsgFetchSigning: (
service: KeyRingService
) => InternalHandler<RequestSignAminoMsgFetchSigning> = (service) => {
return async (env, msg) => {
await service.permissionService.checkBasicAccessPermission(
await service.permissionService.checkOrGrantBasicAccessPermission(
env,
[msg.chainId],
msg.origin
Expand All @@ -757,7 +757,7 @@ const handleRequestSignDirectMsgFetchSigning: (
service: KeyRingService
) => InternalHandler<RequestSignDirectMsgFetchSigning> = (service) => {
return async (env, msg) => {
await service.permissionService.checkBasicAccessPermission(
await service.permissionService.checkOrGrantBasicAccessPermission(
env,
[msg.chainId],
msg.origin
Expand Down Expand Up @@ -804,7 +804,7 @@ const handleRequestVerifyADR36AminoSignDocFetchSigning: (
service
) => {
return async (env, msg) => {
await service.permissionService.checkBasicAccessPermission(
await service.permissionService.checkOrGrantBasicAccessPermission(
env,
[msg.chainId],
msg.origin
Expand All @@ -829,7 +829,7 @@ const handleGetAccountMsg: (
throw Error("could not detect current chainId");
}

await service.permissionService.checkBasicAccessPermission(
await service.permissionService.checkOrGrantBasicAccessPermission(
env,
[chainId],
msg.origin
Expand Down Expand Up @@ -870,7 +870,7 @@ const handleGetKeyMsgFetchSigning: (
) => InternalHandler<GetKeyMsgFetchSigning> = (service) => {
return async (env, msg) => {
const chainId = await service.chainsService.getSelectedChain();
await service.permissionService.checkBasicAccessPermission(
await service.permissionService.checkOrGrantBasicAccessPermission(
env,
[chainId],
msg.origin
Expand Down
1 change: 0 additions & 1 deletion packages/stores/src/core/interaction/chain-switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export class ChainSwitchStore {

try {
const data = this.waitingSuggestedChainId;

if (data) {
yield this.interactionStore.approve(data.type, data.id, chainId);
}
Expand Down
27 changes: 27 additions & 0 deletions wallet-api-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.idea
node_modules/
.DS_Store
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
.yarn/*
1 change: 1 addition & 0 deletions wallet-api-example/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
27 changes: 27 additions & 0 deletions wallet-api-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Keplr Example
This is a simple example if how to use Keplr extension.

## Requirements
- Node.js v18+
- protoc v21.3 (recommended)
```bash
# This script is example for mac arm64 user. for other OS, replace URL(starts with https://..) to be matched with your OS from https://github.com/protocolbuffers/protobuf/releases/tag/v21.3
curl -Lo protoc-21.3.zip https://github.com/protocolbuffers/protobuf/releases/download/v21.3/protoc-21.3-osx-aarch_64.zip
unzip protoc-21.3.zip -d $HOME/protoc
cp -r $HOME/protoc/include /usr/local
cp -r $HOME/protoc/bin /usr/local
```

## Local Development

Install dependencies

```bash
yarn install
yarn proto-build
```

Run development Server
```bash
yarn start
```
22 changes: 22 additions & 0 deletions wallet-api-example/config-overrides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const webpack = require('webpack');

module.exports = function override(config) {
const fallback = config.resolve.fallback || {};
Object.assign(fallback, {
os: require.resolve("os-browserify/browser"),
buffer: require.resolve("buffer/"),
http: require.resolve("stream-http"),
https: require.resolve("https-browserify"),
crypto: require.resolve("crypto-browserify"),
stream: require.resolve("stream-browserify"),
process: require.resolve("process/browser"),
})
config.resolve.fallback = fallback;
config.plugins = (config.plugins || []).concat([
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer']
})
])
return config;
}
56 changes: 56 additions & 0 deletions wallet-api-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "keplr-example",
"version": "0.1.0",
"private": true,
"dependencies": {
"@ethersproject/address": "^5.7.0",
"@keplr-wallet/common": "^0.12.96",
"@keplr-wallet/cosmos": "^0.12.96",
"@keplr-wallet/provider-extension": "^0.12.96",
"@keplr-wallet/types": "^0.12.96",
"@keplr-wallet/unit": "^0.12.96",
"@types/node": "^16.18.48",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"typescript": "^4.9.5"
},
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-scripts eject",
"proto-build": "zx ./src/proto-types-gen/scripts/proto-gen.mjs"
},
"eslintConfig": {
"extends": [
"react-app"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
"https-browserify": "^1.0.0",
"os-browserify": "^0.3.0",
"process": "^0.11.10",
"react-app-rewired": "^2.2.1",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"ts-proto": "^1.157.0",
"zx": "^7.2.3"
}
}
16 changes: 16 additions & 0 deletions wallet-api-example/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<title>Keplr Example App</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
Binary file added wallet-api-example/public/keplr-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading