Skip to content

Commit

Permalink
Merge branch 'additional-tooling' into feat/LW-10346-speed-up-lace-ex…
Browse files Browse the repository at this point in the history
…tension-cip30-methods
  • Loading branch information
mirceahasegan committed Oct 10, 2024
2 parents 78cb8ee + 69defd1 commit 30eab97
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
RemoteApiPropertyType
} from '@cardano-sdk/web-extension';

const MODE_STORAGE_KEY = 'lace-features';
const logger = console;

export const WALLET_MODE_CHANNEL = 'wallet-mode';
Expand All @@ -33,27 +32,5 @@ const withModeApi = async <T>(invoke: (api: ModeApi) => Promise<T>, runtime: Min
}
};

const loadAndStoreFeatureMode = async (runtime: MinimalRuntime) =>
withModeApi(async (modeApi) => {
const featureMode = await modeApi.getMode();
localStorage.setItem(MODE_STORAGE_KEY, JSON.stringify(featureMode));
return featureMode;
}, runtime);

/**
* Get feature flags:
* - if doesn't exist in local storage, get feature flags from service worker
* by using the specified runtime for messaging
* - if exists in local storage
* - return stored feature flags
* - as a side effect, get feature flags from service worker by using the
* specified runtime for messaging and store them in local storage
*/
export const getMode = async (runtime: MinimalRuntime): Promise<'lace' | 'nami'> =>
// const storedMode = localStorage.getItem(MODE_STORAGE_KEY);
// if (storedMode) {
// // update feature flags in local storage without blocking the return
// void loadAndStoreFeatureMode(runtime);
// return JSON.parse(storedMode) as WalletMode;
// }
loadAndStoreFeatureMode(runtime);
withModeApi(async (modeApi) => await modeApi.getMode(), runtime);
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const launchCip30Popup = async (url: string, windowType: Windows.CreateTy
tab.id,
calculatePopupWindowPositionAndSize(
currentWindow,
windowType === 'popup' ? (namiMigration.mode === 'lace' ? POPUP_WINDOW : POPUP_WINDOW_NAMI) : HW_POPUP_WINDOW
windowType === 'popup' ? (namiMigration?.mode === 'nami' ? POPUP_WINDOW_NAMI : POPUP_WINDOW) : HW_POPUP_WINDOW
),
windowType,
true
Expand Down
7 changes: 5 additions & 2 deletions packages/nami/src/ui/UpgradeToLaceHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ export const UpgradeToLaceHeader = ({
}) => {
const location = useLocation();

if (location.pathname.startsWith('/hwTab')) return null;
if (location.pathname.startsWith('/dapp')) return null;
if (
location.pathname.startsWith('/hwTab') ||
location.pathname.startsWith('/dapp')
)
return null;

return (
<motion.div
Expand Down
6 changes: 5 additions & 1 deletion packages/nami/src/ui/app/pages/dapp-connector/signTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,11 @@ export const SignTx = ({
capture(Events.DappConnectorDappTxCancelClick);
}}
sign={async password => {
return request?.sign(password ?? '');
try {
await request?.sign(password ?? '');
} catch (error) {
setIsLoading(l => ({ ...l, error: `Failed to sign. ${error}` }));
}
}}
onConfirm={async (status, signedTx) => {
if (status) {
Expand Down
20 changes: 12 additions & 8 deletions packages/nami/src/ui/app/pages/send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -709,14 +709,18 @@ const Send = ({
</Box>
}
ref={ref}
sign={async (password, hw) => {
sign={async (password, _hw) => {
capture(Events.SendTransactionConfirmationConfirmClick);
return await signAndSubmit({
tx,
password,
withSignTxConfirmation,
inMemoryWallet,
});
try {
await signAndSubmit({
tx,
password,
withSignTxConfirmation,
inMemoryWallet,
});
} catch (error) {
console.log('Failed to sign and submit transaction', error);
}
}}
getCbor={async () => {
const inspection = await tx.inspect();
Expand All @@ -742,7 +746,7 @@ const Send = ({
status: 'success',
duration: 5000,
});
if (await isValidAddress(address.result, currentChain)) {
if (isValidAddress(address.result, currentChain)) {
await updateAccountMetadata({
namiMode: { recentSendToAddress: address.result },
});
Expand Down

0 comments on commit 30eab97

Please sign in to comment.