-
Notifications
You must be signed in to change notification settings - Fork 94
/
constants.ts
78 lines (70 loc) · 2.73 KB
/
constants.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { TFunction } from 'i18next'
export enum SupportedActions {
eth_signTransaction = 'eth_signTransaction',
eth_sendTransaction = 'eth_sendTransaction',
eth_signTypedData = 'eth_signTypedData',
eth_signTypedData_v4 = 'eth_signTypedData_v4',
eth_sign = 'eth_sign',
personal_sign = 'personal_sign',
}
export enum SupportedEvents {
accountsChanged = 'accountsChanged',
chainChanged = 'chainChanged',
}
export function isSupportedAction(action: string) {
return Object.values(SupportedActions).includes(action as SupportedActions)
}
export function isSupportedEvent(event: string) {
return Object.values(SupportedEvents).includes(event as SupportedEvents)
}
export function getDisplayTextFromAction(
t: TFunction,
action: SupportedActions,
dappName: string,
networkName: string
): { description: string; title: string; action: string } {
const actionTranslations: {
[x in SupportedActions]: { description: string; title: string; action: string }
} = {
[SupportedActions.eth_signTransaction]: {
description: networkName
? t('walletConnectRequest.signDappTransaction', { dappName, networkName })
: t('walletConnectRequest.signDappTransactionUnknownNetwork', { dappName }),
title: t('walletConnectRequest.signTransactionTitle'),
action: t('walletConnectRequest.signTransactionAction'),
},
[SupportedActions.eth_sendTransaction]: {
description: networkName
? t('walletConnectRequest.sendDappTransaction', { dappName, networkName })
: t('walletConnectRequest.sendDappTransactionUnknownNetwork', { dappName }),
title: t('walletConnectRequest.sendTransactionTitle'),
action: t('walletConnectRequest.sendTransactionAction'),
},
[SupportedActions.eth_signTypedData]: {
description: t('walletConnectRequest.signPayload', { dappName }),
title: t('walletConnectRequest.signPayloadTitle'),
action: t('allow'),
},
[SupportedActions.eth_signTypedData_v4]: {
description: t('walletConnectRequest.signPayload', { dappName }),
title: t('walletConnectRequest.signPayloadTitle'),
action: t('allow'),
},
[SupportedActions.eth_sign]: {
description: t('walletConnectRequest.signPayload', { dappName }),
title: t('walletConnectRequest.signPayloadTitle'),
action: t('allow'),
},
[SupportedActions.personal_sign]: {
description: t('walletConnectRequest.signPayload', { dappName }),
title: t('walletConnectRequest.signPayloadTitle'),
action: t('allow'),
},
}
const translations = actionTranslations[action]
if (!translations) {
return { description: '', title: '', action: '' }
}
return translations
}
export const chainAgnosticActions: string[] = [SupportedActions.personal_sign]