def METHOD_NAME(address: str) -> Optional[BTCAddress]:
    """
    Converts a legacy BCH address to CashAddr format.
    Code is taken from:
    https://github.com/oskyk/cashaddress/blob/master/cashaddress/convert.py#L46
    Returns None if an error occured during conversion.
    """
    try:
        is_valid = is_valid_bitcoin_cash_address(address)
        if not is_valid:
            return None
        if address.startswith(_PREFIX) is False:
            address = _PREFIX + ':' + address
        _, base32string = address.split(':')
        decoded_string = _b32decode(base32string)
        converted_bits = bech32.convertbits(decoded_string, 5, 8)
        if converted_bits is None:
            return None
        version = _address_type('cash', converted_bits[0])[0]
        legacy_version = _address_type('legacy', version)[1]
        payload = converted_bits[1:-6]
        return BTCAddress(b58encode_check(
            _code_list_to_string([legacy_version] + payload),
        ).decode())
    except ValueError:
        return None