Skip to content

Commit

Permalink
fix(stacking): bn.js buffer polyfill hack, closes #369
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Dec 22, 2020
1 parent 1e03d8e commit e3e1de5
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 3,806 deletions.
4 changes: 2 additions & 2 deletions app/components/home/stacking-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ export const StackingCard: FC<StackingCardProps> = () => {
</Text>
</Flex>
)}
<Flex flexDirection="column" mt="tight" mb="base-loose">
{/* <Flex flexDirection="column" mt="tight" mb="base-loose">
<Text textStyle="body.small.medium">Reward to be paid to</Text>
<Text as="code" fontSize="13px" mt="tight" color="ink.600">
{stackerInfo?.pox_address}
</Text>
</Flex>
</Flex> */}
</Box>
</Box>
)}
Expand Down
6 changes: 5 additions & 1 deletion app/modals/stacking/stacking-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ export const StackingModal: FC<StackingModalProps> = props => {

if (error) {
setIsDecrypting(false);
setDecryptionError('Unable to decrypt wallet');
setDecryptionError(
String(error) === 'OperationError'
? 'Unable to decrypt wallet'
: 'Something else went wrong'
);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion app/modals/stacking/steps/decrypt-wallet-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const DecryptWalletForm: Props = props => {
<Input onChange={handlePasswordInput} type="password" mt="base-loose" />
{hasSubmitted && decryptionError && (
<ErrorLabel>
<ErrorText>Password entered is incorrect</ErrorText>
<ErrorText>{decryptionError}</ErrorText>
</ErrorLabel>
)}
<Text textStyle="body.small" mt="base-tight" mb="base-loose" display="block">
Expand Down
3 changes: 3 additions & 0 deletions app/polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(window as any).global = window;
// eslint-disable-next-line @typescript-eslint/no-var-requires
(window as any).Buffer = (window as any).Buffer || require('buffer').Buffer;
4 changes: 2 additions & 2 deletions app/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contextBridge.exposeInMainWorld('electron', {
__filename,
});

async function deriveArgon2Key({ pass, salt }: Record<string, 'pass' | 'salt'>) {
async function deriveArgon2Key({ pass, salt }: Record<'pass' | 'salt', string>) {
const result = await argon2.hash({
pass,
salt,
Expand All @@ -54,7 +54,7 @@ const walletApi = {
initialValue: () => ipcRenderer.sendSync('store-getEntireStore'),
},

deriveKey: async (args: any) => deriveArgon2Key(args),
deriveKey: async (args: Record<'pass' | 'salt', string>) => deriveArgon2Key(args),

windowEvents: {
blur(callback: () => void) {
Expand Down
3 changes: 1 addition & 2 deletions configs/webpack.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { dependencies as externals } from '../app/package.json';
export default {
target: 'web',

// externals: [...Object.keys(externals || {})],

module: {
noParse: [/\.wasm$/],
rules: [
Expand Down Expand Up @@ -46,6 +44,7 @@ export default {
fs: 'empty',
Buffer: false,
process: false,
child_process: 'empty',
},

output: {
Expand Down
10 changes: 6 additions & 4 deletions configs/webpack.config.renderer.dev.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ export default merge(baseConfig, {

mode: 'development',

// target: 'electron-renderer',
target: 'web',

entry: [
'core-js',
'regenerator-runtime/runtime',
...(process.env.PLAIN_HMR ? [] : ['react-hot-loader/patch']),
`webpack-dev-server/client?http://localhost:${port}/`,
'webpack/hot/only-dev-server',
require.resolve('../app/polyfill.ts'),
require.resolve('../app/index.tsx'),
],

Expand Down Expand Up @@ -106,6 +107,7 @@ export default merge(baseConfig, {
resolve: {
alias: {
'react-dom': '@hot-loader/react-dom',
'bn.js': path.join('./node_modules/bn.js'),
},
},
plugins: [
Expand Down Expand Up @@ -145,9 +147,9 @@ export default merge(baseConfig, {
debug: true,
}),

new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
// new webpack.ProvidePlugin({
// Buffer: ['buffer', 'Buffer'],
// }),

new CopyPlugin({
patterns: [{ from: 'node_modules/argon2-browser/dist/argon2.wasm', to: '.' }],
Expand Down
2 changes: 1 addition & 1 deletion configs/webpack.config.renderer.dev.dll.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default merge(baseConfig, {

mode: 'development',

target: 'electron-renderer',
target: 'web',

externals: ['fsevents', 'crypto-browserify'],

Expand Down
14 changes: 12 additions & 2 deletions configs/webpack.config.renderer.prod.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ export default merge(baseConfig, {

mode: 'production',

// target: 'electron-renderer',
target: 'web',

entry: ['core-js', 'regenerator-runtime/runtime', path.join(__dirname, '..', 'app/index.tsx')],
entry: [
'core-js',
'regenerator-runtime/runtime',
path.join(__dirname, '..', 'app/polyfill.ts'),
path.join(__dirname, '..', 'app/index.tsx'),
],

output: {
path: path.join(__dirname, '..', 'app/dist'),
Expand All @@ -33,6 +37,12 @@ export default merge(baseConfig, {
libraryTarget: 'var',
},

resolve: {
alias: {
'bn.js': path.join('./node_modules/bn.js'),
},
},

module: {
rules: [
// WOFF Font
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
"bignumber.js": "9.0.1",
"bip39": "3.0.2",
"bitcoin-address-validation": "1.0.2",
"bn.js": "5.1.3",
"bn.js": "https://github.com/kyranjamie/bn.js",
"buffer": "6.0.2",
"c32check": "1.1.2",
"connected-react-router": "6.8.0",
Expand Down
Loading

0 comments on commit e3e1de5

Please sign in to comment.