Skip to content

Commit

Permalink
load env from sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
H34D committed Jan 27, 2023
1 parent d5a2f70 commit e6c10b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
20 changes: 7 additions & 13 deletions src/common/helpers/masa/index.ts
@@ -1,15 +1,7 @@
import { EnvironmentName, Masa } from '@masa-finance/masa-sdk';
import { environments, Masa } from '@masa-finance/masa-sdk';
import { ethers, Wallet } from 'ethers';
import { ArweaveConfig } from '../provider/masa-context';

const envs = {
dev: 'https://dev.middleware.masa.finance/',
beta: 'https://beta.middleware.masa.finance/',
test: 'https://test.middleware.masa.finance/',
production: 'https://middleware.masa.finance/',
local: 'http://localhost:4000/',
};

export const createRandomWallet = (): Wallet | null => {
console.info('Creating random wallet!');
const wallet = ethers.Wallet.createRandom();
Expand All @@ -31,19 +23,21 @@ export const createRandomWallet = (): Wallet | null => {

export const createNewMasa = (
newWallet,
env: EnvironmentName,
env: string,
arweaveConfig?: ArweaveConfig,
cookie?: string
) => {
const signer = newWallet ? newWallet : createRandomWallet();

if (!signer) return null;

const environment = environments.find((e) => e.name === env);
if (!environment) return null;

return new Masa({
cookie: cookie || undefined,
wallet: signer,
apiUrl: envs[env],
environment: env,
apiUrl: environment.apiUrl,
environment: environment.environment,
arweave: {
host: arweaveConfig?.host || 'arweave.net',
port: parseInt(arweaveConfig?.port || '443'),
Expand Down
4 changes: 2 additions & 2 deletions src/common/helpers/provider/masa-context.tsx
@@ -1,4 +1,4 @@
import { EnvironmentName, Masa } from '@masa-finance/masa-sdk';
import { Masa } from '@masa-finance/masa-sdk';
import React, {
createContext,
useCallback,
Expand All @@ -20,7 +20,7 @@ export interface ArweaveConfig {
export interface MasaContextProviderProps extends MasaShape {
children: React.ReactNode;
company?: string;
environment?: EnvironmentName;
environment?: "local" | "dev" | "test" | "stage" | "production";
signer?: any;
noWallet?: boolean;
arweaveConfig?: ArweaveConfig;
Expand Down

0 comments on commit e6c10b6

Please sign in to comment.