Skip to content

Commit

Permalink
Cookiemonster removed from masa-react
Browse files Browse the repository at this point in the history
  • Loading branch information
hide-on-bush-x committed Aug 9, 2023
1 parent a05d5f2 commit a474671
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 58 deletions.
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -10,6 +10,7 @@
"engines": {
"node": ">=16"
},
"author": "hide-on-bush",
"scripts": {
"prepare": "husky install && yarn build",
"clean": "rimraf ./dist",
Expand All @@ -30,14 +31,12 @@
"test": "jest --passWithNoTests",
"doc": "typedoc"
},
"author": "hide-on-bush",
"dependencies": {
"@acusti/react-code-input": "^3.11.0",
"@babel/preset-typescript": "^7.21.5",
"@celo/rainbowkit-celo": "^1.0.2",
"@ebay/nice-modal-react": "^1.2.10",
"@masa-finance/masa-contracts-identity": "^1.8.0",
"@masa-finance/zksbt-cookie": "^0.5.4",
"@masa-finance/masa-sdk": "^3.5.8",
"@metamask/providers": "^11.0.0",
"@rainbow-me/rainbowkit": "~0.12.17",
Expand Down
2 changes: 1 addition & 1 deletion src/provider/masa-provider.tsx
Expand Up @@ -60,7 +60,7 @@ export const MasaProvider = ({
soulNameStyle,
masaConfig: {
// networkName: 'ethereum',
environment: environmentName ?? 'dev',
environment: environmentName ?? 'production',
// arweave: arweaveConfig,
},
rainbowkitConfig: {
Expand Down
2 changes: 1 addition & 1 deletion src/refactor/config.ts
Expand Up @@ -48,7 +48,7 @@ export const defaultConfig: Partial<MasaReactConfig> = {
],
allowedWallets: ['metamask', 'valora', 'walletconnect'],
masaConfig: {
environment: 'dev' as EnvironmentName,
environment: 'production' as EnvironmentName,
networkName: 'ethereum' as NetworkName,
verbose: false,
arweave: {
Expand Down
9 changes: 3 additions & 6 deletions src/refactor/masanew.stories.tsx
Expand Up @@ -620,7 +620,7 @@ const TemplateNewMasaState = (props: Args) => (
<MasaProvider
config={{
allowedWallets: ['metamask', 'walletconnect'],
forceChain: 'goerli',
forceChain: 'base',
allowedNetworkNames: [
'goerli',
'ethereum',
Expand All @@ -630,15 +630,12 @@ const TemplateNewMasaState = (props: Args) => (
'polygon',
'bsctest',
'bsc',
'base',
'basegoerli',
'unknown',
],
contractAddressOverrides: {
SoulNameAddress: '0x9C78Bf97A6abf185C8878C13F1Fd5976C41dDCfa',
SoulStoreAddress: '0xFA2e8C51c2fa4BF544eb76eB294Df9a1CF581b01',
},
masaConfig: {
networkName: 'goerli',
networkName: 'base',
},
}}
>
Expand Down
@@ -1,8 +1,6 @@
import React, { useCallback, useMemo, useState } from 'react';
import NiceModal from '@ebay/nice-modal-react';
import { useCookieMonster } from '@masa-finance/zksbt-cookie';
import { CreateSoulNameResult } from '@masa-finance/masa-sdk';
import { useMasaClient } from '../../../../masa-client';
import { useConfig } from '../../../../base-provider';
import CreateSoulnameForm from './CreateSoulnameForm';
import { useRegisterSoulname } from './use-register-soulname';
Expand All @@ -25,22 +23,15 @@ const SoulnameModal = ({
closeOnSuccess,
}: {
onMintError?: () => void;
onMintSuccess?: () => void;
onMintSuccess?: (result: CreateSoulNameResult) => void;
onRegisterFinish?: () => void;
onSuccess?: () => void;
onError?: () => void;
closeOnSuccess?: boolean;
}) => {
const { company } = useConfig();
const { isLoadingSigner, address } = useWalletClient();
const { sdk: masa } = useMasaClient();
const { isLoadingSigner } = useWalletClient();
const { extension, soulname } = useCreateSoulnameModal();
const {connector} = useWalletClient();

const { fireMintEvent } = useCookieMonster({
clientApp: 'Masa React', // TODO: Forward from MasaClient a client name
clientName: 'Masa',
});

const [shouldRestart, setShouldRestart] = useState(false);
const handleError = useCallback(() => {
Expand All @@ -56,36 +47,36 @@ const SoulnameModal = ({
// const handleErrorConfirmed = useCallback(() => setError(null), []);

const handleMintSuccess = async (result: CreateSoulNameResult) => {
// TODO: Remove lint disable
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
const price = result?.metadata?.value;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
const priceValue = (price?.toNumber() as number) ?? '';
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
const paymentMethod = result?.metadata?.paymentMethod as string;
// // TODO: Remove lint disable
// // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
// const price = result?.metadata?.value;
// // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
// const priceValue = (price?.toNumber() as number) ?? '';
// // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
// const paymentMethod = result?.metadata?.paymentMethod as string;

const [symbol, name] = await Promise.all([
masa?.contracts.instances.SoulNameContract.symbol(),
masa?.contracts.instances.SoulNameContract.name(),
]);
// const [symbol, name] = await Promise.all([
// masa?.contracts.instances.SoulNameContract.symbol(),
// masa?.contracts.instances.SoulNameContract.name(),
// ]);

fireMintEvent(
address ?? '',
masa?.config.networkName ?? '',
masa?.contracts.instances.SoulNameContract.address ?? '',
name ?? '',
symbol ?? '',
'Soulname',
'0', // TODO: Value in USD
'USD',
paymentMethod,
priceValue.toString(),
{
soulname,
wallet_type: connector?.name ?? "Unknown"
}
);
onMintSuccess?.();
// fireMintEvent(
// address ?? '',
// masa?.config.networkName ?? '',
// masa?.contracts.instances.SoulNameContract.address ?? '',
// name ?? '',
// symbol ?? '',
// 'Soulname',
// '0', // TODO: Value in USD
// 'USD',
// paymentMethod,
// priceValue.toString(),
// {
// soulname,
// wallet_type: connector?.name ?? "Unknown"
// }
// );
onMintSuccess?.(result);
};

const {
Expand All @@ -98,6 +89,7 @@ const SoulnameModal = ({
onMintSuccess: handleMintSuccess,
onRegisterFinish,
});

// * handlers
const handleRegisterSoulname = useCallback(async () => {
setShouldRestart(false);
Expand Down
Expand Up @@ -17,9 +17,7 @@ export const useRegisterSoulname = ({
onMintError,
onRegisterFinish,
}: Partial<{
onMintSuccess?: (
result: CreateSoulNameResult
) => void;
onMintSuccess?: (result: CreateSoulNameResult) => void;
onMintError?: () => void;
onRegisterFinish?: () => void;
}>) => {
Expand Down Expand Up @@ -53,11 +51,15 @@ export const useRegisterSoulname = ({
soulNameStyle
);

if (result instanceof Error) {
throw result;
if (result instanceof Error || !result || !result.success) {
onMintError?.();
if (result instanceof Error) throw result;

throw new Error('Unexpected error');
}

if (result) {
if (result && result.success) {
console.log({ result });
onMintSuccess?.(result);
}

Expand All @@ -80,11 +82,14 @@ export const useRegisterSoulname = ({
soulNameStyle
);

if (result instanceof Error) {
throw result;
if (result instanceof Error || !result || !result.success) {
onMintError?.();
if (result instanceof Error) throw result;

throw new Error('Unexpected error');
}

if (result) {
if (result && result.success) {
onMintSuccess?.(result);
}

Expand Down

0 comments on commit a474671

Please sign in to comment.