MetaMask - RPC Error: Resource unavailable - vite

I'm getting an error while trying to get a Core wallet account. It happens when I reload the page. It should detect the account but it is not. I'm using Vite with web3modal and ethers. I also use Core wallet Avalanche Fuji test network.
Here is what console looks like:
Here is my code for checking accounts:
const updateCurrentWalletAddress = async () => {
const accounts = await window?.ethereum?.request({
method: "eth_requestAccounts"
}).catch((err)=>{
console.log(err)})
if(accounts){
setWalletAddress(accounts[0])
}
}
Here is the useEffect hook for checking:
useEffect(() => {
updateCurrentWalletAddress()
window?.ethereum?.on("accountsChanged", updateCurrentWalletAddress)
}, []);
I tried clearing browser data, cache and cookies. I tried creating a new account. I tried uninstalling Core Wallet.

The method name should be eth_accounts instead of eth_requestAccounts. This solved my problem.

Related

Azure App Configuration: JavaScript SDK Getting Features From Promise Not Returning Data

I'm doing a PoC for Azure App Configuration. I created a free instance in our Azure env and added a couple of feature flags. The Issue I am having is with the JavaScript SDK when attempting to fetch feature flags from the App Configuration. Here's the snippet of code that I am using. (NOTE: the app is a React app w/ Typescript)
import { AppConfigurationClient } from '#azure/app-configuration';
import { GetConfigurationSettingResponse } from '#azure/app-configuration';
const appConfigClient = new AppConfigurationClient(process.env.REACT_APP_APPCONFIG_CONNECTION_STRING);
const requestFeatureFlags = async (): Promise<GetConfigurationSettingResponse> => {
const featureFlags = await appConfigClient.getConfigurationSetting({ key: '', label: 'my_feature_flags' });
console.log(featureFlags);
return featureFlags;
}
requestFeatureFlags().then((response) => { alert('I am here'); console.log(response) });
In the above I can see the request being made in the browser dev console and response with the feature flags, but the Promise is never returned from the await appConfigClient.getConfigurationSetting({ key: '', label: 'my_feature_flags' }); call. The console log of featureFlags yields this in the browser console ->
The alert inside the then() is never fired. So at this point I'm a loss lol. The SDK can be found here -> npm https://www.npmjs.com/package/#azure/app-configuration/v/1.1.0
If anyone else has come across this issue and help would be most appreciated!

Setting app permissions for Detox iOS tests not working properly

I'm having issues with this and other methods of setting permissions for iOS in Detox. My app will initially launch with the notification popup, then if I dismiss the popup, the app will relaunch without the notification, but it is still requiring manual intervention. My code in init.js is:
beforeAll(async () => {
await detox.init(undefined, { launchApp: false });
await device.launchApp({ permissions: { notifications: 'YES' } });
});
I have also tried the alternative approach found in this thread yielding the same results: https://github.com/wix/Detox/pull/2009
Found the fix here:
https://github.com/wix/Detox/pull/2009#issuecomment-648971528
With this new integration with jest-circus. How should I launch the app with the permissions I need?
I got my tests working again by overriding the initDetox function in my CustomDetoxEnvironment like this:
async initDetox() {
const instance = await this.detox.init(undefined, {launchApp: false});
await instance.device.launchApp({permissions: {notifications: 'YES'}});
return instance;
}
This ended up working for me

Multiple singleton instances across files in TypeScript and NextJs

Recently, I have been working on a personal project involving the creation of some API endpoints using NextJs and TypeScript that call back on the Discord API using discord.js. Please don't get scared off at the mention of the discord API if you have never touched it, I don't think that library is the issue, hence why it is not included in the thread title.
Problem:
I have implemented a singleton for the discord.js API client as the client can take about a second or two to login and initialize, time I don't want to add to each response. This works great on one file/endpoint, where once that file has the instance, it keeps its. However, as soon as I load another file/endpoint, it creates another instance of the singleton, however, after its creation works fine again within that file.
My problem is that I dont want an instance per file, but instead want one instance for the entire application.
DiscordClient.ts:
import { Client } from 'discord.js';
class DiscordClient {
private static discordClient: DiscordClient;
public APIClient: Client;
private constructor() {
this.APIClient = new Client();
this.APIClient.login($TOKEN);
}
public static get Instance() {
if (!this.discordClient) {
this.discordClient = new DiscordClient();
}
return this.discordClient;
}
}
export const DiscordClientInstance = DiscordClient.Instance;
NOTE: token is merely a placeholder for the unique token of my bot application registered with discord.
/pages/api/test1.ts
import { DiscordClientInstance } from "../../DiscordClient";
export default (req, res) => {
let guild = DiscordClientInstance.APIClient.guilds.fetch($GUILD_1_ID)
.then(guild => {
console.log(guild.name);
res.statusCode = 200;
res.json({ name: guild.name });
})
.catch(console.error);
}
/pages/api/test2.ts
import { DiscordClientInstance } from "../../DiscordClient";
export default (req, res) => {
let guild = DiscordClientInstance.APIClient.guilds.fetch($GUILD_2_ID)
.then(guild => {
console.log(guild.name);
res.statusCode = 200;
res.json({ name: guild.name });
})
.catch(console.error);
}
NOTE: $GUILD_#_ID is merely a placeholder for where the the id of the discord server I am fetching would go.
As can be seen above, test1.ts and test2.ts are nearly identical and are inheriting the same const.
If anyone had any clues as to why this is happening, I would be very appreciative. Some people on other sites from my late-night googling have suggested this could be an issue with node, however, I honestly have no clue.
Thanks,
Matt :)
I use this very pattern without issues - Have you tried this in production mode? When in development mode Next.js will compile each page on-demand which I've observed breaking this pattern. Essentially, if you see "compiling..." then you've lost your persistence. In production mode this doesn't happen and you should see your single instance persisted.

Botkit Slackbot responds with 401 error every time

I'm trying to create a very simple Slack bot using botkit and Google App Engine, but for some reason I keep getting 401 errors any time I message the bot. The weird thing is that the Slack Event Subscription URL (the one ending in /api/messages) validates correctly, and I get a 200 response in GAE logs and validation within Slack.
But whenever I actually message the bot it always gets a 401 error with no message explaining the error at all. I've tried various combinations of the code below, and have now stripped it down to the bare minimum as found here. Aside from dependencies and a code to decrypt credentials (which I've verified is working as expected), this is my full code at the moment:
botInit();
async function botInit () {
const credentialsRaw = await getCredentials();
const credentials = JSON.parse(credentialsRaw);
const adapter = new SlackAdapter(credentials);
const controller = new Botkit({
adapter: adapter
});
controller.on('message', async(bot, message) => {
await bot.reply(message, 'I heard a message!');
});
}
I have also tried this for the messaging function:
controller.ready(() => {
controller.hears(['hello', 'hi'], ['message', 'direct_message'],
async (bot, message) => {
await bot.reply(message, 'Meow. :smile_cat:')
})
})
and this for setting up the controller:
const controller = new Botkit({
webhook_uri: '/api/messages',
adapter: adapter
});
And everything gives back the same exact 401 error, despite all of them working with the Event Subscription URL verification on Slack.
I had same issue but figured out the problem.
I had been using Client Secret as clientSigningSecret
But I should use Signing Secret !

First step on Google API + GMAIL = bad request

I'm very new on Google API, Eventually I want to send emails using it. But for now I'm trying something a little bit simpler (and then build it up).
List all emails in the inbox.
From Gmail > API > Reference, I followed these steps:
On Google API Console:
Created my application.
Under API & Services > Credentials I created a user with Project/Owner role (just to make sure there is no permission problems in this step).
Then I created a key and download the json file.
At API & Services > Library I enabled Gmail.
And using the Reference I put together this snippet:
app.ts
import { google } from 'googleapis';
import credentials from './credentials';
async function main() {
const auth = new google.auth.GoogleAuth({
credentials,
scopes: [
'https://mail.google.com/',
'https://www.googleapis.com/auth/gmail.compose',
'https://www.googleapis.com/auth/gmail.modify',
'https://www.googleapis.com/auth/gmail.readonly',
'https://www.googleapis.com/auth/gmail.metadata'
]
});
const authClient = await auth.getClient();
const gmail = google.gmail({ version: 'v1', auth: authClient });
const data = await gmail.users.messages.list({ userId: 'me' });
console.log(data);
}
main().catch(console.log);
package.json
...
"dependencies": {
googleapis": "^48.0.0"
}
...
Every time I ran this snippet I got:
[01] GaxiosError: Bad Request
[02] at Gaxios._request (~\node_modules\gaxios\build\src\gaxios.js:85:23)
...
[06] response: {
...
[35] status: 400,
[36] statusText: 'Bad Request',
[37] request: {
[38] responseURL: 'https://www.googleapis.com/gmail/v1/users/me/messages'
...
I tried many diferent configurations on Google API Console. Tried to change the scope (list of urls from line 8 to 12) for many others, change the credentials.json to a .js and .ts format, put in a global variable (GOOGLE_APPLICATION_CREDENTIALS) instead of a direct import. But despite of all my attempts, I got aways the same error.
How can I fix that?
Check out example from here which does exactly what you want. They seem use a sampleclient instead of a credentials library.

Resources