-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: sendPersonalMessage * fix: current address * feat: gas account login with no signature --------- Co-authored-by: kim12322222 <[email protected]>
- Loading branch information
1 parent
de87d1f
commit 9a34163
Showing
6 changed files
with
201 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { EVENTS, INTERNAL_REQUEST_SESSION } from '@/constant'; | ||
import { WalletControllerType } from '@/ui/utils'; | ||
import { getKRCategoryByType } from '@/utils/transaction'; | ||
import eventBus from '@/eventBus'; | ||
import { matomoRequestEvent } from '@/utils/matomo-request'; | ||
|
||
// fail code | ||
export enum FailedCode { | ||
SubmitTxFailed = 'SubmitTxFailed', | ||
DefaultFailed = 'DefaultFailed', | ||
} | ||
|
||
const report = async ({ | ||
action, | ||
wallet, | ||
currentAccount, | ||
extra, | ||
}: { | ||
action: | ||
| 'createSignText' | ||
| 'startSignText' | ||
| 'cancelSignText' | ||
| 'completeSignText'; | ||
currentAccount; | ||
wallet: WalletControllerType; | ||
extra?: Record<string, any>; | ||
}) => { | ||
if (!currentAccount) { | ||
return; | ||
} | ||
matomoRequestEvent({ | ||
category: 'SignText', | ||
action: action, | ||
label: [ | ||
getKRCategoryByType(currentAccount.type), | ||
currentAccount.brandName, | ||
].join('|'), | ||
transport: 'beacon', | ||
}); | ||
await wallet.reportStats(action, { | ||
type: currentAccount.brandName, | ||
category: getKRCategoryByType(currentAccount.type), | ||
method: 'personalSign', | ||
...extra, | ||
}); | ||
}; | ||
|
||
type ProgressStatus = 'building' | 'builded' | 'signed' | 'submitted'; | ||
|
||
/** | ||
* send personal message without rpcFlow | ||
* @param data | ||
* @param wallet | ||
* @param onProgress callback | ||
*/ | ||
export const sendPersonalMessage = async ({ | ||
data, | ||
wallet, | ||
onProgress, | ||
ga, | ||
}: { | ||
data: string[]; | ||
wallet: WalletControllerType; | ||
onProgress?: (status: ProgressStatus) => void; | ||
ga?: Record<string, any>; | ||
}) => { | ||
onProgress?.('building'); | ||
const { address, ...currentAccount } = (await wallet.getCurrentAccount())!; | ||
|
||
report({ | ||
action: 'createSignText', | ||
wallet, | ||
currentAccount, | ||
}); | ||
|
||
onProgress?.('builded'); | ||
|
||
const handleSendAfter = async () => { | ||
report({ | ||
action: 'completeSignText', | ||
wallet, | ||
currentAccount, | ||
}); | ||
}; | ||
|
||
report({ action: 'startSignText', wallet, currentAccount }); | ||
|
||
// submit tx | ||
let hash = ''; | ||
try { | ||
hash = await wallet.ethPersonalSign({ | ||
data: { | ||
$ctx: { | ||
ga, | ||
}, | ||
params: data, | ||
}, | ||
session: INTERNAL_REQUEST_SESSION, | ||
approvalRes: { | ||
type: currentAccount.type, | ||
address: address, | ||
extra: { | ||
brandName: currentAccount.brandName, | ||
signTextMethod: 'personalSign', | ||
}, | ||
}, | ||
}); | ||
await handleSendAfter(); | ||
} catch (e) { | ||
await handleSendAfter(); | ||
const err = new Error(e.message); | ||
err.name = FailedCode.SubmitTxFailed; | ||
eventBus.emit(EVENTS.COMMON_HARDWARE.REJECTED, e.message); | ||
throw err; | ||
} | ||
|
||
onProgress?.('signed'); | ||
|
||
return { | ||
txHash: hash, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters