Skip to content

Commit 73d8d1e

Browse files
fix: example (#610)
* fix: example * chore: remove xrp --------- Co-authored-by: Leon <[email protected]>
1 parent fb0244c commit 73d8d1e

File tree

12 files changed

+113
-187
lines changed

12 files changed

+113
-187
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"workspaces": {
1111
"packages": [
1212
"packages/*",
13-
"packages/connect-examples/shared-constants",
1413
"packages/connect-examples/expo-example",
1514
"packages/connect-examples/electron-example",
1615
"packages/connect-examples/expo-playground"
@@ -79,15 +78,16 @@
7978
"@rollup/plugin-babel": "^5.3.1",
8079
"@rollup/plugin-commonjs": "^22.0.0",
8180
"@rollup/plugin-json": "^4.1.0",
81+
"@rollup/plugin-node-resolve": "^16.0.3",
8282
"@rollup/plugin-typescript": "^8.3.2",
8383
"@types/bchaddrjs": "^0.4.3",
8484
"@types/jest": "^27.5.1",
8585
"@types/node": "^18.18.8",
8686
"@types/shelljs": "^0.8.11",
87-
"electron-builder": "^24.9.1",
8887
"babel-jest": "^28.1.3",
8988
"babel-loader": "^8.2.5",
9089
"cross-env": "^7.0.3",
90+
"electron-builder": "^24.9.1",
9191
"eslint": "^8.4.1",
9292
"eslint-config-wesbos": "3.2.3",
9393
"eslint-plugin-jest": "^26.6.0",

packages/connect-examples/expo-example/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@tamagui/toast": "1.90.2",
4040
"@ton/core": "^0.57.0",
4141
"asyncstorage-down": "^4.2.0",
42+
"axios": "1.12.2",
4243
"bchaddrjs": "^0.5.2",
4344
"bitcoinjs-lib": "^6.1.5",
4445
"bn.js": "^5.2.1",
@@ -75,15 +76,14 @@
7576
"react-native-screens": "~3.29.0",
7677
"react-native-svg": "^14.1.0",
7778
"react-native-web": "~0.19.10",
78-
"ripple-keypairs": "^1.1.4",
7979
"rlp": "^3.0.0",
8080
"stackblur-canvas": "^2.7.0",
8181
"stream-browserify": "^3.0.0",
8282
"tamagui": "^1.90.2",
8383
"text-encoding": "^0.7.0",
8484
"tonweb": "^0.0.66",
8585
"varint": "^6.0.0",
86-
"xrpl": "^4.0.0"
86+
"ripple-address-codec": "^5.0.0"
8787
},
8888
"devDependencies": {
8989
"@babel/core": "^7.20.0",
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Axios wrapper to fix module.exports.default for rollup compatibility
2+
// eslint-disable-next-line @typescript-eslint/no-var-requires
3+
const axios = require('axios');
4+
5+
// Create a proper wrapper that satisfies rollup's _interopDefaultLegacy expectations
6+
// The compiled code uses: axios__default["default"].interceptors.request.use()
7+
// So we need to ensure that when webpack resolves this, it has the right structure
8+
9+
// Ensure axios has a .default property pointing to itself
10+
if (!axios.default) {
11+
axios.default = axios;
12+
}
13+
14+
// Also ensure interceptors exist
15+
if (!axios.interceptors) {
16+
// This shouldn't happen, but just in case, create a mock
17+
axios.interceptors = {
18+
request: {
19+
use: fn => {
20+
console.warn('axios.interceptors.request.use mock called');
21+
return 0;
22+
},
23+
},
24+
response: {
25+
use: fn => {
26+
console.warn('axios.interceptors.response.use mock called');
27+
return 0;
28+
},
29+
},
30+
};
31+
}
32+
33+
module.exports = axios;
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
// eslint-disable-next-line import/no-relative-packages
2-
import { getConnectSrc } from '@onekey-internal/shared-constants';
32

4-
export const CONNECT_SRC = getConnectSrc();
3+
export const CONNECT_SRC = process.env.CONNECT_SRC || `https://jssdk.onekey.so/1.1.17/`;

packages/connect-examples/expo-example/src/utils/mockDevice/method/xrpGetAddress.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/* eslint-disable no-bitwise */
22
import type { Success, Unsuccessful } from '@onekeyfe/hd-core';
3-
import { bytesToHex } from '@noble/hashes/utils';
4-
import { deriveAddress } from 'xrpl';
3+
import { bytesToHex, hexToBytes } from '@noble/hashes/utils';
4+
import { encodeAccountID } from 'ripple-address-codec';
5+
import { ripemd160 } from '@noble/hashes/ripemd160';
6+
import { sha256 } from '@noble/hashes/sha256';
57
import { deriveKeyPairWithPath, mnemonicToSeed } from '../helper';
68

79
function publicKeyToAddress(publicKey: Uint8Array): string {
810
const pub = bytesToHex(publicKey).toUpperCase();
9-
return deriveAddress(pub);
11+
return encodeAccountID(ripemd160(sha256(hexToBytes(pub)))).toString();
1012
}
1113

1214
/**

packages/connect-examples/expo-example/webpack.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ module.exports = async function (env, argv) {
5555
});
5656
});
5757

58+
// Force axios to use our wrapper which ensures .default exists
59+
config.resolve.alias = {
60+
...config.resolve.alias,
61+
// Force all axios imports to use our wrapper (no $ to match all imports including from node_modules)
62+
axios: require.resolve('./shim-axios.js'),
63+
};
64+
5865
// 保持其他配置不变
5966
config.resolve.fallback = {
6067
crypto: require.resolve('./shim/crypto'),

packages/connect-examples/expo-playground/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"react-router-dom": "^7.6.2",
6161
"reactflow": "^11.11.4",
6262
"rehype-highlight": "^7.0.2",
63-
"ripple-keypairs": "^2.0.0",
6463
"stream-browserify": "^3.0.0",
6564
"stream-http": "^3.2.0",
6665
"string_decoder": "^1.3.0",

packages/connect-examples/shared-constants/constants.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/connect-examples/shared-constants/package.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/core/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,13 @@
3535
"semver": "^7.3.7"
3636
},
3737
"peerDependencies": {
38-
"@noble/hashes": "^1.1.3",
39-
"ripple-keypairs": "^1.3.1"
38+
"@noble/hashes": "^1.1.3"
4039
},
4140
"devDependencies": {
4241
"@noble/hashes": "^1.1.3",
4342
"@types/parse-uri": "^1.0.0",
4443
"@types/semver": "^7.3.9",
4544
"@types/w3c-web-usb": "^1.0.10",
46-
"@types/web-bluetooth": "^0.0.21",
47-
"ripple-keypairs": "^1.3.1"
45+
"@types/web-bluetooth": "^0.0.21"
4846
}
4947
}

0 commit comments

Comments
 (0)