How to use the @0x/assert.assert.assert function in @0x/assert

To help you get started, we’ve selected a few @0x/assert examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xProject / 0x-monorepo / packages / connect / src / utils / orders_channel_message_parser.ts View on Github external
parse(utf8Data: string): OrdersChannelMessage {
        // parse the message
        const messageObj = JSON.parse(utf8Data);
        // ensure we have a type parameter to switch on
        const type: string = _.get(messageObj, 'type');
        assert.assert(type !== undefined, `Message is missing a type parameter: ${utf8Data}`);
        assert.isString('type', type);
        // ensure we have a request id for the resulting message
        const requestId: string = _.get(messageObj, 'requestId');
        assert.assert(requestId !== undefined, `Message is missing a requestId parameter: ${utf8Data}`);
        assert.isString('requestId', requestId);
        switch (type) {
            case OrdersChannelMessageTypes.Update: {
                assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrdersChannelUpdateSchema);
                const ordersJson = messageObj.payload;
                const orders = relayerResponseJsonParsers.parseAPIOrdersJson(ordersJson);
                return _.assign(messageObj, { payload: orders });
            }
            default: {
                return {
                    type: OrdersChannelMessageTypes.Unknown,
                    requestId,
                    payload: undefined,
                };
            }
        }
github 0xProject / 0x-monorepo / contracts / coordinator / src / client / utils / assert.ts View on Github external
async isSenderAddressAsync(
        variableName: string,
        senderAddressHex: string,
        web3Wrapper: Web3Wrapper,
    ): Promise {
        sharedAssert.isETHAddressHex(variableName, senderAddressHex);
        const isSenderAddressAvailable = await web3Wrapper.isSenderAddressAvailableAsync(senderAddressHex);
        sharedAssert.assert(
            isSenderAddressAvailable,
            `Specified ${variableName} ${senderAddressHex} isn't available through the supplied web3 provider`,
        );
    },
};