Skip to content

Commit

Permalink
fix(dcellar-web-ui): unified encoding method same as go-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
devinxl committed May 28, 2024
1 parent 14b9b36 commit bca052c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
5 changes: 4 additions & 1 deletion apps/dcellar-web-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"antd": "5.11.0",
"ahooks": "3.7.7",
"hash-wasm": "4.10.0",
"@bnb-chain/greenfield-js-sdk": "2.1.0-alpha.0",
"@bnb-chain/greenfield-js-sdk": "2.1.0-alpha.2",
"@bnb-chain/greenfield-cosmos-types": "0.4.0-alpha.32",
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
Expand Down Expand Up @@ -92,5 +92,8 @@
"prettier --write"
],
"*.ts?(x)": "tsc-files --noEmit"
},
"browser": {
"crypto": false
}
}
37 changes: 23 additions & 14 deletions apps/dcellar-web-ui/src/utils/string.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IQuotaProps } from '@bnb-chain/greenfield-js-sdk';
import BigNumber from 'bignumber.js';
import { hexlify, toUtf8Bytes } from 'ethers/lib/utils';

export const trimFloatZero = (str: string) => {
const [intStr, floatStr] = str.split('.');
Expand Down Expand Up @@ -89,22 +90,30 @@ export const encodeObjectName = (pathName: string) => {
encodedPathName += s;
continue;

// default:
// // . ! @ # $ % ^ & * ) ( - + = { } [ ] / " , ' < > ~ \ .` ? : ; | \\
// // eslint-disable-next-line no-useless-escape
// if (/[.!@#$%^&*)(\-+={}\[\]\/",'<>~·`?:;|\\]+$/.test(s)) {
// // english characters
// const hexStr = s.charCodeAt(0).toString(16);
// encodedPathName += '%' + hexStr.toUpperCase();
// } else {
// // others characters
// try {
// encodedPathName += encodeURI(s);
// } catch (e) {
// encodedPathName += s;
// }
// }
// others characters need to be encoded
default:
// . ! @ # $ % ^ & * ) ( - + = { } [ ] / " , ' < > ~ \ .` ? : ; | \\
// eslint-disable-next-line no-useless-escape
if (/[.!@#$%^&*)(\-+={}\[\]\/",'<>~·`?:;|\\]+$/.test(s)) {
// english characters
const hexStr = s.charCodeAt(0).toString(16);
encodedPathName += '%' + hexStr.toUpperCase();
} else {
// others characters
try {
encodedPathName += encodeURI(s);
} catch (e) {
encodedPathName += s;
}
default: {
const u = toUtf8Bytes(s);

for (let i = 0; i < u.length; i++) {
const hexStr = hexlify(u[i]);
encodedPathName += '%' + hexStr.slice(2).toUpperCase();
}
}
}
}
return encodedPathName;
Expand Down
8 changes: 4 additions & 4 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bca052c

Please sign in to comment.