Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: deprecation warnings, closes #4928 #4929

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 56 additions & 20 deletions src/inpage/inpage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,31 +252,67 @@ const provider: HiroWalletProviderOverrides = {
},
};

function consoleDeprecationNotice(text: string) {
// eslint-disable-next-line no-console
console.warn(`Deprecation warning: ${text}`);
}

function warnAboutDeprecatedProvider(legacyProvider: object) {
return Object.fromEntries(
Object.entries(legacyProvider).map(([key, value]) => {
if (typeof value === 'function') {
return [
key,
(...args: any[]) => {
switch (key) {
case 'authenticationRequest':
consoleDeprecationNotice(
`Use LeatherProvider.request('getAddresses') instead, see docs https://leather.gitbook.io/developers/bitcoin/connect-users/get-addresses`
);
break;
case 'psbtRequest':
consoleDeprecationNotice(
`Use LeatherProvider.request('signPsbt') instead, see docs https://leather.gitbook.io/developers/bitcoin/sign-transactions/partially-signed-bitcoin-transactions-psbts`
);
break;
case 'structuredDataSignatureRequest':
case 'signatureRequest':
consoleDeprecationNotice(`Use LeatherProvider.request('stx_signMessage') instead`);
break;
default:
consoleDeprecationNotice(
'The provider object is deprecated. Use `LeatherProvider` instead'
);
}

return value(...args);
},
];
}
return [key, value];
})
);
}

try {
// Make properties immutable to contend with other wallets that use agressive
// "prioritisation" default settings. As wallet use this approach, Leather has
// to use it too, resulting in browsers' own internal logic being used to
// determine content script exeuction order. A more fair way to contend over
// shared provider space.
Object.defineProperty(window, 'StacksProvider', { get: () => provider, set: () => {} });
Object.defineProperty(window, 'LeatherProvider', { get: () => provider, set: () => {} });
// Makes properties immutable to contend with other wallets that use agressive
// "prioritisation" default settings. As other wallet's use this approach,
// Leather has to use it too, so that the browsers' own internal logic being
// used to determine content script exeuction order. A more fair way to
// contend over shared provider space. `StacksProvider` should be considered
// deprecated and each wallet use their own provider namespace.
Object.defineProperty(window, 'StacksProvider', {
get: () => warnAboutDeprecatedProvider(provider),
set: () => {},
});
Object.defineProperty(window, 'HiroWalletProvider', {
get: () => provider,
get: () => warnAboutDeprecatedProvider(provider),
set: () => {},
});
Object.defineProperty(window, 'LeatherProvider', { get: () => provider, set: () => {} });
} catch (e) {}

// Legacy product provider objects
if (typeof window.btc === 'undefined') {
(window as any).btc = {
request: (window as any).StacksProvider?.request,
listen(event: 'accountChange', callback: (arg: any) => void) {
function handler(e: MessageEvent) {
if (!e.data) return;
if ((e as any).event !== event) return;
callback((e as any).event);
}
window.addEventListener('message', handler);
return () => window.removeEventListener('message', handler);
},
};
(window as any).btc = warnAboutDeprecatedProvider(provider);
}
Loading