Skip to content
Draft
Show file tree
Hide file tree
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
15 changes: 12 additions & 3 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions app/_locales/en_GB/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Messenger } from '@metamask/base-controller';
import type {
SubscriptionControllerActions,
SubscriptionControllerEvents,
} from '@metamask/subscription-controller';
import type { SubscriptionControllerEvents } from '@metamask/subscription-controller';
import {
SERVICE_NAME,
SubscriptionServiceAction,
SubscriptionServiceMessenger,
} from '../../../services/subscription/types';

Expand All @@ -16,10 +14,7 @@ import {
* @returns The restricted messenger.
*/
export function getSubscriptionServiceMessenger(
messenger: Messenger<
SubscriptionControllerActions,
SubscriptionControllerEvents
>,
messenger: Messenger<SubscriptionServiceAction, SubscriptionControllerEvents>,
): SubscriptionServiceMessenger {
return messenger.getRestricted({
name: SERVICE_NAME,
Expand All @@ -30,6 +25,7 @@ export function getSubscriptionServiceMessenger(
'SubscriptionController:updatePaymentMethod',
'SubscriptionController:getCryptoApproveTransactionParams',
'SubscriptionController:getBillingPortalUrl',
'AuthenticationController:getBearerToken',
],
allowedEvents: [],
});
Expand Down
3 changes: 3 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2288,6 +2288,9 @@ export default class MetamaskController extends EventEmitter {
this.SubscriptionService.updateSubscriptionCryptoPaymentMethod.bind(
this.SubscriptionService,
),
submitShieldClaim: this.SubscriptionService.submitShieldClaim.bind(
this.SubscriptionService,
),

// hardware wallets
connectHardware: this.connectHardware.bind(this),
Expand Down
39 changes: 39 additions & 0 deletions app/scripts/services/subscription/subscription-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
StartSubscriptionRequest,
UpdatePaymentMethodOpts,
} from '@metamask/subscription-controller';
import { handleFetch } from '@metamask/controller-utils';
import ExtensionPlatform from '../../platforms/extension';
import { WebAuthenticator } from '../oauth/types';
import {
Expand Down Expand Up @@ -128,6 +129,44 @@ export class SubscriptionService {
return subscriptions;
}

async submitShieldClaim(params: {
email: string;
impactedWalletAddress: string;
impactedTransactionHash: string;
reimbursementWalletAddress: string;
caseDescription: string;
files: File[];
}) {
console.log('check: submitShieldClaim', params);
const url = 'https://claims.dev-api.cx.metamask.io/claims';
const formData = new FormData();
formData.append('email', params.email);
formData.append('impactedWalletAddress', params.impactedWalletAddress);
formData.append('impactedTransactionHash', params.impactedTransactionHash);
formData.append(
'reimbursementWalletAddress',
params.reimbursementWalletAddress,
);
formData.append('caseDescription', params.caseDescription);
// add multiple files to formData
params.files.forEach((file) => {
formData.append('attachments', file);
});

console.log('check: formData', formData);
const accessToken = await this.#messenger.call(
'AuthenticationController:getBearerToken',
);
return await handleFetch(url, {
method: 'POST',
body: formData,
headers: {
'Content-Type': 'multipart/form-data',
Authorization: `Bearer ${accessToken}`,
},
});
}

async #openAndWaitForTabToClose(params: { url: string; successUrl: string }) {
const openedTab = await this.#platform.openTab({ url: params.url });

Expand Down
8 changes: 7 additions & 1 deletion app/scripts/services/subscription/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { RestrictedMessenger } from '@metamask/base-controller';
import {
SubscriptionControllerGetBillingPortalUrlAction,
SubscriptionControllerGetCryptoApproveTransactionParamsAction,
SubscriptionControllerGetPricingAction,
SubscriptionControllerGetSubscriptionsAction,
SubscriptionControllerStartShieldSubscriptionWithCardAction,
SubscriptionControllerUpdatePaymentMethodAction,
} from '@metamask/subscription-controller';
import { AuthenticationControllerGetBearerToken } from '@metamask/profile-sync-controller/auth';
import ExtensionPlatform from '../../platforms/extension';
import { WebAuthenticator } from '../oauth/types';

Expand All @@ -16,7 +19,10 @@ export type SubscriptionServiceAction =
| SubscriptionControllerGetPricingAction
| SubscriptionControllerStartShieldSubscriptionWithCardAction
| SubscriptionControllerUpdatePaymentMethodAction
| SubscriptionControllerGetSubscriptionsAction;
| SubscriptionControllerGetSubscriptionsAction
| SubscriptionControllerGetCryptoApproveTransactionParamsAction
| SubscriptionControllerGetBillingPortalUrlAction
| AuthenticationControllerGetBearerToken;

export type SubscriptionServiceEvent = never;

Expand Down
5 changes: 5 additions & 0 deletions shared/constants/app-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export enum PasswordChangeToastType {
Errored = 'errored',
}

export enum ClaimSubmitToastType {
Success = 'success',
Errored = 'errored',
}

export type NetworkConnectionBanner =
| { status: 'unknown' | 'available' }
| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"showNewSrpAddedToast": "boolean",
"showPasswordChangeToast": null,
"showCopyAddressToast": "boolean",
"showClaimSubmitToast": null,
"showSupportDataConsentModal": "boolean",
"showConnectionsRemovedModal": "boolean"
},
Expand Down
18 changes: 17 additions & 1 deletion ui/components/app/toast-master/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import {
isSolanaAccount,
} from '../../../selectors';
import { MetaMaskReduxState } from '../../../store/store';
import { PasswordChangeToastType } from '../../../../shared/constants/app-state';
import {
PasswordChangeToastType,
ClaimSubmitToastType,
} from '../../../../shared/constants/app-state';
import { AccountGroupWithInternalAccounts } from '../../../selectors/multichain-accounts/account-tree.types';
import { getCaip25CaveatValueFromPermissions } from '../../../pages/permissions-connect/connect-page/utils';
import { supportsChainIds } from '../../../hooks/useAccountGroupsForPermissions';
Expand All @@ -32,6 +35,7 @@ type State = {
| 'showNewSrpAddedToast'
| 'showPasswordChangeToast'
| 'showCopyAddressToast'
| 'showClaimSubmitToast'
>
>;
metamask: Partial<
Expand Down Expand Up @@ -192,3 +196,15 @@ export function selectShowCopyAddressToast(
): boolean {
return Boolean(state.appState.showCopyAddressToast);
}

/**
* Retrieves the state for the "Claim Submit" toast
*
* @param state - Redux state object.
* @returns ClaimSubmitToastType or null
*/
export function selectClaimSubmitToast(
state: Pick<State, 'appState'>,
): ClaimSubmitToastType | null {
return state.appState.showClaimSubmitToast || null;
}
55 changes: 54 additions & 1 deletion ui/components/app/toast-master/toast-master.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ import { AvatarNetwork, Icon, IconName } from '../../component-library';
import { PreferredAvatar } from '../preferred-avatar';
import { Toast, ToastContainer } from '../../multichain';
import { SurveyToast } from '../../ui/survey-toast';
import { PasswordChangeToastType } from '../../../../shared/constants/app-state';
import {
PasswordChangeToastType,
ClaimSubmitToastType,
} from '../../../../shared/constants/app-state';
import { getDappActiveNetwork } from '../../../selectors/dapp';
import {
getAccountGroupWithInternalAccounts,
Expand All @@ -60,6 +63,7 @@ import {
selectPasswordChangeToast,
selectShowCopyAddressToast,
selectShowConnectAccountGroupToast,
selectClaimSubmitToast,
} from './selectors';
import {
setNewPrivacyPolicyToastClickedOrClosed,
Expand All @@ -69,6 +73,7 @@ import {
setShowNewSrpAddedToast,
setShowPasswordChangeToast,
setShowCopyAddressToast,
setShowClaimSubmitToast,
} from './utils';

export function ToastMaster() {
Expand Down Expand Up @@ -103,6 +108,7 @@ export function ToastMaster() {
return (
<ToastContainer>
<PasswordChangeToast />
<ClaimSubmitToast />
</ToastContainer>
);
}
Expand Down Expand Up @@ -514,3 +520,50 @@ function CopyAddressToast() {
)
);
}

const ClaimSubmitToast = () => {
const t = useI18nContext();
const dispatch = useDispatch();

const showClaimSubmitToast = useSelector(selectClaimSubmitToast);
const autoHideToastDelay = 5 * SECOND;

return (
showClaimSubmitToast !== null && (
<Toast
dataTestId={
showClaimSubmitToast === ClaimSubmitToastType.Success
? 'claim-submit-toast-success'
: 'claim-submit-toast-error'
}
key="claim-submit-toast"
text={
showClaimSubmitToast === ClaimSubmitToastType.Success
? t('shieldClaimSubmitSuccess')
: t('shieldClaimSubmitError')
}
startAdornment={
<Icon
name={
showClaimSubmitToast === ClaimSubmitToastType.Success
? IconName.Check
: IconName.Danger
}
color={
showClaimSubmitToast === ClaimSubmitToastType.Success
? IconColor.successDefault
: IconColor.errorDefault
}
/>
}
autoHideTime={autoHideToastDelay}
onAutoHideToast={() => {
dispatch(setShowClaimSubmitToast(null));
}}
onClose={() => {
dispatch(setShowClaimSubmitToast(null));
}}
/>
)
);
};
13 changes: 12 additions & 1 deletion ui/components/app/toast-master/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import {
SET_SHOW_NEW_SRP_ADDED_TOAST,
SET_SHOW_PASSWORD_CHANGE_TOAST,
SET_SHOW_COPY_ADDRESS_TOAST,
SET_SHOW_CLAIM_SUBMIT_TOAST,
SHOW_NFT_DETECTION_ENABLEMENT_TOAST,
} from '../../../store/actionConstants';
import { submitRequestToBackground } from '../../../store/background-connection';
import { PasswordChangeToastType } from '../../../../shared/constants/app-state';
import {
PasswordChangeToastType,
ClaimSubmitToastType,
} from '../../../../shared/constants/app-state';

/**
* Returns true if the privacy policy toast was shown either never, or less than a day ago.
Expand Down Expand Up @@ -92,3 +96,10 @@ export function setShowCopyAddressToast(value: boolean) {
payload: value,
};
}

export function setShowClaimSubmitToast(value: ClaimSubmitToastType | null) {
return {
type: SET_SHOW_CLAIM_SUBMIT_TOAST,
payload: value,
};
}
13 changes: 12 additions & 1 deletion ui/ducks/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
WebHIDConnectedStatuses,
} from '../../../shared/constants/hardware-wallets';
import * as actionConstants from '../../store/actionConstants';
import { PasswordChangeToastType } from '../../../shared/constants/app-state';
import {
PasswordChangeToastType,
ClaimSubmitToastType,
} from '../../../shared/constants/app-state';

type AppState = {
customNonceValue: string;
Expand Down Expand Up @@ -130,6 +133,7 @@ type AppState = {
showPasswordChangeToast: PasswordChangeToastType | null;
showConnectionsRemovedModal: boolean;
showCopyAddressToast: boolean;
showClaimSubmitToast: ClaimSubmitToastType | null;
};

export type AppSliceState = {
Expand Down Expand Up @@ -230,6 +234,7 @@ const initialState: AppState = {
showNewSrpAddedToast: false,
showPasswordChangeToast: null,
showCopyAddressToast: false,
showClaimSubmitToast: null,
showSupportDataConsentModal: false,
showConnectionsRemovedModal: false,
};
Expand Down Expand Up @@ -775,6 +780,12 @@ export default function reduceApp(
showCopyAddressToast: action.payload,
};

case actionConstants.SET_SHOW_CLAIM_SUBMIT_TOAST:
return {
...appState,
showClaimSubmitToast: action.payload,
};

case actionConstants.SET_SHOW_SUPPORT_DATA_CONSENT_MODAL:
return {
...appState,
Expand Down
Loading
Loading