Skip to content

Commit 9c49f33

Browse files
Cancuuuangarita-devrocky-fleektomiiralinasytnik
authored
Release/0.6.0 (#563)
* Chore/update 0.6.0 (#567) * Fixed transactionId and object proptypes * Auto fix with --fix * Fixed remaining issues * Updated controller to 0.19.8 and bumped plug version to 0.5.4 * Moved whitelist population to requestConnect * Removed whitelist population * Updated branch Co-authored-by: rocky-fleek <[email protected]> Co-authored-by: tomiir <[email protected]> * add tokens and add nft buttons * add nft form done - form component abstraction not done - add nft not working yet * feat: tests initialization * added get-nft-info method * added few changes * now the buttons looks like the design * removed standards to DIP721v2 only - display token info in step2 * feat: test ids added/first test added and passed * added add-custom-nft function * feat: all tests added and passed * fix: variables changes * feat: extra case added * feat: tests for settings-network added and done * added get nfts after add custom in step2 * Fix: Redundant optimistic update (#587) * Added controller with optimistic update fix. Removed filterCollectionTokens method as it was redundant * Reconciliated yarn lock * Renamed hook to blockNFTFetch and removed unnecessary formatting * Restored lockfile * Reinstalled controller' Co-authored-by: rocky-fleek <[email protected]> * feat: send custom tokens on sonic network tests added and passed * fix: hardcode fixes * feat: case with checking that tabs are blocked added * show collections with 0 nfts without chevron - if the icon is null show a default image * change package.json and yarn.lock to upstream content * few console logs removed, text and state names * yarn lock updated to release yarn lock * now can download pem file with your account id * Remove custom token (#589) * Updated controller version * Added removeToken to Keyring * Added remove to AssetItem * Prepopulated protectedAsset * Added translation for remove token modal * Renamed Remove to remove custom token * Feat/account switch refactor (#566) * Added swit account icon * Added AccountItem component * Added edit account field * Added account switch to WalletDetails * Removed replacing icns on set * Made profile edit on click * Added walletId param to icns methods * Lint fixes for profile * Added local ICNS data * Lint fixes * Added shared transition * Conditionaly show switch account button * disable edit name while using icns * removed clgs and moved useEffect * added close curly brace * Update source/views/Extension/Views/AddNFT/hooks/useSteps.jsx Co-authored-by: angarita-dev <[email protected]> * Update source/views/Extension/Views/AddNFT/Steps/Step2.jsx Co-authored-by: angarita-dev <[email protected]> * it work calling sendMessage in AppConnection * fixed length problem * Migrated walletId to uuid * removed console.log * removed unused field on redux * fixed address shortening for ICNS names * Added border radius to custom tokens search * reduced token decimal places * Reduced font weight of text in banner * Added border raduis to second step of addToken * Updated yarn.lock * Added utils for icns address * modified getAssetFee function - removed fixed fee values - now can send max amount of any tokens * added fallback if fee and decimal doenst exist * Serialize host into metadata and pass it into regular connection requests * Controller version bump * Fixed switch account ICNS bug * Added account icon constant * replaced user icon with constant * Fixed switch account & account default icon * Updated dab-js and added fee as a parameter in the send operation * Prevented default on Profile actions (#611) * remove switch account icon (#613) * automation fixes * Installed controller and dabjs with icp standard fixes * Fixed connect account modal (#618) * Fix/Contacts (#616) * WIP * Code cleanup * mend * Fixed hiddenAccounts * Fixed state accounts * Fixed export identity * Bumped controller version * Added missing semicolon * Plug controller bump * Rollback controller to 0.22.3 * Fixed collection info and nft details issues * Fixed popup & connect accounts info (#625) * Abstracted internalRequestBalance and fixed issues with bigint parsing * Removed subaccount validation * Installed controller 0.22.5 with Principal serializatio on pid contacts * feat: new secret added * Removed provider update on useEffect * Removede console.logs * Fix/update provider & toasts (#631) * Updated provider package * Stop showing toast for provider errors * Disconnect only based on principalId * Removed update providerConnection * Made onConfirm method optional * Removed update provider connection from home * Updated contollero to version 0.22.6 * Updated extension icons to rainbow background ones (#595) Co-authored-by: rocky-fleek <[email protected]> Co-authored-by: angarita-dev <[email protected]> Co-authored-by: rocky-fleek <[email protected]> Co-authored-by: tomiir <[email protected]> Co-authored-by: Alina Sytnik <[email protected]> Co-authored-by: Alina Sytnik <[email protected]>
1 parent e0cdf12 commit 9c49f33

File tree

93 files changed

+3357
-1640
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+3357
-1640
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ typings/
7070
.env
7171
.env.test
7272

73+
# PEM files
74+
*.pem
75+
7376
# parcel-bundler cache (https://parceljs.org/)
7477
.cache
7578

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "plug",
3-
"version": "0.5.4.1",
3+
"version": "0.6.0",
44
"description": "Your plug into the Internet Computer",
55
"private": true,
66
"repository": "https://github.com/Psychedelic/plug",
@@ -37,9 +37,9 @@
3737
"@material-ui/icons": "^4.11.2",
3838
"@metamask/post-message-stream": "^4.0.0",
3939
"@psychedelic/browser-rpc": "2.1.0",
40-
"@psychedelic/dab-js": "1.4.5",
41-
"@psychedelic/plug-controller": "0.19.8",
42-
"@psychedelic/plug-inpage-provider": "^2.3.0",
40+
"@psychedelic/dab-js": "1.4.12",
41+
"@psychedelic/plug-controller": "0.22.6",
42+
"@psychedelic/plug-inpage-provider": "^2.3.1",
4343
"@reduxjs/toolkit": "^1.6.0",
4444
"advanced-css-reset": "^1.2.2",
4545
"axios": "^0.21.1",

source/Background/Keyring/index.js

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ export const HANDLER_TYPES = {
8787
EDIT_PRINCIPAL: 'edit-principal',
8888
GET_PUBLIC_KEY: 'get-public-key',
8989
GET_TOKEN_INFO: 'get-token-info',
90+
GET_NFT_INFO: 'get-nft-info',
9091
ADD_CUSTOM_TOKEN: 'add-custom-token',
92+
ADD_CUSTOM_NFT: 'add-custom-nft',
9193
CREATE_PRINCIPAL: 'create-principal',
9294
SET_CURRENT_PRINCIPAL: 'set-current-principal',
9395
GET_PEM_FILE: 'get-pem-file',
@@ -121,7 +123,9 @@ export const getKeyringErrorMessage = (type) => ({
121123
[HANDLER_TYPES.EDIT_PRINCIPAL]: 'editing your principal.',
122124
[HANDLER_TYPES.GET_PUBLIC_KEY]: 'getting your public key.',
123125
[HANDLER_TYPES.GET_TOKEN_INFO]: 'fetching token info.',
126+
[HANDLER_TYPES.GET_NFT_INFO]: 'fetching nft info.',
124127
[HANDLER_TYPES.ADD_CUSTOM_TOKEN]: 'adding custom token.',
128+
[HANDLER_TYPES.ADD_CUSTOM_NFT]: 'adding custom nft.',
125129
[HANDLER_TYPES.CREATE_PRINCIPAL]: 'creating your principal.',
126130
[HANDLER_TYPES.SET_CURRENT_PRINCIPAL]: 'setting your principal.',
127131
[HANDLER_TYPES.GET_PEM_FILE]: 'getting your PEM file.',
@@ -136,6 +140,7 @@ export const getKeyringErrorMessage = (type) => ({
136140
[HANDLER_TYPES.REMOVE_NETWORK]: 'removing the network',
137141
[HANDLER_TYPES.SET_CURRENT_NETWORK]: 'setting the current network',
138142
[HANDLER_TYPES.GET_CURRENT_NETWORK]: 'getting the current network',
143+
[HANDLER_TYPES.REMOVE_CUSTOM_TOKEN]: 'removing custom token',
139144
}[type]);
140145

141146
export const sendMessage = (args, callback) => {
@@ -179,8 +184,8 @@ export const getKeyringHandler = (type, keyring) => ({
179184
},
180185
[HANDLER_TYPES.CREATE_PRINCIPAL]: async (params) => keyring.createPrincipal(params),
181186
[HANDLER_TYPES.SET_CURRENT_PRINCIPAL]:
182-
async (walletNumber) => {
183-
await keyring.setCurrentPrincipal(walletNumber);
187+
async (walletId) => {
188+
await keyring.setCurrentPrincipal(walletId);
184189
const state = await keyring.getState();
185190
extension.tabs.query({ active: true }, (tabs) => {
186191
extension.tabs.sendMessage(tabs[0].id, { action: 'updateConnection' });
@@ -223,12 +228,13 @@ export const getKeyringHandler = (type, keyring) => ({
223228
return { error: e.message };
224229
}
225230
},
226-
[HANDLER_TYPES.GET_BALANCE]: async (subaccount) => {
231+
[HANDLER_TYPES.GET_BALANCE]: async (walletId) => {
227232
try {
228-
const assets = await keyring.getBalances({ subaccount });
233+
const assets = await keyring.getBalances({ subaccount: walletId });
229234
const parsedAssets = parseAssetsAmount(assets);
230235
const icpPrice = await getICPPrice();
231-
return formatAssets(parsedAssets, icpPrice);
236+
const formattedAssets = formatAssets(parsedAssets, icpPrice);
237+
return formattedAssets.map((asset) => recursiveParseBigint(asset));
232238
} catch (error) {
233239
// eslint-disable-next-line
234240
console.log('Error when fetching token balances', error);
@@ -259,8 +265,8 @@ export const getKeyringHandler = (type, keyring) => ({
259265
}
260266
},
261267
[HANDLER_TYPES.EDIT_PRINCIPAL]:
262-
async ({ walletNumber, name, emoji }) => (
263-
keyring.editPrincipal(walletNumber, { name, emoji })
268+
async ({ walletId, name, emoji }) => (
269+
keyring.editPrincipal(walletId, { name, emoji })
264270
),
265271
[HANDLER_TYPES.GET_PUBLIC_KEY]:
266272
async () => keyring.getPublicKey(),
@@ -279,6 +285,33 @@ export const getKeyringHandler = (type, keyring) => ({
279285
return { error: e.message };
280286
}
281287
},
288+
[HANDLER_TYPES.GET_NFT_INFO]:
289+
async ({ canisterId, standard }) => {
290+
try {
291+
const nftInfo = await keyring.getNFTInfo({
292+
canisterId,
293+
standard,
294+
});
295+
return nftInfo;
296+
} catch (e) {
297+
// eslint-disable-next-line
298+
console.log('Error while fetching NFT info', e);
299+
return { error: e.message };
300+
}
301+
},
302+
[HANDLER_TYPES.ADD_CUSTOM_NFT]:
303+
async ({ canisterId, standard }) => {
304+
try {
305+
const nfts = await keyring.registerNFT({
306+
canisterId, standard,
307+
});
308+
return (nfts || []).map((nft) => recursiveParseBigint(nft));
309+
} catch (e) {
310+
// eslint-disable-next-line
311+
console.log('Error registering nft', e);
312+
return { error: e.message };
313+
}
314+
},
282315
[HANDLER_TYPES.ADD_CUSTOM_TOKEN]:
283316
async ({ canisterId, standard, logo }) => {
284317
try {
@@ -294,7 +327,7 @@ export const getKeyringHandler = (type, keyring) => ({
294327
}
295328
},
296329
[HANDLER_TYPES.GET_PEM_FILE]:
297-
async (walletNumber) => keyring.getPemFile(walletNumber),
330+
async (walletId) => keyring.getPemFile(walletId),
298331
[HANDLER_TYPES.BURN_XTC]:
299332
async ({ to, amount }) => {
300333
try {
@@ -324,19 +357,22 @@ export const getKeyringHandler = (type, keyring) => ({
324357
return { error: e.message };
325358
}
326359
},
327-
[HANDLER_TYPES.GET_ICNS_DATA]: async ({ refresh }) => {
328-
const { wallets, currentWalletId } = await keyring.getState();
329-
let icnsData = wallets?.[currentWalletId]?.icnsData || { names: [] };
360+
[HANDLER_TYPES.GET_ICNS_DATA]: async ({ refresh, walletId = keyring.currentWalletId }) => {
361+
const { wallets } = await keyring.getState();
362+
let icnsData = wallets?.[walletId]?.icnsData || { names: [] };
330363
if (!icnsData?.names?.length || refresh) {
331-
icnsData = await keyring.getICNSData();
364+
icnsData = await keyring.getICNSData({ subaccount: walletId });
332365
} else {
333366
keyring.getICNSData();
334367
}
335368
return icnsData;
336369
},
337-
[HANDLER_TYPES.SET_REVERSE_RESOLVED_NAME]: async (name) => {
370+
[HANDLER_TYPES.SET_REVERSE_RESOLVED_NAME]: async ({
371+
name,
372+
walletId = keyring.currentWalletId,
373+
}) => {
338374
try {
339-
const res = await keyring.setReverseResolvedName({ name });
375+
const res = await keyring.setReverseResolvedName({ name, subaccount: walletId });
340376
return res;
341377
} catch (e) {
342378
// eslint-disable-next-line
@@ -434,6 +470,16 @@ export const getKeyringHandler = (type, keyring) => ({
434470
return { error: e.message };
435471
}
436472
},
473+
[HANDLER_TYPES.REMOVE_CUSTOM_TOKEN]: async (canisterId) => {
474+
try {
475+
const newTokens = await keyring.removeToken(canisterId);
476+
return Object.values(newTokens);
477+
} catch (e) {
478+
// eslint-disable-next-line
479+
console.log('Error removing the network', e);
480+
return { error: e.message };
481+
}
482+
},
437483
}[type]);
438484

439485
export const getContacts = () => new Promise((resolve, reject) => {

source/Background/errors.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ export default {
2727
code: 401, message: 'The transaction that was just attempted failed because it was not a valid batch transaction. Please contact the project’s developers.',
2828
},
2929
SIZE_ERROR: { code: 400, message: "There isn't enough space to open the popup" },
30+
GET_BALANCE_ERROR: { code: 400, message: 'There was an error trying to fetch your balances.' },
3031
...SILENT_ERRORS,
3132
};

source/Modules/Controller/connection.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,15 @@ export class ConnectionModule extends ControllerModuleBase {
9999
#disconnect() {
100100
return {
101101
methodName: 'disconnect',
102-
handler: async (opts, url) => {
103-
removeApp(this.keyring?.currentWalletId?.toString(), url, (removed) => {
102+
handler: async (opts, url, principal) => {
103+
const state = await this.keyring.getState();
104+
105+
const walletIdFromPrincipal = Object.values(state.wallets).find((wallet) => (
106+
wallet.principal === principal
107+
))?.walletId;
108+
const walletIdToRemove = walletIdFromPrincipal ?? this.keyring.currentWalletId;
109+
110+
removeApp(walletIdToRemove, url, (removed) => {
104111
if (!removed) {
105112
opts.callback(ERRORS.CONNECTION_ERROR, null);
106113
}
@@ -124,6 +131,7 @@ export class ConnectionModule extends ControllerModuleBase {
124131
const { id: callId } = message.data.data;
125132
const { id: portId } = sender;
126133
const { url: domainUrl, icons } = metadata;
134+
const newMetadata = { ...metadata, host };
127135

128136
if (isValidWhitelist) {
129137
canistersInfo = await fetchCanistersInfo(whitelist);
@@ -137,8 +145,6 @@ export class ConnectionModule extends ControllerModuleBase {
137145

138146
// If we receive a whitelist, we open the allow agent modal
139147
if (isValidWhitelist) {
140-
const newMetadata = { ...metadata, requestConnect: true };
141-
142148
const fixedHeight = this.keyring?.isUnlocked
143149
? Math.min(422 + 65 * whitelist.length, 550)
144150
: SIZES.loginHeight;
@@ -170,6 +176,7 @@ export class ConnectionModule extends ControllerModuleBase {
170176
argsJson: JSON.stringify({ timeout, transactionId }),
171177
type: 'connect',
172178
domainUrl,
179+
metadataJson: JSON.stringify(newMetadata),
173180
}, callback);
174181
}
175182
},

source/Modules/Controller/information.js

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ export class InformationModule extends ControllerModuleBase {
2828
];
2929
}
3030

31-
async #internalRequestBalance(accountId, callback) {
31+
async #internalRequestBalance(subaccount, callback, portConfig) {
3232
const getBalance = getKeyringHandler(HANDLER_TYPES.GET_BALANCE, this.keyring);
33-
const icpBalance = await getBalance(accountId);
34-
if (icpBalance.error) {
35-
callback(ERRORS.SERVER_ERROR(icpBalance.error), null);
33+
const balances = await getBalance(subaccount);
34+
if (balances?.error) {
35+
callback(ERRORS.GET_BALANCE_ERROR, null, portConfig);
3636
} else {
37-
callback(null, icpBalance);
37+
callback(null, balances, portConfig);
3838
}
3939
}
4040

@@ -44,14 +44,10 @@ export class InformationModule extends ControllerModuleBase {
4444
methodName: 'requestBalance',
4545
handler: async (opts, metadata, subaccount, transactionId) => {
4646
const { callback, message, sender } = opts;
47-
4847
getApps(this.keyring?.currentWalletId.toString(), (apps = {}) => {
4948
const app = apps?.[metadata.url] || {};
50-
5149
if (app?.status === CONNECTION_STATUS.accepted) {
52-
if (subaccount && Number.isNaN(parseInt(subaccount, 10))) {
53-
callback(ERRORS.CLIENT_ERROR('Invalid account id'), null);
54-
} else if (!this.keyring?.isUnlocked) {
50+
if (!this.keyring?.isUnlocked) {
5551
this.displayPopUp({
5652
callId: message.data.data.id,
5753
portId: sender.id,
@@ -78,22 +74,9 @@ export class InformationModule extends ControllerModuleBase {
7874
const { subaccount } = args;
7975
getApps(this.keyring?.currentWalletId.toString(), async (apps = {}) => {
8076
const app = apps?.[url] || {};
81-
callback(null, true);
82-
77+
callback(null, true); // Close modal
8378
if (app?.status === CONNECTION_STATUS.accepted) {
84-
const getBalance = getKeyringHandler(
85-
HANDLER_TYPES.GET_BALANCE,
86-
this.keyring,
87-
);
88-
const icpBalance = await getBalance(subaccount);
89-
90-
if (icpBalance.error) {
91-
callback(ERRORS.SERVER_ERROR(icpBalance.error), null, [
92-
{ portId, callId },
93-
]);
94-
} else {
95-
callback(null, icpBalance, [{ portId, callId }]);
96-
}
79+
this.#internalRequestBalance(subaccount, callback, [{ portId, callId }]);
9780
} else {
9881
callback(ERRORS.CONNECTION_ERROR, null, [{ portId, callId }]);
9982
}

source/Modules/storageManager.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ export const getApps = (currentWalletId, cb) => {
2727
const defaultValue = {};
2828

2929
secureGetWrapper(currentWalletId, defaultValue, (state) => (
30-
cb(state?.[parseInt(currentWalletId, 10)]?.apps || defaultValue)
30+
cb(state?.[currentWalletId]?.apps || defaultValue)
3131
));
3232
};
3333

3434
export const getApp = (currentWalletId, appUrl, cb) => {
3535
const defaultValue = {};
3636

3737
secureGetWrapper(currentWalletId, defaultValue, (state) => {
38-
cb(state?.[parseInt(currentWalletId, 10)]?.apps?.[appUrl] || defaultValue);
38+
cb(state?.[currentWalletId]?.apps?.[appUrl] || defaultValue);
3939
});
4040
};
4141

@@ -121,13 +121,22 @@ export const getProtectedIds = (cb) => {
121121

122122
export const setUseICNS = (useICNS, walletNumber, cb = () => {}) => {
123123
const defaultValue = true;
124-
secureSetWrapper({ icns: { [walletNumber]: useICNS } }, defaultValue, cb);
124+
125+
secureGetWrapper('icns', defaultValue, (state) => {
126+
cb(state?.icns?.[walletNumber] ?? defaultValue);
127+
secureSetWrapper({
128+
icns: {
129+
...state?.icns,
130+
[walletNumber]: useICNS,
131+
},
132+
}, defaultValue, cb);
133+
});
125134
};
126135

127136
export const getUseICNS = (walletNumber, cb) => {
128137
const defaultValue = true;
129138
secureGetWrapper('icns', defaultValue, (state) => {
130-
cb(state?.icns?.[parseInt(walletNumber, 10)] ?? defaultValue);
139+
cb(state?.icns?.[walletNumber] ?? defaultValue);
131140
});
132141
};
133142

@@ -145,12 +154,17 @@ export const getBatchTransactions = (cb) => {
145154

146155
export const getWalletsConnectedToUrl = (url, walletIds, cb) => {
147156
const wallets = [];
148-
walletIds.forEach((id) => {
157+
if (!walletIds.length) {
158+
cb([]);
159+
return;
160+
}
161+
162+
walletIds.forEach((id, index) => {
149163
getApp(id.toString(), url, (app = {}) => {
150164
if (app?.status === CONNECTION_STATUS.accepted) {
151165
wallets.push(id);
152166
}
153-
if (id === walletIds.length - 1) {
167+
if (index === walletIds.length - 1) {
154168
cb(wallets);
155169
}
156170
});
@@ -193,3 +207,12 @@ export const removePendingTransaction = (transactionId, cb) => {
193207
export const resetPendingTransactions = () => {
194208
secureSetWrapper({ activeTransactions: { } }, {}, () => {});
195209
};
210+
211+
export const updateWalletId = (previousWalletId, newWalletId) => {
212+
getApps(previousWalletId, (apps) => {
213+
setApps(newWalletId, apps);
214+
});
215+
getUseICNS(previousWalletId, (result) => {
216+
setUseICNS(newWalletId, result);
217+
});
218+
};

source/assets/icons/coins.svg

Lines changed: 3 additions & 0 deletions
Loading

source/assets/icons/favicon-16.png

483 Bytes
Loading

source/assets/icons/favicon-32.png

1 KB
Loading

0 commit comments

Comments
 (0)