-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
validate payload, handle request and update styles
- Loading branch information
1 parent
a43c673
commit b29827f
Showing
6 changed files
with
170 additions
and
55 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
OsnapPluginData, | ||
Transaction as TTransaction, | ||
GnosisSafe, | ||
Network | ||
} from '../types'; | ||
import { | ||
validateModuleAddress, | ||
validateTransaction | ||
} from '../utils/validators'; | ||
|
||
export const SIMULATION_ENDPOINT = | ||
'https://ethereum-api-read-prod-77jg7zf4ea-ue.a.run.app/osnap/simulate'; | ||
|
||
export function validatePayload(data: OsnapPluginData): void | never { | ||
const { safe } = data; | ||
if (!safe) { | ||
throw new Error('No safe data'); | ||
} | ||
if (!validateModuleAddress(safe.network, safe?.moduleAddress)) { | ||
throw new Error('Module address is incorrect for this network'); | ||
} | ||
if (!(safe.transactions.length > 0)) { | ||
throw new Error('No transactions to simulate'); | ||
} | ||
safe.transactions.forEach((tx, i) => { | ||
if (!validateTransaction(tx)) { | ||
throw new Error(`Transaction ${i + 1} has missing data`); | ||
} | ||
}); | ||
return; | ||
} | ||
|
||
export function prepareTenderlySimulationPayload(props: { | ||
transactions: TTransaction[]; | ||
safe: GnosisSafe | null; | ||
network: Network; | ||
}): OsnapPluginData { | ||
// this will not happen in this component | ||
if (!props.safe) { | ||
throw new Error('No safe selected'); | ||
} | ||
|
||
const { safeAddress, safeName } = props.safe; | ||
|
||
const payload: GnosisSafe = { | ||
safeAddress, | ||
safeName, | ||
network: props.network, | ||
moduleAddress: props.safe.moduleAddress, | ||
transactions: props.transactions | ||
}; | ||
|
||
return { safe: payload }; | ||
} |
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