Skip to content

Commit

Permalink
ROLLBACK: update dfinity packages (#290)
Browse files Browse the repository at this point in the history
* ROLLBACK: dfinity packages update

* Fixed inifinite nft loading and firefox manifest

* Add new packages and recovered fixes and activity formattin

* Used proper deps

;

* Updated package version

* Installed compatible controller package

Co-authored-by: rocky-fleek <[email protected]>
  • Loading branch information
0xAaCE and rocky-fleek authored Nov 17, 2021
1 parent bfa1f12 commit c0c3553
Show file tree
Hide file tree
Showing 7 changed files with 1,050 additions and 1,009 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"@fleekhq/browser-rpc": "^2.0.2",
"@material-ui/core": "^4.11.3",
"@material-ui/icons": "^4.11.2",
"@psychedelic/dab-js": "0.3.0",
"@psychedelic/plug-controller": "0.11.3",
"@psychedelic/plug-inpage-provider": "1.5.0",
"@psychedelic/dab-js": "0.2.5",
"@psychedelic/plug-controller": "0.11.0-cap-custom",
"@psychedelic/plug-inpage-provider": "1.5.0-comp",
"@reduxjs/toolkit": "^1.6.0",
"advanced-css-reset": "^1.2.2",
"axios": "^0.21.1",
Expand Down
26 changes: 12 additions & 14 deletions source/Background/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ import NotificationManager from '../lib/NotificationManager';

import SIZES from '../Pages/Notification/components/Transfer/constants';
import { getKeyringHandler, HANDLER_TYPES, getKeyringErrorMessage } from './Keyring';
import {
validateTransferArgs,
validateBurnArgs,
validateTransactions,
fromArrayBufferToHex,
fromHexToArrayBuffer,
} from './utils';
import { validateTransferArgs, validateBurnArgs, validateTransactions } from './utils';
import ERRORS, { SILENT_ERRORS } from './errors';
import plugProvider from '../Inpage/index';

Expand Down Expand Up @@ -467,8 +461,10 @@ backgroundController.exposeController(
height,
});
} else {
const signed = await keyring.sign(fromHexToArrayBuffer(payload));
callback(null, fromArrayBufferToHex(signed));
const parsedPayload = new Uint8Array(Object.values(payload));

const signed = await keyring.sign(parsedPayload.buffer);
callback(null, [...new Uint8Array(signed)]);
}
});
} catch (e) {
Expand All @@ -484,8 +480,10 @@ backgroundController.exposeController(

if (status === CONNECTION_STATUS.accepted) {
try {
const signed = await keyring.sign(fromHexToArrayBuffer(payload));
callback(null, fromArrayBufferToHex(signed), [{ callId, portId }]);
const parsedPayload = new Uint8Array(Object.values(payload));

const signed = await keyring.sign(parsedPayload.buffer);
callback(null, new Uint8Array(signed), [{ callId, portId }]);
callback(null, true);
} catch (e) {
callback(ERRORS.SERVER_ERROR(e), null, [{ portId, callId }]);
Expand All @@ -502,7 +500,7 @@ backgroundController.exposeController('getPublicKey', async (opts) => {
const { callback } = opts;
try {
const publicKey = await keyring.getPublicKey();
callback(null, fromArrayBufferToHex(publicKey.toDer()));
callback(null, publicKey);
} catch (e) {
callback(ERRORS.SERVER_ERROR(e), null);
}
Expand Down Expand Up @@ -568,7 +566,7 @@ backgroundController.exposeController(
});
}
const publicKey = await keyring.getPublicKey();
callback(null, fromArrayBufferToHex(publicKey.toDer()));
callback(null, publicKey);
} else {
const url = qs.stringifyUrl({
url: 'notification.html',
Expand Down Expand Up @@ -630,7 +628,7 @@ backgroundController.exposeController(
if (response?.status === CONNECTION_STATUS.accepted) {
try {
const publicKey = await keyring.getPublicKey();
callback(null, fromArrayBufferToHex(publicKey.toDer()), [{ portId, callId }]);
callback(null, publicKey, [{ portId, callId }]);
callback(null, true);
} catch (e) {
callback(ERRORS.SERVER_ERROR(e), null, [{ portId, callId }]);
Expand Down
37 changes: 0 additions & 37 deletions source/Background/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,40 +45,3 @@ export const validateTransactions = (transactions) => Array.isArray(transactions
&& transactions?.every(
(tx) => tx.idl && tx.canisterId && tx.methodName && tx.args,
);

/*
* Return an array buffer from its hexadecimal representation.
* @param hexString The hexadecimal string.
*/
export function fromHexToUint8Array(hexString) {
return new Uint8Array(
(hexString.match(/.{1,2}/g) ?? []).map((byte) => parseInt(byte, 16)),
);
}

/**
* Returns an hexadecimal representation of an array buffer.
* @param bytes The array buffer.
*/
export function fromUint8ArrayToHex(bytes) {
return bytes.reduce(
(str, byte) => str + byte.toString(16).padStart(2, '0'),
'',
);
}

/**
* Return an array buffer from its hexadecimal representation.
* @param hexString The hexadecimal string.
*/
export function fromHexToArrayBuffer(hexString) {
return fromHexToUint8Array(hexString).buffer;
}

/**
* Returns an hexadecimal representation of an array buffer.
* @param bytes The array buffer.
*/
export function fromArrayBufferToHex(bytes) {
return fromUint8ArrayToHex(new Uint8Array(bytes));
}
2 changes: 2 additions & 0 deletions source/Popup/Views/Home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { HANDLER_TYPES, sendMessage } from '@background/Keyring';
import {
setAccountInfo,
setCollections,
setCollectionsLoading,
} from '@redux/wallet';

import { useICPPrice } from '@redux/icp';
Expand Down Expand Up @@ -68,6 +69,7 @@ const Home = () => {
if (nftCollections?.length) {
dispatch(setCollections({ collections: nftCollections, principalId }));
}
dispatch(setCollectionsLoading(false));
});
}
dispatch(setAccountInfo(state.wallets[state.currentWalletId]));
Expand Down
2 changes: 1 addition & 1 deletion source/components/NFTs/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const NFTs = () => {
dispatch(setCollectionsLoading(true));
sendMessage({
type: HANDLER_TYPES.GET_NFTS,
params: { refresh: false },
params: {},
}, (nftCollections) => {
if (nftCollections?.length && !optimisticNFTUpdate) {
dispatch(setCollections({ collections: nftCollections, principalId }));
Expand Down
1 change: 0 additions & 1 deletion source/redux/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const walletSlice = createSlice({
collections: [],
collectionsLoading: true,
transactionsLoading: true,
optimisticNFTUpdate: false,
},
reducers: {
updateWalletDetails: (state, action) => {
Expand Down
Loading

0 comments on commit c0c3553

Please sign in to comment.